invokr 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0174897be54196672b5fc187801b8afb7b950a5
4
- data.tar.gz: 4b3b4c3656ffb373aab0cfdd56060689dbb7a40b
3
+ metadata.gz: 73bc0fda0e1042d90213b140225f0c24f727eb4a
4
+ data.tar.gz: 962b2726be50743af31c737a9420ead3041c87b0
5
5
  SHA512:
6
- metadata.gz: 0f5edb40a999afc101c009ce040a82170c3356ffe25b79150e590dc7b6813ac84db2d9be765ac74764c8f0102cd57cc00a02ae1376fa776dd6e593b1865a106e
7
- data.tar.gz: 4c8001a382bb203d173ef4558f690678987c9ad9d5113f7e0dbad775e0e24748b291e057ac7f2abbb29f47cc9f9ca99d7a2c68dfd3fce05f658c5dac401d2cc6
6
+ metadata.gz: 05ad75d24db1b1a4685efcbe0088ae1032bcb148a3ca8cd681fe6f517f54749fb472aab77974f7bbb17b87a838a0dda751f422ef2baa04c7739c1e576e93fd05
7
+ data.tar.gz: b7892e1f79b26d0bb730c5258ca4f993fb606affac126e581927ccf2af876ef01c0788e25fb9fd9e9c7f7fdb8180107974ad9b818b802fd613dc42284d1464ba
data/.gitignore CHANGED
@@ -21,3 +21,4 @@ tmp
21
21
  *.a
22
22
  mkmf.log
23
23
  tags
24
+ .ruby-version
data/README.md CHANGED
@@ -50,7 +50,12 @@ def my_method arg1 = 'foo', arg2 = 'bar'
50
50
  end
51
51
  ```
52
52
 
53
- Without knowing how to parse the source code for `#my_method`, Invokr couldn't know what the default values are. And even if I brought in e.g. [ruby_parser](https://github.com/seattlerb/ruby_parser), I'd have to support lazy evaluation, for when you supply a method or constant as the default. This complexity is completely unneccessary when using keyword arguments, so I suggest using that approach for multiple defaults.
53
+ Without knowing how to parse the source code for `#my_method`, Invokr couldn't know what the default values are. And even if I brought in e.g. [ruby_parser](https://github.com/seattlerb/ruby_parser), I'd have to support lazy evaluation, for when you supply a method or constant as the default. This complexity is completely unneccessary when using keyword arguments, so I suggest using that approach for multiple defaults for now.
54
+
55
+ ## Todo
56
+
57
+ * Cleanup
58
+ * Use the `Invokr::Method` object within the `Invokr::Builder`.
54
59
 
55
60
  ## Pre-keyword argument hash defaults
56
61
 
@@ -13,6 +13,13 @@ module Invokr
13
13
  end
14
14
 
15
15
  Method = Struct.new :method do
16
+ def invoke receiver = method.owner, hsh_args
17
+ unless receiver == method.owner or receiver.kind_of? method.owner
18
+ raise TypeError, "no implicit conversion of #{receiver.class} into #{method.owner.name}"
19
+ end
20
+ Invokr.invoke method: method.name, on: receiver, with: hsh_args
21
+ end
22
+
16
23
  def dependencies
17
24
  map_identifiers parameters
18
25
  end
@@ -1,3 +1,3 @@
1
1
  module Invokr
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -15,4 +15,41 @@ class QueryTest < Minitest::Test
15
15
  def test_required_dependencies
16
16
  assert_equal [:album], @method.required_dependencies
17
17
  end
18
+
19
+ def test_invoking_singleton_from_query_object
20
+ assert_equal ['junta', 'trey'], @method.invoke(album: 'junta')
21
+ end
22
+
23
+ def test_invoking_instance_from_query_object
24
+ test_klass = define_test_klass
25
+ method = Invokr.query_method test_klass.instance_method :upcase
26
+
27
+ val = method.invoke test_klass.new, dep: 'phIsh'
28
+ assert_equal "PHISH", val
29
+ end
30
+
31
+ def test_cannot_invoke_instance_not_type_other_than_method_owner
32
+ test_klass = define_test_klass
33
+ method = Invokr.query_method test_klass.instance_method :upcase
34
+
35
+ error = assert_raises TypeError do
36
+ method.invoke Array.new, dep: 'phIsh'
37
+ end
38
+
39
+ assert_equal 'no implicit conversion of Array into TestKlass', error.message
40
+ end
41
+
42
+ private
43
+
44
+ def define_test_klass
45
+ Class.new do
46
+ def self.name
47
+ 'TestKlass'
48
+ end
49
+
50
+ def upcase dep
51
+ dep.upcase
52
+ end
53
+ end
54
+ end
18
55
  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.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ntl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-22 00:00:00.000000000 Z
11
+ date: 2014-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler