gluer 0.0.2 → 0.0.3

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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/gluer.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Gluer::VERSION
9
9
  spec.authors = ["rcabralc"]
10
10
  spec.email = ["rcabralc@gmail.com"]
11
- spec.description = %q{Configuration reloader}
12
- spec.summary = %q{Reloads configuration code in a per-file basis}
11
+ spec.description = %q{Reloads configuration code in a per-file basis}
12
+ spec.summary = %q{Configuration reloader}
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
15
15
 
@@ -10,31 +10,39 @@ module Gluer
10
10
  @args = args
11
11
  @block = block
12
12
  @committed = false
13
+ @rolled_back = false
13
14
  end
14
15
 
15
16
  def commit
16
- registry.tap do |registry|
17
- commit_hook.call(registry, context, *args, &block)
18
- committed_on(registry)
19
- end
17
+ raise RuntimeError, 'already committed' if committed?
18
+ commit_hook.call(registry, context, *args, &block)
19
+ mark_committed
20
20
  end
21
21
 
22
22
  def rollback
23
- if committed?
24
- rollback_hook.call(registry_when_committed, context, *args, &block)
25
- end
23
+ raise RuntimeError, 'not committed' unless committed?
24
+ raise RuntimeError, 'already rolled back' if rolled_back?
25
+ rollback_hook.call(registry, context, *args, &block)
26
+ mark_rolled_back
27
+ end
28
+
29
+ def committed?
30
+ @committed
31
+ end
32
+
33
+ def rolled_back?
34
+ @rolled_back
26
35
  end
27
36
 
28
37
  private
29
- attr_reader :definition, :context, :args, :block, :registry_when_committed
38
+ attr_reader :definition, :context, :args, :block
30
39
 
31
- def committed_on(registry)
32
- @registry_when_committed = registry
40
+ def mark_committed
33
41
  @committed = true
34
42
  end
35
43
 
36
- def committed?
37
- @committed
44
+ def mark_rolled_back
45
+ @rolled_back = true
38
46
  end
39
47
 
40
48
  def commit_hook
@@ -46,7 +54,7 @@ module Gluer
46
54
  end
47
55
 
48
56
  def registry
49
- definition.registry_factory.call
57
+ @registry ||= definition.registry_factory.call
50
58
  end
51
59
  end
52
60
  end
data/lib/gluer/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gluer
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,110 @@
1
+ require 'gluer/registration'
2
+
3
+ describe Gluer::Registration do
4
+ # The lifecycle of a Registration:
5
+ #
6
+ # instantiation
7
+ # |
8
+ # v
9
+ # commit (commit hook is called with registry factored out from
10
+ # | definition)
11
+ # |
12
+ # v
13
+ # rollback (rollback hook is called with the same registry)
14
+ # |
15
+ # v
16
+ # garbage collected
17
+ #
18
+ # And if the same registration is committed more than once or rolled back
19
+ # before being committed, errors raise.
20
+
21
+ let(:context) { stub('a context') }
22
+ let(:args) { [stub('argument')] }
23
+ let(:block) { lambda { block_called } }
24
+
25
+ let(:commit_hook) { stub('the commit hook', :call => nil) }
26
+ let(:rollback_hook) { stub('the rollback hook',:call => nil) }
27
+ let(:registry) { stub('registry') }
28
+
29
+ let(:definition) do
30
+ stub(
31
+ :registry_factory => lambda { registry },
32
+ :commit_hook => commit_hook,
33
+ :rollback_hook => rollback_hook,
34
+ )
35
+ end
36
+
37
+ subject do
38
+ Gluer::Registration.new(definition, context, args, block)
39
+ end
40
+
41
+ before do
42
+ stub(:block_called)
43
+ end
44
+
45
+ it "starts as uncommitted" do
46
+ expect(subject).to_not be_committed
47
+ end
48
+
49
+ it "starts as not rolled back" do
50
+ expect(subject).to_not be_rolled_back
51
+ end
52
+
53
+ describe "#commit" do
54
+ it "calls the commit hook with right arguments" do
55
+ commit_hook.should_receive(:call).with(registry, context, *args)
56
+ subject.commit
57
+ end
58
+
59
+ it "passes the block as the block argument to the hook" do
60
+ should_receive(:block_called)
61
+ commit_hook.stub(:call) do |*, &given_block|
62
+ given_block.call if given_block
63
+ end
64
+ subject.commit
65
+ end
66
+
67
+ it "reports as committed" do
68
+ subject.commit
69
+ expect(subject).to be_committed
70
+ end
71
+
72
+ it "rejects further commits" do
73
+ subject.commit
74
+ expect { subject.commit }.to raise_error
75
+ end
76
+ end
77
+
78
+ describe "#rollback" do
79
+ before { subject.commit }
80
+
81
+ it "calls the rollback hook with right arguments, using same registry" do
82
+ definition.registry_factory.should_not_receive(:call)
83
+ rollback_hook.should_receive(:call).with(registry, context, *args)
84
+ subject.rollback
85
+ end
86
+
87
+ it "passes the block as the block argument to the hook" do
88
+ should_receive(:block_called)
89
+ rollback_hook.stub(:call) do |*, &given_block|
90
+ given_block.call if given_block
91
+ end
92
+ subject.rollback
93
+ end
94
+
95
+ it "reports as rolled back" do
96
+ subject.rollback
97
+ expect(subject).to be_rolled_back
98
+ end
99
+
100
+ it "rejects further rollbacks" do
101
+ subject.rollback
102
+ expect { subject.rollback }.to raise_error
103
+ end
104
+
105
+ it "rejects further commits" do
106
+ subject.rollback
107
+ expect { subject.commit }.to raise_error
108
+ end
109
+ end
110
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,22 @@
1
1
  require 'simplecov'
2
- SimpleCov.start
2
+ SimpleCov.start do
3
+ add_filter '/spec/'
4
+ end
5
+
6
+ # This file was generated by the `rspec --init` command. Conventionally, all
7
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
8
+ # Require this file using `require "spec_helper"` to ensure that it is only
9
+ # loaded once.
10
+ #
11
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+
17
+ # Run specs in random order to surface order dependencies. If you find an
18
+ # order dependency and want to debug it, you can fix the order by providing
19
+ # the seed, which is printed after each run.
20
+ # --seed 1234
21
+ config.order = 'random'
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gluer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-03 00:00:00.000000000 Z
12
+ date: 2013-05-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -91,7 +91,7 @@ dependencies:
91
91
  - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
- description: Configuration reloader
94
+ description: Reloads configuration code in a per-file basis
95
95
  email:
96
96
  - rcabralc@gmail.com
97
97
  executables: []
@@ -99,6 +99,7 @@ extensions: []
99
99
  extra_rdoc_files: []
100
100
  files:
101
101
  - .gitignore
102
+ - .rspec
102
103
  - .ruby-version
103
104
  - Gemfile
104
105
  - LICENSE.txt
@@ -118,7 +119,8 @@ files:
118
119
  - lib/gluer/registration_hook.rb
119
120
  - lib/gluer/registration_pool.rb
120
121
  - lib/gluer/version.rb
121
- - spec/integration/registration_spec.rb
122
+ - spec/integration/default_usage_spec.rb
123
+ - spec/registration_spec.rb
122
124
  - spec/spec_helper.rb
123
125
  homepage: ''
124
126
  licenses:
@@ -135,7 +137,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
137
  version: '0'
136
138
  segments:
137
139
  - 0
138
- hash: 778545071681117987
140
+ hash: -643542908819081747
139
141
  required_rubygems_version: !ruby/object:Gem::Requirement
140
142
  none: false
141
143
  requirements:
@@ -144,13 +146,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
146
  version: '0'
145
147
  segments:
146
148
  - 0
147
- hash: 778545071681117987
149
+ hash: -643542908819081747
148
150
  requirements: []
149
151
  rubyforge_project:
150
152
  rubygems_version: 1.8.25
151
153
  signing_key:
152
154
  specification_version: 3
153
- summary: Reloads configuration code in a per-file basis
155
+ summary: Configuration reloader
154
156
  test_files:
155
- - spec/integration/registration_spec.rb
157
+ - spec/integration/default_usage_spec.rb
158
+ - spec/registration_spec.rb
156
159
  - spec/spec_helper.rb
@@ -1,5 +1,5 @@
1
- require 'gluer'
2
1
  require 'spec_helper'
2
+ require 'gluer'
3
3
 
4
4
  describe "Default usage" do
5
5
  before(:all) do