redistat 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/redistat.rb +11 -9
- data/lib/redistat/core_ext.rb +5 -0
- data/lib/redistat/core_ext/hash.rb +23 -0
- data/lib/redistat/finder.rb +2 -0
- data/lib/redistat/options.rb +0 -2
- data/lib/redistat/result.rb +1 -8
- data/lib/redistat/summary.rb +5 -4
- data/lib/redistat/version.rb +1 -1
- data/redistat.gemspec +0 -1
- data/spec/core_ext/hash_spec.rb +30 -0
- data/spec/finder_spec.rb +5 -2
- metadata +9 -19
data/lib/redistat.rb
CHANGED
@@ -1,13 +1,19 @@
|
|
1
1
|
|
2
2
|
require 'rubygems'
|
3
|
-
require 'active_support'
|
4
|
-
require 'active_support/hash_with_indifferent_access' if !{}.respond_to?(:with_indifferent_access) # Active Support 2.x and 3.x
|
5
|
-
require 'redis'
|
6
3
|
require 'date'
|
7
4
|
require 'time'
|
5
|
+
require 'digest/sha1'
|
6
|
+
|
7
|
+
# Active Support 2.x or 3.x
|
8
|
+
require 'active_support'
|
9
|
+
if !{}.respond_to?(:with_indifferent_access)
|
10
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
11
|
+
require 'active_support/core_ext/hash/reverse_merge'
|
12
|
+
end
|
13
|
+
|
8
14
|
require 'time_ext'
|
15
|
+
require 'redis'
|
9
16
|
require 'json'
|
10
|
-
require 'digest/sha1'
|
11
17
|
|
12
18
|
require 'redistat/options'
|
13
19
|
require 'redistat/connection'
|
@@ -17,7 +23,6 @@ require 'redistat/date'
|
|
17
23
|
require 'redistat/date_helper'
|
18
24
|
require 'redistat/event'
|
19
25
|
require 'redistat/finder'
|
20
|
-
require 'redistat/finder/date_set'
|
21
26
|
require 'redistat/key'
|
22
27
|
require 'redistat/label'
|
23
28
|
require 'redistat/model'
|
@@ -26,10 +31,7 @@ require 'redistat/scope'
|
|
26
31
|
require 'redistat/summary'
|
27
32
|
require 'redistat/version'
|
28
33
|
|
29
|
-
require 'redistat/core_ext
|
30
|
-
require 'redistat/core_ext/time'
|
31
|
-
require 'redistat/core_ext/fixnum'
|
32
|
-
require 'redistat/core_ext/bignum'
|
34
|
+
require 'redistat/core_ext'
|
33
35
|
|
34
36
|
module Redistat
|
35
37
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Hash
|
2
|
+
|
3
|
+
def merge_and_incr(hash)
|
4
|
+
self.clone.merge_and_incr!(hash)
|
5
|
+
end
|
6
|
+
|
7
|
+
def merge_and_incr!(hash)
|
8
|
+
raise ArgumentError unless hash.is_a?(Hash)
|
9
|
+
hash.each do |key, value|
|
10
|
+
self[key] = value unless self.set_or_incr(key, value)
|
11
|
+
end
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def set_or_incr(key, value)
|
16
|
+
return false unless value.is_a?(Numeric)
|
17
|
+
self[key] = 0 unless self.has_key?(key)
|
18
|
+
return false unless self[key].is_a?(Numeric)
|
19
|
+
self[key] += value
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/redistat/finder.rb
CHANGED
data/lib/redistat/options.rb
CHANGED
data/lib/redistat/result.rb
CHANGED
data/lib/redistat/summary.rb
CHANGED
@@ -18,10 +18,10 @@ module Redistat
|
|
18
18
|
|
19
19
|
if options[:enable_grouping]
|
20
20
|
stats = inject_group_summaries(stats)
|
21
|
-
key.groups.each
|
21
|
+
key.groups.each do |k|
|
22
22
|
update_key(k, stats, depth_limit, options[:connection_ref])
|
23
23
|
k.update_index if options[:label_indexing]
|
24
|
-
|
24
|
+
end
|
25
25
|
else
|
26
26
|
update_key(key, stats, depth_limit, options[:connection_ref])
|
27
27
|
end
|
@@ -43,6 +43,7 @@ module Redistat
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def self.inject_group_summaries!(stats)
|
46
|
+
summaries = {}
|
46
47
|
stats.each do |key, value|
|
47
48
|
parts = key.to_s.split(GROUP_SEPARATOR)
|
48
49
|
parts.pop
|
@@ -51,11 +52,11 @@ module Redistat
|
|
51
52
|
parts.each do |part|
|
52
53
|
sum_parts << part
|
53
54
|
sum_key = sum_parts.join(GROUP_SEPARATOR)
|
54
|
-
(
|
55
|
+
(summaries.has_key?(sum_key)) ? summaries[sum_key] += value : summaries[sum_key] = value
|
55
56
|
end
|
56
57
|
end
|
57
58
|
end
|
58
|
-
stats
|
59
|
+
stats.merge_and_incr!(summaries)
|
59
60
|
end
|
60
61
|
|
61
62
|
def self.inject_group_summaries(stats)
|
data/lib/redistat/version.rb
CHANGED
data/redistat.gemspec
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Hash do
|
4
|
+
|
5
|
+
it "should #set_or_incr values" do
|
6
|
+
hash = {:count => 1}
|
7
|
+
hash.set_or_incr(:sum, 3).should be_true
|
8
|
+
hash.should == {:count => 1, :sum => 3}
|
9
|
+
hash.set_or_incr(:count, 4).should be_true
|
10
|
+
hash.should == {:count => 5, :sum => 3}
|
11
|
+
hash.set_or_incr(:count, 'test').should be_false
|
12
|
+
hash.set_or_incr(:view, 'test').should be_false
|
13
|
+
hash.should == {:count => 5, :sum => 3}
|
14
|
+
hash[:view] = 'test'
|
15
|
+
hash.set_or_incr(:view, 3).should be_false
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should #merge_and_incr hashes" do
|
19
|
+
hash = { :count => 1, :city => 'hell', :sum => 3, :name => 'john' }
|
20
|
+
|
21
|
+
new_hash = { :count => 3, :city => 'slum', :views => 2 }
|
22
|
+
hash.clone.merge_and_incr(new_hash).should == { :count => 4, :city => 'slum', :views => 2,
|
23
|
+
:sum => 3, :name => 'john' }
|
24
|
+
|
25
|
+
new_hash = { :count => 'six', :city => 'slum', :views => 2, :time => 'late' }
|
26
|
+
hash.clone.merge_and_incr(new_hash).should == { :count => 'six', :city => 'slum', :views => 2,
|
27
|
+
:sum => 3, :name => 'john', :time => 'late' }
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/spec/finder_spec.rb
CHANGED
@@ -44,8 +44,11 @@ describe Redistat::Finder do
|
|
44
44
|
finder = Redistat::Finder.depth(:hour)
|
45
45
|
finder.options[:depth].should == :hour
|
46
46
|
|
47
|
-
finder = Redistat::Finder.interval(
|
48
|
-
finder.options[:interval].should
|
47
|
+
finder = Redistat::Finder.interval(true)
|
48
|
+
finder.options[:interval].should be_true
|
49
|
+
|
50
|
+
finder = Redistat::Finder.interval(false)
|
51
|
+
finder.options[:interval].should be_false
|
49
52
|
|
50
53
|
end
|
51
54
|
|
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: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jim Myhrberg
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-12 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -130,20 +130,6 @@ dependencies:
|
|
130
130
|
version: 0.6.3
|
131
131
|
type: :development
|
132
132
|
version_requirements: *id007
|
133
|
-
- !ruby/object:Gem::Dependency
|
134
|
-
name: ruby-debug
|
135
|
-
prerelease: false
|
136
|
-
requirement: &id008 !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
|
-
requirements:
|
139
|
-
- - ">="
|
140
|
-
- !ruby/object:Gem::Version
|
141
|
-
hash: 3
|
142
|
-
segments:
|
143
|
-
- 0
|
144
|
-
version: "0"
|
145
|
-
type: :development
|
146
|
-
version_requirements: *id008
|
147
133
|
description: A Redis-backed statistics storage and querying library written in Ruby.
|
148
134
|
email:
|
149
135
|
- contact@jimeh.me
|
@@ -165,9 +151,11 @@ files:
|
|
165
151
|
- lib/redistat.rb
|
166
152
|
- lib/redistat/collection.rb
|
167
153
|
- lib/redistat/connection.rb
|
154
|
+
- lib/redistat/core_ext.rb
|
168
155
|
- lib/redistat/core_ext/bignum.rb
|
169
156
|
- lib/redistat/core_ext/date.rb
|
170
157
|
- lib/redistat/core_ext/fixnum.rb
|
158
|
+
- lib/redistat/core_ext/hash.rb
|
171
159
|
- lib/redistat/core_ext/time.rb
|
172
160
|
- lib/redistat/database.rb
|
173
161
|
- lib/redistat/date.rb
|
@@ -186,6 +174,7 @@ files:
|
|
186
174
|
- redistat.gemspec
|
187
175
|
- spec/collection_spec.rb
|
188
176
|
- spec/connection_spec.rb
|
177
|
+
- spec/core_ext/hash_spec.rb
|
189
178
|
- spec/database_spec.rb
|
190
179
|
- spec/date_spec.rb
|
191
180
|
- spec/db/.emptydir
|
@@ -233,13 +222,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
233
222
|
requirements: []
|
234
223
|
|
235
224
|
rubyforge_project: redistat
|
236
|
-
rubygems_version: 1.
|
225
|
+
rubygems_version: 1.6.1
|
237
226
|
signing_key:
|
238
227
|
specification_version: 3
|
239
228
|
summary: A Redis-backed statistics storage and querying library written in Ruby.
|
240
229
|
test_files:
|
241
230
|
- spec/collection_spec.rb
|
242
231
|
- spec/connection_spec.rb
|
232
|
+
- spec/core_ext/hash_spec.rb
|
243
233
|
- spec/database_spec.rb
|
244
234
|
- spec/date_spec.rb
|
245
235
|
- spec/db/.emptydir
|