Module: Textus::Dispatch::Binder
- Defined in:
- lib/textus/dispatch/binder.rb
Defined Under Namespace
Classes: Pending
Class Method Summary collapse
- .bind(spec, inputs) ⇒ Object
- .command(spec, inputs) ⇒ Object
- .inputs_from_ordered(spec, ordered_positionals, by_name_keywords) ⇒ Object
- .inputs_from_wire(spec, raw) ⇒ Object
Class Method Details
.bind(spec, inputs) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/textus/dispatch/binder.rb', line 22 def bind(spec, inputs) missing = spec.required_args.reject { |a| inputs.key?(a.name) } raise MissingArgs.new(spec, missing) unless missing.empty? spec.args.each_with_object({}) do |a, h| if inputs.key?(a.name) h[a.name] = inputs[a.name] elsif !a.default.nil? h[a.name] = a.default end end end |
.command(spec, inputs) ⇒ Object
18 19 20 |
# File 'lib/textus/dispatch/binder.rb', line 18 def command(spec, inputs) Pending.new(spec: spec, inputs: inputs) end |
.inputs_from_ordered(spec, ordered_positionals, by_name_keywords) ⇒ Object
35 36 37 38 |
# File 'lib/textus/dispatch/binder.rb', line 35 def inputs_from_ordered(spec, ordered_positionals, by_name_keywords) names = spec.args.select(&:positional).map(&:name) names.zip(ordered_positionals).to_h.compact.merge(by_name_keywords) end |
.inputs_from_wire(spec, raw) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/textus/dispatch/binder.rb', line 40 def inputs_from_wire(spec, raw) raw ||= {} spec.args.each_with_object({}) do |a, h| h[a.name] = raw[a.wire.to_s] if raw.key?(a.wire.to_s) end end |