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 +4 -4
- data/.gitignore +1 -0
- data/README.md +6 -1
- data/lib/invokr.rb +7 -0
- data/lib/invokr/version.rb +1 -1
- data/test/query_test.rb +37 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73bc0fda0e1042d90213b140225f0c24f727eb4a
|
4
|
+
data.tar.gz: 962b2726be50743af31c737a9420ead3041c87b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05ad75d24db1b1a4685efcbe0088ae1032bcb148a3ca8cd681fe6f517f54749fb472aab77974f7bbb17b87a838a0dda751f422ef2baa04c7739c1e576e93fd05
|
7
|
+
data.tar.gz: b7892e1f79b26d0bb730c5258ca4f993fb606affac126e581927ccf2af876ef01c0788e25fb9fd9e9c7f7fdb8180107974ad9b818b802fd613dc42284d1464ba
|
data/.gitignore
CHANGED
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
|
|
data/lib/invokr.rb
CHANGED
@@ -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
|
data/lib/invokr/version.rb
CHANGED
data/test/query_test.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2014-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|