diff --git a/lib/redistat/key.rb b/lib/redistat/key.rb index d4969b2..da98ed5 100644 --- a/lib/redistat/key.rb +++ b/lib/redistat/key.rb @@ -22,7 +22,7 @@ module Redistat def to_s(depth = nil) depth ||= @options[:depth] if !@options[:depth].nil? key = "#{@scope}" - key << "/#{@label.hash}" if !label.nil? + key << "/" + ((@options[:hash_label].nil? || @options[:hash_label] == true) ? @label.hash : @label.name) if !label.nil? key << ":#{@date.to_s(depth)}" end diff --git a/spec/key_spec.rb b/spec/key_spec.rb index 197c166..8e40e66 100644 --- a/spec/key_spec.rb +++ b/spec/key_spec.rb @@ -20,12 +20,18 @@ describe Redistat::Key do end it "should convert to string properly" do - @key.to_s.should == "#{@scope}/#{@label_hash}:" + [:year, :month, :day].map { |k| @now.send(k).to_s.rjust(2, '0') }.join + @key.to_s.should == "#{@scope}/#{@label_hash}:#{@key.date.to_s(:day)}" props = [:year, :month, :day, :hour, :min, :sec] props.each do - @key.to_s(props.last).should == "#{@scope}/#{@label_hash}:" + props.map { |k| @now.send(k).to_s.rjust(2, '0') if !k.nil? }.join + @key.to_s(props.last).should == "#{@scope}/#{@label_hash}:#{@key.date.to_s(props.last)}" props.pop end end + it "should abide to hash_label option" do + @label = "about_us" + @key = Redistat::Key.new(@scope, @label, @now, {:depth => :day, :hash_label => false}) + @key.to_s.should == "#{@scope}/#{@label}:#{@key.date.to_s(:day)}" + end + end \ No newline at end of file