spank 0.0.1393558686 → 1.0.1420314444
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.hound.yml +2 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -1
- data/README.md +6 -6
- data/lib/spank/version.rb +1 -1
- data/spank.gemspec +6 -6
- data/spec/spec_helper.rb +16 -0
- data/spec/unit/container_spec.rb +50 -48
- data/spec/unit/ioc_spec.rb +4 -6
- data/spec/unit/proxy_spec.rb +11 -13
- metadata +23 -23
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc301cc64728fac2deb1c9254d30d48ace7a1f1e
|
4
|
+
data.tar.gz: 47933865366f32ed7f64d848aa2d202c1a0a1691
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b83330fc11559793975f6edc5fb7618ec274cfabfdab5b099d37ac7487b970b2b3bf636648619c7e5c8bf65c58a652086a436c450d8395696714ddaa9343c5b
|
7
|
+
data.tar.gz: d89544b1e0ac1019b0a2c36a50ae5b8ec1d7646ff108773c3a816d9de8596f95acb6db07a040f80b0dff3fde66ac9a261c874ca7385fe85c72436b0a5af350b4
|
data/.hound.yml
ADDED
data/.rspec
ADDED
data/.travis.yml
CHANGED
@@ -1,3 +1,13 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
|
3
|
+
- 2.0.0
|
4
|
+
- 2.2.0
|
5
|
+
sudo: false
|
6
|
+
deploy:
|
7
|
+
provider: rubygems
|
8
|
+
api_key:
|
9
|
+
secure: iVIcz0B2sp3Tj2bGEA0CTxSoLWDAjw+L94g6h9GKntfUKasnayn8BYOEXObIdcl2o0LQe3d68UXmnBbXSi7eFW6yyBhsRn0op3rTxkxh0Lez6jEZagcGIgtCwmmf+ppthYSXi+s0kwhW3kAM797ULpV6aagHBs93PuNh1XIbQs0=
|
10
|
+
gem: spank
|
11
|
+
on:
|
12
|
+
tags: true
|
13
|
+
repo: mokhan/spank
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ Register a single component and resolve it.
|
|
25
25
|
|
26
26
|
```ruby
|
27
27
|
|
28
|
-
container = Container.new
|
28
|
+
container = Spank::Container.new
|
29
29
|
container.register(:item) do |container|
|
30
30
|
"ITEM"
|
31
31
|
end
|
@@ -37,7 +37,7 @@ Register multiple items, and resolve them.
|
|
37
37
|
|
38
38
|
```ruby
|
39
39
|
|
40
|
-
container = Container.new
|
40
|
+
container = Spank::Container.new
|
41
41
|
container.register(:pants) { jeans }
|
42
42
|
container.register(:pants) { dress_pants }
|
43
43
|
pants = container.resolve_all(:pants)
|
@@ -48,7 +48,7 @@ Register a singleton.
|
|
48
48
|
|
49
49
|
```ruby
|
50
50
|
|
51
|
-
container = Container.new
|
51
|
+
container = Spank::Container.new
|
52
52
|
container.register(:singleton) { fake }.as_singleton
|
53
53
|
single_instance = container.resolve(:singleton)
|
54
54
|
same_instance = container.resolve(:singleton)
|
@@ -64,7 +64,7 @@ Automatic dependency resolution.
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
container = Container.new
|
67
|
+
container = Spank::Container.new
|
68
68
|
container.register(:mom) { mom }
|
69
69
|
container.register(:dad) { dad }
|
70
70
|
child = sut.build(Child)
|
@@ -86,7 +86,7 @@ Register selective interceptors.
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
-
container = Container.new
|
89
|
+
container = Spank::Container.new
|
90
90
|
container.register(:command) { Command.new }.intercept(:run).with(Interceptor.new)
|
91
91
|
proxy = container.resolve(:command)
|
92
92
|
proxy.run("hi")
|
@@ -97,7 +97,7 @@ Register selective interceptors.
|
|
97
97
|
|
98
98
|
```ruby
|
99
99
|
|
100
|
-
container = Container.new
|
100
|
+
container = Spank::Container.new
|
101
101
|
Spank::IOC.bind_to(container)
|
102
102
|
item = Spank::IOC.resolve(:item)
|
103
103
|
|
data/lib/spank/version.rb
CHANGED
data/spank.gemspec
CHANGED
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Spank::VERSION
|
9
9
|
spec.authors = ["mo khan"]
|
10
10
|
spec.email = ["mo@mokhan.ca"]
|
11
|
-
spec.description = %q{A
|
11
|
+
spec.description = %q{A lightweight ruby inversion of control (IOC) container}
|
12
12
|
spec.summary = %q{spank!}
|
13
|
-
spec.homepage = "
|
13
|
+
spec.homepage = "https://github.com/mokhan/spank"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
spec.required_ruby_version = '>= 2.0.0'
|
21
21
|
|
22
|
-
spec.add_development_dependency "bundler"
|
23
|
-
spec.add_development_dependency "rake"
|
24
|
-
spec.add_development_dependency "rspec"
|
25
|
-
spec.add_development_dependency "simplecov"
|
22
|
+
spec.add_development_dependency "bundler"
|
23
|
+
spec.add_development_dependency "rake", '~> 10.4'
|
24
|
+
spec.add_development_dependency "rspec", '~> 3.1'
|
25
|
+
spec.add_development_dependency "simplecov", '~> 0.9'
|
26
26
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,19 @@
|
|
1
1
|
require 'simplecov'
|
2
2
|
SimpleCov.start
|
3
3
|
require 'spank'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.expect_with :rspec do |expectations|
|
7
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
8
|
+
end
|
9
|
+
|
10
|
+
config.mock_with :rspec do |mocks|
|
11
|
+
mocks.verify_partial_doubles = true
|
12
|
+
end
|
13
|
+
|
14
|
+
config.filter_run :focus
|
15
|
+
config.run_all_when_everything_filtered = true
|
16
|
+
config.warnings = true
|
17
|
+
config.order = :random
|
18
|
+
Kernel.srand config.seed
|
19
|
+
end
|
data/spec/unit/container_spec.rb
CHANGED
@@ -1,28 +1,24 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
1
|
module Spank
|
4
2
|
describe Container do
|
5
|
-
|
3
|
+
subject { Container.new }
|
6
4
|
|
7
5
|
describe "when resolving an item that has been registered" do
|
8
6
|
let(:registered_item) { Object.new }
|
9
7
|
|
10
8
|
before :each do
|
11
|
-
|
9
|
+
subject.register(:item) do
|
12
10
|
registered_item
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
it "should return the registered item" do
|
19
|
-
result.should == registered_item
|
14
|
+
it "returns the registered item" do
|
15
|
+
expect(subject.resolve(:item)).to eql(registered_item)
|
20
16
|
end
|
21
17
|
end
|
22
18
|
|
23
19
|
describe "when resolving the container" do
|
24
|
-
it "
|
25
|
-
|
20
|
+
it "returns itself" do
|
21
|
+
expect(subject.resolve(:container)).to eql(subject)
|
26
22
|
end
|
27
23
|
end
|
28
24
|
|
@@ -31,57 +27,56 @@ module Spank
|
|
31
27
|
let(:dress_pants) { double("dress pants") }
|
32
28
|
|
33
29
|
before :each do
|
34
|
-
|
35
|
-
|
30
|
+
subject.register(:pants) { jeans }
|
31
|
+
subject.register(:pants) { dress_pants }
|
36
32
|
end
|
37
33
|
|
38
34
|
context "when resolving a single item" do
|
39
|
-
|
40
|
-
|
41
|
-
it "should return the first one registered" do
|
42
|
-
result.should == jeans
|
35
|
+
it "returns the first one registered" do
|
36
|
+
expect(subject.resolve(:pants)).to eql(jeans)
|
43
37
|
end
|
44
38
|
end
|
45
39
|
|
46
40
|
context "when resolving all items" do
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
results.should == [jeans, dress_pants]
|
41
|
+
it "returns them all" do
|
42
|
+
results = subject.resolve_all(:pants)
|
43
|
+
expect(results).to match_array([jeans, dress_pants])
|
51
44
|
end
|
52
45
|
end
|
53
46
|
|
54
47
|
context "when resolving all items for an unknown key" do
|
55
|
-
it "
|
56
|
-
|
48
|
+
it "returns an empty array" do
|
49
|
+
expect(subject.resolve_all(:shirts)).to be_empty
|
57
50
|
end
|
58
51
|
end
|
59
52
|
end
|
60
53
|
|
61
54
|
context "when a component is registered as a singleton" do
|
62
55
|
before :each do
|
63
|
-
|
56
|
+
subject.register(:singleton) { Object.new }.as_singleton
|
64
57
|
end
|
65
58
|
|
66
|
-
it "
|
67
|
-
|
59
|
+
it "returns the same instance of the component every time" do
|
60
|
+
expect(subject.resolve(:singleton)).to eql(subject.resolve(:singleton))
|
68
61
|
end
|
69
62
|
end
|
70
63
|
|
71
64
|
context "when invoking the factory method" do
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
it "should pass the container through to the block" do
|
78
|
-
@result.should == sut
|
65
|
+
it "passes the container through to the block" do
|
66
|
+
result = nil
|
67
|
+
subject.register(:item) { |item| result = item }
|
68
|
+
subject.resolve(:item)
|
69
|
+
expect(result).to eql(subject)
|
79
70
|
end
|
80
71
|
end
|
81
72
|
|
82
73
|
context "when automatically resolving dependencies" do
|
83
74
|
class Child
|
75
|
+
attr_reader :mom, :dad
|
76
|
+
|
84
77
|
def initialize(mom,dad)
|
78
|
+
@mom = mom
|
79
|
+
@dad = dad
|
85
80
|
end
|
86
81
|
def greeting(message)
|
87
82
|
end
|
@@ -92,18 +87,21 @@ module Spank
|
|
92
87
|
let(:dad) { double("dad") }
|
93
88
|
|
94
89
|
before :each do
|
95
|
-
|
96
|
-
|
90
|
+
subject.register(:mom) { mom }
|
91
|
+
subject.register(:dad) { dad }
|
97
92
|
end
|
98
93
|
|
99
|
-
it "
|
100
|
-
|
94
|
+
it "glues the pieces together automatically" do
|
95
|
+
child = subject.build(Child)
|
96
|
+
expect(child).to be_a_kind_of(Child)
|
97
|
+
expect(child.mom).to eql(mom)
|
98
|
+
expect(child.dad).to eql(dad)
|
101
99
|
end
|
102
100
|
end
|
103
101
|
|
104
102
|
context "when a component cannot automatically be constructed" do
|
105
|
-
it "
|
106
|
-
expect {
|
103
|
+
it "raises an error" do
|
104
|
+
expect { subject.build(Child) }.to raise_error(ContainerError)
|
107
105
|
end
|
108
106
|
end
|
109
107
|
end
|
@@ -134,22 +132,26 @@ module Spank
|
|
134
132
|
let(:other_interceptor) { TestInterceptor.new("second") }
|
135
133
|
|
136
134
|
before :each do
|
137
|
-
|
138
|
-
|
139
|
-
|
135
|
+
subject.
|
136
|
+
register(:command) { command }.
|
137
|
+
intercept(:run).with(interceptor).and(other_interceptor)
|
138
|
+
subject.
|
139
|
+
register(:single_command) { command }.
|
140
|
+
intercept(:run).with(interceptor)
|
141
|
+
subject.resolve(:command).run("hi")
|
140
142
|
end
|
141
143
|
|
142
|
-
it "
|
143
|
-
interceptor.called.
|
144
|
+
it "allows the first interceptor to intercept calls to the target" do
|
145
|
+
expect(interceptor.called).to be_truthy
|
144
146
|
end
|
145
147
|
|
146
|
-
it "
|
147
|
-
other_interceptor.called.
|
148
|
+
it "allows the second interceptor to intercept calls to the target" do
|
149
|
+
expect(other_interceptor.called).to be_truthy
|
148
150
|
end
|
149
151
|
|
150
|
-
it "
|
151
|
-
command.called.
|
152
|
-
command.received.
|
152
|
+
it "forwards the args to the command" do
|
153
|
+
expect(command.called).to be_truthy
|
154
|
+
expect(command.received).to match_array(["hi"])
|
153
155
|
end
|
154
156
|
end
|
155
157
|
end
|
data/spec/unit/ioc_spec.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
1
|
describe Spank::IOC do
|
4
2
|
after :each do
|
5
3
|
Spank::IOC.unbind
|
@@ -10,14 +8,14 @@ describe Spank::IOC do
|
|
10
8
|
let(:component) { double }
|
11
9
|
|
12
10
|
before :each do
|
13
|
-
container.
|
11
|
+
allow(container).to receive(:resolve).
|
12
|
+
with(:dbconnection).
|
13
|
+
and_return(component)
|
14
14
|
Spank::IOC.bind_to(container)
|
15
15
|
end
|
16
16
|
|
17
|
-
let(:result) { Spank::IOC.resolve(:idbconnection) }
|
18
|
-
|
19
17
|
it "resolves the item from the container" do
|
20
|
-
|
18
|
+
expect(Spank::IOC.resolve(:dbconnection)).to eq(component)
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
data/spec/unit/proxy_spec.rb
CHANGED
@@ -1,33 +1,31 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
1
|
module Spank
|
4
2
|
describe Proxy do
|
5
|
-
|
3
|
+
subject { Proxy.new(target) }
|
6
4
|
let(:target) { double("target", :greet => nil) }
|
7
5
|
|
8
6
|
context "when invoking a method" do
|
9
|
-
before {
|
7
|
+
before { subject.greet("blah") }
|
10
8
|
|
11
|
-
it "
|
12
|
-
target.
|
9
|
+
it "sends the message to the target" do
|
10
|
+
expect(target).to have_received(:greet).with("blah")
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
16
14
|
context "when an interceptor is registered" do
|
17
15
|
context "when invoking a method" do
|
18
|
-
let(:interceptor) { double(
|
16
|
+
let(:interceptor) { double("interceptor", intercept: "") }
|
19
17
|
|
20
18
|
before :each do
|
21
|
-
|
22
|
-
|
19
|
+
subject.add_interceptor(:greet, interceptor)
|
20
|
+
subject.greet("blah")
|
23
21
|
end
|
24
|
-
it "
|
25
|
-
interceptor.
|
22
|
+
it "allows the interceptor to intercept the call" do
|
23
|
+
expect(interceptor).to have_received(:intercept)
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
29
27
|
context "when invoking a method with a block" do
|
30
|
-
it "
|
28
|
+
it "passes the block to the target" do
|
31
29
|
proxy = Proxy.new([])
|
32
30
|
expect do
|
33
31
|
proxy.each do |x|
|
@@ -39,7 +37,7 @@ module Spank
|
|
39
37
|
end
|
40
38
|
|
41
39
|
context "when invoking a method that is not defined on the target" do
|
42
|
-
it "
|
40
|
+
it "raises an error" do
|
43
41
|
expect { Proxy.new("blah").goodbye }.to raise_error
|
44
42
|
end
|
45
43
|
end
|
metadata
CHANGED
@@ -1,72 +1,72 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1420314444
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mo khan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '10.4'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '10.4'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3.1'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '3.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: simplecov
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
61
|
+
version: '0.9'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
description: A
|
68
|
+
version: '0.9'
|
69
|
+
description: A lightweight ruby inversion of control (IOC) container
|
70
70
|
email:
|
71
71
|
- mo@mokhan.ca
|
72
72
|
executables: []
|
@@ -74,8 +74,8 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
|
-
- ".
|
78
|
-
- ".
|
77
|
+
- ".hound.yml"
|
78
|
+
- ".rspec"
|
79
79
|
- ".travis.yml"
|
80
80
|
- Gemfile
|
81
81
|
- LICENSE.txt
|
@@ -97,7 +97,7 @@ files:
|
|
97
97
|
- spec/unit/container_spec.rb
|
98
98
|
- spec/unit/ioc_spec.rb
|
99
99
|
- spec/unit/proxy_spec.rb
|
100
|
-
homepage:
|
100
|
+
homepage: https://github.com/mokhan/spank
|
101
101
|
licenses:
|
102
102
|
- MIT
|
103
103
|
metadata: {}
|
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
117
|
version: '0'
|
118
118
|
requirements: []
|
119
119
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.
|
120
|
+
rubygems_version: 2.4.5
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: spank!
|
data/.ruby-gemset
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
spank
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.1.1
|