Class: Remap::Constructor::Keyword
- Inherits:
-
Concrete
- Object
- Concrete
- Remap::Constructor::Keyword
- Defined in:
- lib/remap/constructor/keyword.rb
Overview
Allows a class (target) to be called with keyword arguments
Instance Method Summary collapse
-
#call(state) ⇒ State
Calls #target as with keyword arguments.
- #strategy ⇒ :keyword
Instance Method Details
#call(state) ⇒ State
Calls Remap::Constructor#target as with keyword arguments
Fails if Remap::Constructor#target does not respond to Remap::Constructor#method Fails if Remap::Constructor#target cannot be called with state
Used by Base to define constructors for mapped data
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/remap/constructor/keyword.rb', line 29 def call(state) super.fmap do |input, &error| unless input.is_a?(Hash) return error["Input is not a hash"] end target.public_send(id, **input) rescue ArgumentError => e raise e.exception("Failed to create [%p] with input [%s] (%s}) using method %s" % [ target, input, input.class, id ]) end end |
#strategy ⇒ :keyword
10 |
# File 'lib/remap/constructor/keyword.rb', line 10 attribute :strategy, Value(:keyword) |