poniard 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +5 -0
- data/lib/poniard/injector.rb +3 -1
- data/lib/poniard/version.rb +1 -1
- data/poniard.gemspec +0 -1
- data/spec/injector_spec.rb +13 -11
- metadata +4 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a48046036fef997cfa02d4949ce2a26b1468e47
|
4
|
+
data.tar.gz: 6b452b4fb1adb6349c8523aab280e87a7a9ec4ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81ce29dd7b8e9d5a3a91bad63000cab890fd4372bb2a0202c0ed95998e93def8585a499ee21bcfbd92370f805a91115043e22e0a9544c665403b6ba518af1ae9
|
7
|
+
data.tar.gz: 3a66f8a893495a00f746b0bdf66ae5f02e7c6203867210df41498568fc2b494682583b8afcaf3342a0632ad3a8032e2b7f40b3e9187a6d399c037a26489a097c
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -204,6 +204,11 @@ Developing
|
|
204
204
|
Not widely used. May be some obvious things missing from built-in controller
|
205
205
|
sources that you will have to add.
|
206
206
|
|
207
|
+
As far as I know Poniard has not been used on any high traffic applications, and
|
208
|
+
I wouldn't be surprised if there is a performance penalty for using it due to
|
209
|
+
the use of reflection. Please benchmark (and share!) before using in such an
|
210
|
+
environment.
|
211
|
+
|
207
212
|
### Compatibility
|
208
213
|
|
209
214
|
Requires 1.9 or above.
|
data/lib/poniard/injector.rb
CHANGED
@@ -45,8 +45,10 @@ module Poniard
|
|
45
45
|
private
|
46
46
|
|
47
47
|
def dispatch_method(method, unknown_param_f, overrides = {})
|
48
|
+
sources = sources_for(overrides)
|
49
|
+
|
48
50
|
args = method.parameters.map {|_, name|
|
49
|
-
source =
|
51
|
+
source = sources.detect {|source|
|
50
52
|
source.provides?(name)
|
51
53
|
}
|
52
54
|
|
data/lib/poniard/version.rb
CHANGED
data/poniard.gemspec
CHANGED
data/spec/injector_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe Poniard::Injector do
|
|
8
8
|
it 'calls a lambda' do
|
9
9
|
called = false
|
10
10
|
described_class.new([]).dispatch -> { called = true }
|
11
|
-
called.
|
11
|
+
expect(called).to eq(true)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'calls a method' do
|
@@ -18,7 +18,9 @@ describe Poniard::Injector do
|
|
18
18
|
end
|
19
19
|
end.new
|
20
20
|
|
21
|
-
described_class.new([]).dispatch(object.method(:a_number))
|
21
|
+
actual = described_class.new([]).dispatch(object.method(:a_number))
|
22
|
+
|
23
|
+
expect(actual).to eq(12345)
|
22
24
|
end
|
23
25
|
|
24
26
|
it 'calls a method with a parameter provided by a source' do
|
@@ -26,7 +28,7 @@ describe Poniard::Injector do
|
|
26
28
|
described_class.new([
|
27
29
|
thing: thing
|
28
30
|
]).dispatch ->(thing) { called = thing }
|
29
|
-
called.
|
31
|
+
expect(called).to eq(thing)
|
30
32
|
end
|
31
33
|
|
32
34
|
it 'recursively injects sources' do
|
@@ -41,7 +43,7 @@ describe Poniard::Injector do
|
|
41
43
|
{thing: thing},
|
42
44
|
two_source
|
43
45
|
]).dispatch ->(two_things) { called = two_things }
|
44
|
-
called.
|
46
|
+
expect(called).to eq([thing, thing])
|
45
47
|
end
|
46
48
|
|
47
49
|
it 'uses the first source that provides a parameter' do
|
@@ -50,7 +52,7 @@ describe Poniard::Injector do
|
|
50
52
|
{thing: thing},
|
51
53
|
{thing: nil}
|
52
54
|
]).dispatch ->(thing) { called = thing }
|
53
|
-
called.
|
55
|
+
expect(called).to eq(thing)
|
54
56
|
end
|
55
57
|
|
56
58
|
it 'allows sources to be overriden at dispatch' do
|
@@ -58,36 +60,36 @@ describe Poniard::Injector do
|
|
58
60
|
described_class.new([
|
59
61
|
{thing: nil}
|
60
62
|
]).dispatch ->(thing) { called = thing }, thing: thing
|
61
|
-
called.
|
63
|
+
expect(called).to eq(thing)
|
62
64
|
end
|
63
65
|
|
64
66
|
it 'provides itself as a source' do
|
65
67
|
called = false
|
66
68
|
injector = described_class.new
|
67
69
|
injector.dispatch ->(injector) { called = injector }
|
68
|
-
called.
|
70
|
+
expect(called).to eq(injector)
|
69
71
|
end
|
70
72
|
|
71
73
|
it 'allows nil values in hash sources' do
|
72
74
|
value = nil
|
73
75
|
injector = described_class.new
|
74
76
|
injector.dispatch ->(x) { value = x.nil? }, x: nil
|
75
|
-
value.
|
77
|
+
expect(value).to eq(true)
|
76
78
|
end
|
77
79
|
|
78
80
|
it 'yields a fail object when source is unknown' do
|
79
81
|
called = false
|
80
82
|
m = ->(unknown) {
|
81
|
-
|
83
|
+
expect{
|
82
84
|
unknown.bogus
|
83
|
-
}.
|
85
|
+
}.to raise_error(
|
84
86
|
Poniard::UnknownParam,
|
85
87
|
"Tried to call method on an uninjected param: unknown"
|
86
88
|
)
|
87
89
|
called = true
|
88
90
|
}
|
89
91
|
described_class.new.dispatch(m)
|
90
|
-
called.
|
92
|
+
expect(called).to eq(true)
|
91
93
|
end
|
92
94
|
|
93
95
|
describe '#eager_dispatch' do
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poniard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xavier Shay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rspec
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '2.11'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '2.11'
|
11
|
+
date: 2014-05-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description: A dependency injector for Rails, allows you to write clean controllers.
|
28
14
|
email:
|
29
15
|
- contact@xaviershay.com
|
@@ -63,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
49
|
version: '0'
|
64
50
|
requirements: []
|
65
51
|
rubyforge_project:
|
66
|
-
rubygems_version: 2.2.
|
52
|
+
rubygems_version: 2.2.2
|
67
53
|
signing_key:
|
68
54
|
specification_version: 4
|
69
55
|
summary: A dependency injector for Rails, allows you to write clean controllers.
|