Class: Hinge::Resolver::Node
- Inherits:
-
Object
- Object
- Hinge::Resolver::Node
- Defined in:
- lib/hinge/resolver.rb
Instance Attribute Summary collapse
-
#dependency_names ⇒ Object
readonly
Returns the value of attribute dependency_names.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, container) ⇒ Node
constructor
A new instance of Node.
- #invoke(ordered_values) ⇒ Object
Constructor Details
#initialize(name, container) ⇒ Node
Returns a new instance of Node.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/hinge/resolver.rb', line 56 def initialize(name, container) @name = name @method_name = "build_#{@name}" @method = begin container.method(@method_name) rescue NameError nil end if @method @dependency_names = [] @positional_args_count = 0 @keyword_arg_names = [] @method.parameters.each do |kind, argument_name| argument_name = argument_name.to_sym @dependency_names << argument_name case kind when :req @positional_args_count += 1 when :keyreq @keyword_arg_names << argument_name end end end end |
Instance Attribute Details
#dependency_names ⇒ Object (readonly)
Returns the value of attribute dependency_names.
83 84 85 |
# File 'lib/hinge/resolver.rb', line 83 def dependency_names @dependency_names end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
83 84 85 |
# File 'lib/hinge/resolver.rb', line 83 def method @method end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
83 84 85 |
# File 'lib/hinge/resolver.rb', line 83 def method_name @method_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
83 84 85 |
# File 'lib/hinge/resolver.rb', line 83 def name @name end |
Instance Method Details
#invoke(ordered_values) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/hinge/resolver.rb', line 85 def invoke(ordered_values) splat = ordered_values.take(@positional_args_count) splat << Hash[ @keyword_arg_names.zip(ordered_values.drop(@positional_args_count)) ] if @keyword_arg_names.any? @method.call(*splat) end |