invokr 0.9.3 → 0.9.4

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: 59481f0300eae143fd2769e3646633635ba1efb3
4
- data.tar.gz: 3cf7786413ec97872250d51f3d251ad931e08901
3
+ metadata.gz: 85451302ca410ddae97b77e6b255882d00f33a19
4
+ data.tar.gz: e91e12a4e7025a3b7cb3301032dd6cb2223e46d3
5
5
  SHA512:
6
- metadata.gz: b42e3bd03fcbf008d14b10261d1e8628388ce0c7a5754745555c9fbf0d1b6e9e51b9cec53d97f2ed52258ddfd6749262b3135c8702e668611ada219f4997d755
7
- data.tar.gz: 1ddcb4768df3052b7fb180b3673f826f5767c5548a8c6b87ed36b2ea0606aa3af2494a9f5d99cf299baefe14d963e970a1656c0884129a5c906ede0f4a7f66eb
6
+ metadata.gz: bf52146b18eabed9c93bea408b3d54d4a9c473928f2b47954f57b6e4fbacacac18818cfb87a9559212069a0dad76d44016703b19dafc7e019e53dd66e2620705
7
+ data.tar.gz: 449775825ff9878ae2b67d745a883b3cd0666c75178d45c4a7171f1c39c5f071cf6df7f3b5923f2fc9340a94d46c361ca4a58d2683c888789ea5ce92b61686e0
@@ -31,10 +31,10 @@ module Invokr
31
31
 
32
32
  def build_invocation
33
33
  @block_arg = @implicit_block if @implicit_block
34
- if method.is_a? Proc
35
- Invocation.new :call, @positional_args, @keyword_args, @block_arg
36
- else
34
+ if method.respond_to? :name
37
35
  Invocation.new method.name, @positional_args, @keyword_args, @block_arg
36
+ else
37
+ Invocation.new :call, @positional_args, @keyword_args, @block_arg
38
38
  end
39
39
  end
40
40
 
@@ -4,7 +4,7 @@ module Invokr
4
4
 
5
5
  def inject obj, using
6
6
  meth = case obj
7
- when Proc then :inject_proc
7
+ when -> (obj) { obj.respond_to?(:call) } then :inject_proc
8
8
  when Class then :inject_klass
9
9
  else raise ArgumentError, "can't inject #{obj.inspect}"
10
10
  end
@@ -1,3 +1,3 @@
1
1
  module Invokr
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.4"
3
3
  end
@@ -16,17 +16,32 @@ class DependencyInjectionExampleTest < Minitest::Test
16
16
  end
17
17
 
18
18
  def test_injecting_a_proc
19
- my_proc = -> foo do OpenStruct.new foo: foo end
19
+ my_proc = -> (foo,bar) do OpenStruct.new foo: foo, bar: bar end
20
20
 
21
21
  obj = Invokr.inject(
22
22
  my_proc,
23
23
  :using => {
24
24
  :foo => 'bar',
25
+ :bar => 'baz',
25
26
  :ping => 'pong',
26
27
  }
27
28
  )
28
29
 
29
30
  assert_equal 'bar', obj.foo
31
+ assert_equal 'baz', obj.bar
32
+ end
33
+
34
+ def test_injecting_proc_duck_type
35
+ obj = Invokr.inject(
36
+ TestProcDuckType.new,
37
+ :using => {
38
+ :foo => 'FOO',
39
+ :bar => 'BAZ',
40
+ },
41
+ )
42
+
43
+ assert_equal 'FOO', obj.foo
44
+ assert_equal 'BAZ', obj.bar
30
45
  end
31
46
 
32
47
  class TestObject
@@ -37,4 +52,14 @@ class DependencyInjectionExampleTest < Minitest::Test
37
52
  @guitarist = guitarist
38
53
  end
39
54
  end
55
+
56
+ class TestProcDuckType
57
+ def parameters
58
+ [[:req, :foo],[:req, :bar]]
59
+ end
60
+
61
+ def call(foo, bar)
62
+ OpenStruct.new foo: foo, bar: bar
63
+ end
64
+ end
40
65
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invokr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ntl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-15 00:00:00.000000000 Z
11
+ date: 2014-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler