docket 0.0.1 → 0.1.1

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/Gemfile CHANGED
@@ -2,5 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in docket.gemspec
4
4
  gemspec
5
-
6
- gem 'circular_list', :path => '/Users/hubertliu/dev/gems/circular_list'
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :default => :spec
@@ -15,9 +15,28 @@ module Docket
15
15
  robin = _next_robin identifier
16
16
  action.call(robin)
17
17
  end
18
+
19
+ def unset identifier
20
+ unset_key identifier
21
+ unset_from_groups identifier
22
+ end
18
23
 
19
24
  protected
20
25
 
26
+ def unset_key identifier
27
+ storage.remove identifier
28
+ end
29
+
30
+ def unset_from_groups identifier
31
+ groups = storage.read("#{identifier}_groups")
32
+ groups.each do |group|
33
+ old_group = storage.read(group)
34
+ storage.save(group, old_group.reject { |item| item == identifier })
35
+ end
36
+
37
+ storage.remove "#{identifier}_groups"
38
+ end
39
+
21
40
  def _next_robin identifier
22
41
  list = storage.read(identifier) || []
23
42
  robin_list = RobinList.new(list)
@@ -31,7 +50,9 @@ module Docket
31
50
  def _set identifier, robins, options={}
32
51
  list = options[:list] || robins
33
52
 
34
- storage.save(identifier, list, options)
53
+ storage.save(identifier, list)
54
+ storage.append(options[:group], identifier) if options[:group]
55
+ storage.append("#{identifier}_groups", options[:group]) if options[:group]
35
56
  end
36
57
 
37
58
  end
@@ -11,8 +11,6 @@ module Docket
11
11
 
12
12
  def save key, value, options={}
13
13
  touch do
14
- append_to_group(options[:group], key) if options[:group]
15
-
16
14
  db.set! key, value
17
15
  db.compact
18
16
  db.flush
@@ -22,10 +20,14 @@ module Docket
22
20
  def append key, value
23
21
  touch do
24
22
  new_value = Array(read(key)) << value
25
- save(key, new_value)
23
+ save(key, new_value.uniq)
26
24
  end
27
25
  end
28
26
 
27
+ def remove key
28
+ touch { db.delete! key }
29
+ end
30
+
29
31
  def read key
30
32
  touch { db.get key }
31
33
  end
@@ -38,10 +40,6 @@ module Docket
38
40
  db.close
39
41
  end
40
42
 
41
- def append_to_group group, value
42
- append group, value
43
- end
44
-
45
43
  private
46
44
 
47
45
  def clear!
@@ -1,3 +1,3 @@
1
1
  module Docket
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -5,10 +5,53 @@ describe Docket::RoundRobin do
5
5
  let(:round_robin) { Docket::RoundRobin.new(:storage => $storage) }
6
6
 
7
7
  describe '#set' do
8
+
9
+ before :all do
10
+ $storage.send(:clear!)
11
+ end
12
+
8
13
  it 'sets a list of robins for some identifier key' do
9
14
  round_robin.set("trainer_15", ['dog', 'lion', 'tiger'])
10
15
  expect($storage.db.get('trainer_15')).to be_kind_of(Array)
11
16
  end
17
+
18
+ context "using group" do
19
+ before :each do
20
+ round_robin.set("trainer_15", ['dog', 'lion', 'tiger'], :group => 'group1')
21
+ reload_storage_connection
22
+ end
23
+
24
+ it "writes to the group list" do
25
+ expect($storage.read("group1")).to eql(['trainer_15'])
26
+ end
27
+
28
+ it "creates its own index of groups" do
29
+ expect($storage.read("trainer_15_groups")).to eql(['group1'])
30
+ end
31
+ end
32
+ end
33
+
34
+ describe '#unset' do
35
+
36
+ before :each do
37
+ $storage.send(:clear!)
38
+ round_robin.set("trainer_15", ['dog', 'lion', 'tiger'], :group => "daily")
39
+ round_robin.set("trainer_16", ['cat', 'mouse', 'cheese'], :group => "daily")
40
+ round_robin.unset("trainer_15")
41
+ end
42
+
43
+ it "removes the list of groups associated" do
44
+ expect($storage.read('daily')).to_not include("trainer_15")
45
+ expect($storage.read('daily')).to include("trainer_16")
46
+ end
47
+
48
+ it "removes index of groups" do
49
+ expect($storage.read("trainer_15_groups")).to be_nil
50
+ end
51
+
52
+ it "removes the identifier" do
53
+ expect($storage.read("trainer_15")).to be_nil
54
+ end
12
55
  end
13
56
 
14
57
  describe '#perform' do
@@ -42,6 +85,23 @@ describe Docket::RoundRobin do
42
85
  round_robin.perform("trainer_15", action)
43
86
  expect(@animal_to_train).to eql('tiger')
44
87
  end
88
+
89
+ it "works with arrays of arrays" do
90
+ action = lambda { |robin| @robins = robin }
91
+
92
+ round_robin.set("trainer_15", [['dog', 'lion', 'tiger'], ['cages', 'sidewalks', 'bathrooms']])
93
+
94
+ round_robin.perform("trainer_15", action)
95
+ expect(@robins).to eql(['cages', 'sidewalks', 'bathrooms'])
96
+ round_robin.perform("trainer_15", action)
97
+ expect(@robins).to eql(['dog', 'lion', 'tiger'])
98
+
99
+ round_robin.set("trainer_16", [['kids', 'adults']])
100
+ round_robin.perform("trainer_16", action)
101
+ expect(@robins).to eql(['kids', 'adults'])
102
+ round_robin.perform("trainer_16", action)
103
+ expect(@robins).to eql(['kids', 'adults'])
104
+ end
45
105
  end
46
106
 
47
107
  end
data/spec/storage_spec.rb CHANGED
@@ -25,17 +25,6 @@ describe Docket::Storage do
25
25
 
26
26
  expect($storage.db.keys.size).to eql(1)
27
27
  end
28
-
29
- context "using group" do
30
- it "writes key to the group list" do
31
- $storage.save 'key1_group', 'value1', :group => "test_group1"
32
-
33
- reload_storage_connection
34
-
35
-
36
- expect($storage.read("test_group1")).to eql(['key1_group'])
37
- end
38
- end
39
28
  end
40
29
 
41
30
  describe '#read' do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docket
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- version: 0.0.1
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Hubert Liu
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2014-03-05 00:00:00 Z
18
+ date: 2014-03-13 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bundler