Class: Invokr::Method
- Inherits:
-
Struct
- Object
- Struct
- Invokr::Method
- Defined in:
- lib/invokr/method.rb
Instance Attribute Summary collapse
-
#method ⇒ Object
Returns the value of attribute method.
Instance Method Summary collapse
- #dependencies ⇒ Object
- #invoke(args = {}) ⇒ Object
- #optional_dependencies ⇒ Object
- #parameters ⇒ Object
- #required_dependencies ⇒ Object
- #trim_args(hsh_args) ⇒ Object
Instance Attribute Details
#method ⇒ Object
Returns the value of attribute method
2 3 4 |
# File 'lib/invokr/method.rb', line 2 def method @method end |
Instance Method Details
#dependencies ⇒ Object
17 18 19 |
# File 'lib/invokr/method.rb', line 17 def dependencies map_identifiers parameters end |
#invoke(args = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/invokr/method.rb', line 3 def invoke args = {} receiver, method_name, hsh_args = extract_args! args unless receiver == method.owner or receiver.kind_of? method.owner raise TypeError, "no implicit conversion of #{receiver.class} into #{method.owner.name}" end invocation = Builder.build method, hsh_args, args[:block] invocation.method = method_name unless method_name == method.name invocation.invoke! receiver end |
#optional_dependencies ⇒ Object
21 22 23 |
# File 'lib/invokr/method.rb', line 21 def optional_dependencies map_identifiers select_parameters_by_type [:opt, :key] end |
#parameters ⇒ Object
29 30 31 |
# File 'lib/invokr/method.rb', line 29 def parameters method.parameters end |
#required_dependencies ⇒ Object
25 26 27 |
# File 'lib/invokr/method.rb', line 25 def required_dependencies map_identifiers select_parameters_by_type [:req, :keyreq] end |
#trim_args(hsh_args) ⇒ Object
13 14 15 |
# File 'lib/invokr/method.rb', line 13 def trim_args hsh_args hsh_args.select { |key, _| dependencies.include? key } end |