collectr 0.0.7 → 1.0.0

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: 500e76055e3f231839011dd446328953c11982a5
4
- data.tar.gz: 03c0c4f0d1a7fae7589db60babb079dac94e2e19
3
+ metadata.gz: cd10b772686cd8a80b70a85a0d5c523c9fdcb4b6
4
+ data.tar.gz: da8f0bdf753af2d4abd1afc207a22b19e3bd9f79
5
5
  SHA512:
6
- metadata.gz: a67daafbd63e7034553e4a836be561ccfb22fd7ec180b36af9b9bf9af83bdc1f3b9a26f5e56b0ea10bc8833331adc0c0b1fe81b944f464d0469d17019a55801b
7
- data.tar.gz: b1bffa70a650b4d5f22668d6d7d442870e92b256bacb490b6e1929739b47827e4d9ac41797c125a1ab425293d9a45794237f92ae876c31f33453e4c499951cba
6
+ metadata.gz: 4c21545dce0ae951df5e1e83df1d7f99d1b5e172f2e02223145efe1d398cfda6234555f387df1356535b1a0b4347bf5334aca7b5f071d21b8c7f5d31ca6e3e14
7
+ data.tar.gz: 5de5acf3777e51f00de689fa38ad2e896519a23e1f3ad75ed81bd8401b3faae81ca37f839bd1f288f162158c74b83d49e851ddfb47e50399c0b478577323827a
@@ -7,6 +7,9 @@ rvm:
7
7
  - 2.1.5
8
8
  - 2.2.0
9
9
 
10
+ services:
11
+ - redis-server
12
+
10
13
  script: 'bundle exec rake'
11
14
 
12
15
  notifications:
data/README.md CHANGED
@@ -1,11 +1,9 @@
1
- [![Build Status](https://api.travis-ci.org/brianmd/collectr.png?branch=master)](https://travis-ci.org/brianmd/collectr) [![Gem Version](https://badge.fury.io/rb/collectr.png)](http://badge.fury.io/rb/collectr) [![Coverage Status](https://coveralls.io/repos/brianmd/collectr/badge.png?branch=master&service=github)](https://coveralls.io/github/brianmd/collectr?branch=master)
1
+ [![Build Status](https://api.travis-ci.org/brianmd/collectr.png?branch=master)](https://travis-ci.org/brianmd/collectr) [![Gem Version](https://badge.fury.io/rb/collectr.png)](http://badge.fury.io/rb/collectr) [![Coverage Status](https://coveralls.io/repos/brianmd/collectr/badge.svg?branch=master&service=github)](https://coveralls.io/github/brianmd/collectr?branch=master)
2
2
 
3
3
  # Collectr
4
4
 
5
5
  Abstraction for thread-safe collections (array, hash, set, bag).
6
6
 
7
- Once it is fleshed out, will include complete abstractions for redis and memory.
8
-
9
7
  ## Installation
10
8
 
11
9
  Add this line to your application's Gemfile:
@@ -16,7 +14,7 @@ gem 'collectr'
16
14
 
17
15
  And then execute:
18
16
 
19
- $ bundle
17
+ $ bundle install
20
18
 
21
19
  Or install it yourself as:
22
20
 
@@ -24,7 +22,48 @@ Or install it yourself as:
24
22
 
25
23
  ## Usage
26
24
 
27
- TODO: Write usage instructions here
25
+ ```ruby
26
+ require 'collectr/redis/redis_hash'
27
+ x = Collectr::RedisHash.new('example')
28
+ x[3] = 7
29
+ x[3]
30
+ => 7
31
+ x.fetch(3) { 88 }
32
+ => 7
33
+ x.fetch(:not_found) { 88 }
34
+ => 88
35
+ ```
36
+
37
+ ```ruby
38
+ require 'collectr/redis/redis_hash_expiry'
39
+ x = Collectr::RedisHashExpiry.new('example', expires_in: 60)
40
+ x['purple'] = :blue
41
+ x['purple']
42
+ => "blue"
43
+ sleep 61
44
+ x['purple']
45
+ => nil
46
+ x.write('nine', 9, expires_in: 2)
47
+ x['nine']
48
+ ```
49
+
50
+ ```ruby
51
+ require 'collectr/memory/memory_hash'
52
+ x = Collectr::MemoryHash.new('example')
53
+ x[:a] = 'abc'
54
+ x[:a]
55
+ => "abc"
56
+ ```
57
+
58
+ ```ruby
59
+ require 'collectr/redis/redis_array'
60
+ array = Collectr::RedisArray.new('arr', max_size: 3)
61
+ array.clear
62
+ array << 'a'
63
+ array << 'b'
64
+ array.to_a
65
+ => ["a", "b"]
66
+ ```
28
67
 
29
68
  ## Contributing
30
69
 
@@ -51,6 +51,10 @@ module Collectr
51
51
  @store.keys
52
52
  end
53
53
 
54
+ def values
55
+ @store.values
56
+ end
57
+
54
58
  def to_hash
55
59
  @store #.copy
56
60
  end
@@ -38,6 +38,10 @@ module Collectr
38
38
  []
39
39
  end
40
40
 
41
+ def values
42
+ Set.new
43
+ end
44
+
41
45
  def to_hash
42
46
  {}
43
47
  end
@@ -1,4 +1,3 @@
1
- require 'redis'
2
1
  require 'json'
3
2
 
4
3
  require_relative 'redis_base'
@@ -1,3 +1,5 @@
1
+ require 'redis'
2
+
1
3
  module Collectr
2
4
  class RedisBase
3
5
  def serialize(val)
@@ -1,25 +1,7 @@
1
- require 'redis'
2
1
  require 'json'
3
2
 
4
3
  require_relative 'redis_base'
5
4
 
6
- # __FILE__.has_spec 'common/spec/classes/collection/hash_spec'
7
-
8
-
9
- # class Redis
10
- # def fetch(key, options={})
11
- # val = self[key]
12
- # if val.nil?
13
- # begin
14
- # val = yield key
15
- # self[key] = val
16
- # end
17
- # end
18
- # val
19
- # end
20
- # end
21
-
22
-
23
5
  module Collectr
24
6
  class RedisHash < RedisBase
25
7
  attr_reader :store
@@ -91,6 +73,10 @@ module Collectr
91
73
  @store.hkeys(@title).collect{ |key| deserialize key }
92
74
  end
93
75
 
76
+ def values
77
+ keys.collect{ |key| self[key] }
78
+ end
79
+
94
80
  def to_hash
95
81
  hash = {}
96
82
  @store.hgetall(@title).each do |key, val|
@@ -1,4 +1,3 @@
1
- require 'redis'
2
1
  require 'json'
3
2
 
4
3
  require_relative 'redis_base'
@@ -46,7 +45,6 @@ module Collectr
46
45
  end
47
46
 
48
47
  def fetch(key, options={})
49
- expiration = options.fetch(:expires_in) { @default_expires_in }
50
48
  result = self[key]
51
49
  if result.nil?
52
50
  return nil if has_key?(key)
@@ -94,6 +92,10 @@ module Collectr
94
92
  @store.keys(key_prefix).collect{ |key| dekey key }
95
93
  end
96
94
 
95
+ def values
96
+ keys.collect{ |key| self[key] }
97
+ end
98
+
97
99
  def to_hash
98
100
  hash = {}
99
101
  keys.each do |key|
@@ -1,3 +1,3 @@
1
1
  module Collectr
2
- VERSION = "0.0.7"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -1,6 +1,10 @@
1
1
  require 'json'
2
2
  require 'spec_helper'
3
3
 
4
+ if redis_exists?
5
+ warn Redis.current.flushall
6
+ end
7
+
4
8
  shared_examples 'a hash' do
5
9
  context 'when keys and/or values may be other than strings' do
6
10
  subject(:collection) { described_class.new 'example' }
@@ -25,6 +29,7 @@ shared_examples 'a hash' do
25
29
 
26
30
  its(:size) { should eq(3) }
27
31
  it { expect(collection.keys.to_set).to eq([1, 'b2', [1,2]].to_set) }
32
+ it { expect(collection.values.to_set).to eq(["aa1", nil, 3].to_set) }
28
33
  its(:to_hash) { should eq({1=>'aa1', 'b2'=>nil, [1,2]=>3}) }
29
34
  it { expect(collection.fetch(1)).to eq('aa1') }
30
35
  it { expect(collection.fetch('b2')).to eq(nil) }
@@ -55,21 +60,5 @@ shared_examples 'a hash' do
55
60
  # it 'string key is distinct from symbol key' do expect(collection.fetch('x')).to eq(7) end
56
61
  it 'new value is retained' do collection['x'] = 9 ; expect(collection.fetch('x')).to eq(9) end
57
62
  end
58
-
59
- # context 'when expires' do
60
- # it 'expires on time'
61
- # end
62
63
  end
63
64
 
64
- if redis_exists? and false
65
- describe Collectr::RedisHash do
66
- it_behaves_like 'a hash'
67
- end
68
-
69
- describe Collectr::RedisHashExpiry do
70
- it_behaves_like 'a hash'
71
- end
72
- end
73
-
74
- # warn Redis.current.flushall
75
-
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.7
4
+ version: 1.0.0
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-08-17 00:00:00.000000000 Z
11
+ date: 2015-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis