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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef5508b4fd489d875c554e14b9a7c66865c5b9ba
4
- data.tar.gz: 4cc883b6c7e1715a2bf226900b46e7aa75614dd7
3
+ metadata.gz: 500e76055e3f231839011dd446328953c11982a5
4
+ data.tar.gz: 03c0c4f0d1a7fae7589db60babb079dac94e2e19
5
5
  SHA512:
6
- metadata.gz: deee470529b6ec71158c8846b10ec7b6cec78c2a72f9b752b44a29a35d456529eeeb6dec9e2be57fd7db2a70dad604b19a5ca8da806c234b2b345ae99dfeb440
7
- data.tar.gz: 6e717276f583f241aa831e31d1c6d7a3dd8a1cb96a6179c8574ac09951b7f417b2c518b23af85f725472481881f6da7971ac88361fad73612b40990b30757e74
6
+ metadata.gz: a67daafbd63e7034553e4a836be561ccfb22fd7ec180b36af9b9bf9af83bdc1f3b9a26f5e56b0ea10bc8833331adc0c0b1fe81b944f464d0469d17019a55801b
7
+ data.tar.gz: b1bffa70a650b4d5f22668d6d7d442870e92b256bacb490b6e1929739b47827e4d9ac41797c125a1ab425293d9a45794237f92ae876c31f33453e4c499951cba
@@ -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
@@ -1,4 +1,4 @@
1
- module Collection
1
+ module Collectr
2
2
  class NullHash
3
3
  attr_reader :store
4
4
 
File without changes
@@ -0,0 +1,13 @@
1
+ module Collectr
2
+ class RedisBase
3
+ def serialize(val)
4
+ @raw ? val : [val].to_json
5
+ end
6
+
7
+ def deserialize(val)
8
+ @raw ? val : JSON.parse(val)[0]
9
+ rescue
10
+ val
11
+ end
12
+ end
13
+ end
File without changes
File without changes
File without changes
File without changes
@@ -1,3 +1,3 @@
1
1
  module Collectr
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/spec/bag_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
- require 'bag'
2
+ require 'collectr/bag'
3
3
 
4
- describe Bag do
4
+ describe Collectr::Bag do
5
5
  subject(:bag) { Bag.new }
6
6
 
7
7
  it 'handles empty bag' do
@@ -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' }
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
- require 'memory/memory_hash.rb'
3
- require 'hash_spec'
2
+ require 'collectr/memory/memory_hash.rb'
3
+ require 'hash_spec_helper'
4
4
 
5
5
  describe Collectr::MemoryHash do
6
6
  it_behaves_like 'a hash'
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- require 'redis/redis_array'
3
+ require 'collectr/redis/redis_array'
4
4
 
5
5
  if redis_exists?
6
6
  describe Collectr::RedisArray do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
- require 'redis/redis_hash_expiry'
3
- require 'hash_spec'
2
+ require 'collectr/redis/redis_hash_expiry'
3
+ require 'hash_spec_helper'
4
4
 
5
5
  if redis_exists?
6
6
  describe Collectr::RedisHashExpiry do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
- require 'redis/redis_hash'
3
- require 'hash_spec'
2
+ require 'collectr/redis/redis_hash'
3
+ require 'hash_spec_helper'
4
4
 
5
5
  if redis_exists?
6
6
  describe Collectr::RedisHash do
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.6
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-07-20 00:00:00.000000000 Z
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/hash_spec.rb
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.4.8
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/hash_spec.rb
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
@@ -1,11 +0,0 @@
1
- class RedisBase
2
- def serialize(val)
3
- @raw ? val : [val].to_json
4
- end
5
-
6
- def deserialize(val)
7
- @raw ? val : JSON.parse(val)[0]
8
- rescue
9
- val
10
- end
11
- end