redistat 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/VERSION +1 -1
- data/lib/redistat/key.rb +7 -7
- data/lib/redistat/label.rb +15 -8
- data/lib/redistat/model.rb +8 -0
- data/spec/key_spec.rb +6 -6
- data/spec/label_spec.rb +7 -7
- data/spec/model_helper.rb +1 -0
- data/spec/model_spec.rb +6 -0
- metadata +3 -3
data/.gitignore
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/redistat/key.rb
CHANGED
@@ -5,20 +5,20 @@ module Redistat
|
|
5
5
|
attr_accessor :date
|
6
6
|
attr_accessor :options
|
7
7
|
|
8
|
-
def initialize(scope,
|
8
|
+
def initialize(scope, label_name = nil, time_stamp = nil, options = {})
|
9
|
+
@options = default_options.merge(options || {})
|
9
10
|
@scope = scope
|
10
|
-
self.label =
|
11
|
-
self.date =
|
12
|
-
@options = default_options.merge(options ||= {})
|
11
|
+
self.label = label_name if !label_name.nil?
|
12
|
+
self.date = time_stamp ||= Time.now
|
13
13
|
end
|
14
14
|
|
15
15
|
def default_options
|
16
|
-
{ :depth => :
|
16
|
+
{ :depth => :hour, :hashed_label => false }
|
17
17
|
end
|
18
18
|
|
19
19
|
def prefix
|
20
20
|
key = "#{@scope}"
|
21
|
-
key << "
|
21
|
+
key << "/#{label}" if !label.nil?
|
22
22
|
key << ":"
|
23
23
|
key
|
24
24
|
end
|
@@ -40,7 +40,7 @@ module Redistat
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def label=(input)
|
43
|
-
@label = (input.instance_of?(Redistat::Label)) ? input : Label.create(input)
|
43
|
+
@label = (input.instance_of?(Redistat::Label)) ? input : Label.create(input, @options)
|
44
44
|
end
|
45
45
|
|
46
46
|
def to_s(depth = nil)
|
data/lib/redistat/label.rb
CHANGED
@@ -2,16 +2,23 @@ module Redistat
|
|
2
2
|
class Label
|
3
3
|
include Database
|
4
4
|
|
5
|
-
attr_reader :
|
6
|
-
attr_reader :hash
|
5
|
+
attr_reader :raw
|
7
6
|
|
8
|
-
def initialize(str)
|
9
|
-
@
|
10
|
-
@
|
7
|
+
def initialize(str, options = {})
|
8
|
+
@options = options
|
9
|
+
@raw = str.to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
def name
|
13
|
+
@options[:hashed_label] ? hash : @raw
|
14
|
+
end
|
15
|
+
|
16
|
+
def hash
|
17
|
+
@hash ||= Digest::SHA1.hexdigest(@raw)
|
11
18
|
end
|
12
19
|
|
13
20
|
def save
|
14
|
-
@saved = (db.set("#{KEY_LEBELS}#{
|
21
|
+
@saved = (db.set("#{KEY_LEBELS}#{hash}", @raw) == "OK") if @options[:hashed_label]
|
15
22
|
self
|
16
23
|
end
|
17
24
|
|
@@ -19,8 +26,8 @@ module Redistat
|
|
19
26
|
@saved ||= false
|
20
27
|
end
|
21
28
|
|
22
|
-
def self.create(name)
|
23
|
-
self.new(name).save
|
29
|
+
def self.create(name, options = {})
|
30
|
+
self.new(name, options).save
|
24
31
|
end
|
25
32
|
|
26
33
|
end
|
data/lib/redistat/model.rb
CHANGED
@@ -20,6 +20,14 @@ module Redistat
|
|
20
20
|
end
|
21
21
|
alias :find :fetch
|
22
22
|
|
23
|
+
def hashed_label(boolean = nil)
|
24
|
+
if !boolean.nil?
|
25
|
+
options[:hashed_label] = boolean
|
26
|
+
else
|
27
|
+
options[:hashed_label] || nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
23
31
|
def depth(depth = nil)
|
24
32
|
if !depth.nil?
|
25
33
|
options[:depth] = depth
|
data/spec/key_spec.rb
CHANGED
@@ -19,24 +19,24 @@ describe Redistat::Key do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should convert to string properly" do
|
22
|
-
@key.to_s.should == "#{@scope}/#{@
|
22
|
+
@key.to_s.should == "#{@scope}/#{@label}:#{@key.date.to_s(:hour)}"
|
23
23
|
props = [:year, :month, :day, :hour, :min, :sec]
|
24
24
|
props.each do
|
25
|
-
@key.to_s(props.last).should == "#{@scope}/#{@
|
25
|
+
@key.to_s(props.last).should == "#{@scope}/#{@label}:#{@key.date.to_s(props.last)}"
|
26
26
|
props.pop
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
it "should abide to
|
31
|
-
@key = Redistat::Key.new(@scope, @label, @date, {:depth => :hour, :
|
30
|
+
it "should abide to hashed_label option" do
|
31
|
+
@key = Redistat::Key.new(@scope, @label, @date, {:depth => :hour, :hashed_label => true})
|
32
32
|
@key.to_s.should == "#{@scope}/#{@label_hash}:#{@key.date.to_s(:hour)}"
|
33
|
-
@key = Redistat::Key.new(@scope, @label, @date, {:depth => :hour, :
|
33
|
+
@key = Redistat::Key.new(@scope, @label, @date, {:depth => :hour, :hashed_label => false})
|
34
34
|
@key.to_s.should == "#{@scope}/#{@label}:#{@key.date.to_s(:hour)}"
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should have default depth option" do
|
38
38
|
@key = Redistat::Key.new(@scope, @label, @date)
|
39
|
-
@key.depth.should == :
|
39
|
+
@key.depth.should == :hour
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should allow changing attributes" do
|
data/spec/label_spec.rb
CHANGED
@@ -15,14 +15,14 @@ describe Redistat::Label do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should store a label hash lookup key" do
|
18
|
-
|
19
|
-
|
20
|
-
db.get("#{Redistat::KEY_LEBELS}#{
|
18
|
+
label = Redistat::Label.new(@name, {:hashed_label => true}).save
|
19
|
+
label.saved?.should be_true
|
20
|
+
db.get("#{Redistat::KEY_LEBELS}#{label.hash}").should == @name
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
db.get("#{Redistat::KEY_LEBELS}#{
|
22
|
+
name = "contact_us"
|
23
|
+
label = Redistat::Label.create(name, {:hashed_label => true})
|
24
|
+
label.saved?.should be_true
|
25
|
+
db.get("#{Redistat::KEY_LEBELS}#{label.hash}").should == name
|
26
26
|
end
|
27
27
|
|
28
28
|
end
|
data/spec/model_helper.rb
CHANGED
data/spec/model_spec.rb
CHANGED
@@ -16,17 +16,23 @@ describe Redistat::Model do
|
|
16
16
|
it "should listen to model-defined options" do
|
17
17
|
ModelHelper2.depth.should == :day
|
18
18
|
ModelHelper2.store_event.should == true
|
19
|
+
ModelHelper2.hashed_label.should == true
|
19
20
|
|
20
21
|
ModelHelper.depth.should == nil
|
21
22
|
ModelHelper.store_event.should == nil
|
23
|
+
ModelHelper.hashed_label.should == nil
|
22
24
|
ModelHelper.depth(:hour)
|
23
25
|
ModelHelper.depth.should == :hour
|
24
26
|
ModelHelper.store_event(true)
|
25
27
|
ModelHelper.store_event.should == true
|
28
|
+
ModelHelper.hashed_label(true)
|
29
|
+
ModelHelper.hashed_label.should == true
|
26
30
|
ModelHelper.options[:depth] = nil
|
27
31
|
ModelHelper.options[:store_event] = nil
|
32
|
+
ModelHelper.options[:hashed_label] = nil
|
28
33
|
ModelHelper.depth.should == nil
|
29
34
|
ModelHelper.store_event.should == nil
|
35
|
+
ModelHelper.hashed_label.should == nil
|
30
36
|
end
|
31
37
|
|
32
38
|
it "should store and fetch stats" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redistat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jim Myhrberg
|