collectr 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/collectr/bag.rb +62 -0
- data/lib/collectr/memory/memory_factory.rb +24 -0
- data/lib/{memory → collectr/memory}/memory_hash.rb +0 -0
- data/lib/{null → collectr/null}/null_hash.rb +1 -1
- data/lib/{redis → collectr/redis}/redis_array.rb +0 -0
- data/lib/collectr/redis/redis_base.rb +13 -0
- data/lib/{redis → collectr/redis}/redis_factory.rb +0 -0
- data/lib/{redis → collectr/redis}/redis_hash.rb +0 -0
- data/lib/{redis → collectr/redis}/redis_hash_expiry.rb +0 -0
- data/lib/{redis → collectr/redis}/redis_set.rb +0 -0
- data/lib/collectr/version.rb +1 -1
- data/spec/bag_spec.rb +2 -2
- data/spec/{hash_spec.rb → hash_spec_helper.rb} +0 -3
- data/spec/memory/memory_hash_spec.rb +2 -2
- data/spec/redis/redis_array_spec.rb +1 -1
- data/spec/redis/redis_hash_expiry_spec.rb +2 -2
- data/spec/redis/redis_hash_spec.rb +2 -2
- metadata +15 -15
- data/lib/bag.rb +0 -59
- data/lib/memory/memory_factory.rb +0 -22
- data/lib/redis/redis_base.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 500e76055e3f231839011dd446328953c11982a5
|
4
|
+
data.tar.gz: 03c0c4f0d1a7fae7589db60babb079dac94e2e19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a67daafbd63e7034553e4a836be561ccfb22fd7ec180b36af9b9bf9af83bdc1f3b9a26f5e56b0ea10bc8833331adc0c0b1fe81b944f464d0469d17019a55801b
|
7
|
+
data.tar.gz: b1bffa70a650b4d5f22668d6d7d442870e92b256bacb490b6e1929739b47827e4d9ac41797c125a1ab425293d9a45794237f92ae876c31f33453e4c499951cba
|
data/lib/collectr/bag.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
module Collectr
|
2
|
+
class Bag
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
def initialize(collection=nil)
|
6
|
+
@bag = Hash.new{ 0 }
|
7
|
+
collection.each{ |item| self << item } if collection
|
8
|
+
end
|
9
|
+
|
10
|
+
def add(obj)
|
11
|
+
@bag[obj] += 1
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def <<(obj)
|
16
|
+
add(obj)
|
17
|
+
end
|
18
|
+
|
19
|
+
def [](obj)
|
20
|
+
@bag[obj]
|
21
|
+
end
|
22
|
+
|
23
|
+
def keys
|
24
|
+
@bag.keys
|
25
|
+
end
|
26
|
+
|
27
|
+
def size
|
28
|
+
@bag.size
|
29
|
+
end
|
30
|
+
|
31
|
+
def count
|
32
|
+
sum = 0
|
33
|
+
each{ |key, val| sum += val }
|
34
|
+
sum
|
35
|
+
end
|
36
|
+
|
37
|
+
def each(&block)
|
38
|
+
@bag.each{ |k,v| block.call k,v }
|
39
|
+
end
|
40
|
+
|
41
|
+
def bag
|
42
|
+
@bag
|
43
|
+
end
|
44
|
+
|
45
|
+
def empty?
|
46
|
+
@bag.empty?
|
47
|
+
end
|
48
|
+
|
49
|
+
def as_sorted_counts
|
50
|
+
@bag.sort_by{ |key, cnt| -cnt }
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
# for cloning
|
56
|
+
def initialize_copy(source)
|
57
|
+
@bag = source.bag.clone
|
58
|
+
super
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Collectr
|
2
|
+
class MemoryFactory
|
3
|
+
def initialize(redis_store=nil)
|
4
|
+
end
|
5
|
+
|
6
|
+
def hash(title=default_title, options={})
|
7
|
+
MemoryHash.new title, options
|
8
|
+
end
|
9
|
+
|
10
|
+
def set(title=default_title)
|
11
|
+
RedisSet.new title, store: @store
|
12
|
+
end
|
13
|
+
|
14
|
+
def array(title=default_title)
|
15
|
+
RedisArray.new title, store: @store
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def default_title
|
21
|
+
Time.now.to_s
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/collectr/version.rb
CHANGED
data/spec/bag_spec.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
#require 'redis/redis_hash.rb'
|
5
|
-
#require 'redis/redis_hash_expiry.rb'
|
6
|
-
|
7
4
|
shared_examples 'a hash' do
|
8
5
|
context 'when keys and/or values may be other than strings' do
|
9
6
|
subject(:collection) { described_class.new 'example' }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: collectr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Murphy-Dye
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -208,20 +208,20 @@ files:
|
|
208
208
|
- README.md
|
209
209
|
- Rakefile
|
210
210
|
- collectr.gemspec
|
211
|
-
- lib/bag.rb
|
212
211
|
- lib/collectr.rb
|
212
|
+
- lib/collectr/bag.rb
|
213
|
+
- lib/collectr/memory/memory_factory.rb
|
214
|
+
- lib/collectr/memory/memory_hash.rb
|
215
|
+
- lib/collectr/null/null_hash.rb
|
216
|
+
- lib/collectr/redis/redis_array.rb
|
217
|
+
- lib/collectr/redis/redis_base.rb
|
218
|
+
- lib/collectr/redis/redis_factory.rb
|
219
|
+
- lib/collectr/redis/redis_hash.rb
|
220
|
+
- lib/collectr/redis/redis_hash_expiry.rb
|
221
|
+
- lib/collectr/redis/redis_set.rb
|
213
222
|
- lib/collectr/version.rb
|
214
|
-
- lib/memory/memory_factory.rb
|
215
|
-
- lib/memory/memory_hash.rb
|
216
|
-
- lib/null/null_hash.rb
|
217
|
-
- lib/redis/redis_array.rb
|
218
|
-
- lib/redis/redis_base.rb
|
219
|
-
- lib/redis/redis_factory.rb
|
220
|
-
- lib/redis/redis_hash.rb
|
221
|
-
- lib/redis/redis_hash_expiry.rb
|
222
|
-
- lib/redis/redis_set.rb
|
223
223
|
- spec/bag_spec.rb
|
224
|
-
- spec/
|
224
|
+
- spec/hash_spec_helper.rb
|
225
225
|
- spec/memory/memory_hash_spec.rb
|
226
226
|
- spec/redis/redis_array_spec.rb
|
227
227
|
- spec/redis/redis_hash_expiry_spec.rb
|
@@ -247,13 +247,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
247
247
|
version: '0'
|
248
248
|
requirements: []
|
249
249
|
rubyforge_project:
|
250
|
-
rubygems_version: 2.
|
250
|
+
rubygems_version: 2.2.2
|
251
251
|
signing_key:
|
252
252
|
specification_version: 4
|
253
253
|
summary: Abstraction for thread-safe collections (array, hash, set, bag).
|
254
254
|
test_files:
|
255
255
|
- spec/bag_spec.rb
|
256
|
-
- spec/
|
256
|
+
- spec/hash_spec_helper.rb
|
257
257
|
- spec/memory/memory_hash_spec.rb
|
258
258
|
- spec/redis/redis_array_spec.rb
|
259
259
|
- spec/redis/redis_hash_expiry_spec.rb
|
data/lib/bag.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
class Bag
|
2
|
-
include Enumerable
|
3
|
-
|
4
|
-
def initialize(collection=nil)
|
5
|
-
@bag = Hash.new{ 0 }
|
6
|
-
collection.each{ |item| self << item } if collection
|
7
|
-
end
|
8
|
-
|
9
|
-
def add(obj)
|
10
|
-
@bag[obj] += 1
|
11
|
-
self
|
12
|
-
end
|
13
|
-
|
14
|
-
def <<(obj)
|
15
|
-
add(obj)
|
16
|
-
end
|
17
|
-
|
18
|
-
def [](obj)
|
19
|
-
@bag[obj]
|
20
|
-
end
|
21
|
-
|
22
|
-
def keys
|
23
|
-
@bag.keys
|
24
|
-
end
|
25
|
-
|
26
|
-
def size
|
27
|
-
@bag.size
|
28
|
-
end
|
29
|
-
|
30
|
-
def count
|
31
|
-
sum = 0
|
32
|
-
each{ |key, val| sum += val }
|
33
|
-
sum
|
34
|
-
end
|
35
|
-
|
36
|
-
def each(&block)
|
37
|
-
@bag.each{ |k,v| block.call k,v }
|
38
|
-
end
|
39
|
-
|
40
|
-
def bag
|
41
|
-
@bag
|
42
|
-
end
|
43
|
-
|
44
|
-
def empty?
|
45
|
-
@bag.empty?
|
46
|
-
end
|
47
|
-
|
48
|
-
def as_sorted_counts
|
49
|
-
@bag.sort_by{ |key, cnt| -cnt }
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
# for cloning
|
55
|
-
def initialize_copy(source)
|
56
|
-
@bag = source.bag.clone
|
57
|
-
super
|
58
|
-
end
|
59
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
class MemoryFactory
|
2
|
-
def initialize(redis_store=nil)
|
3
|
-
end
|
4
|
-
|
5
|
-
def hash(title=default_title, options={})
|
6
|
-
MemoryHash.new title, options
|
7
|
-
end
|
8
|
-
|
9
|
-
def set(title=default_title)
|
10
|
-
RedisSet.new title, store: @store
|
11
|
-
end
|
12
|
-
|
13
|
-
def array(title=default_title)
|
14
|
-
RedisArray.new title, store: @store
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def default_title
|
20
|
-
Time.now.to_s
|
21
|
-
end
|
22
|
-
end
|