Class: ActiveInteraction::Inputs
- Inherits:
-
Hash
- Object
- Hash
- ActiveInteraction::Inputs
- Defined in:
- lib/active_interaction/inputs.rb
Overview
Holds inputs passed to the interaction.
Class Method Summary collapse
- .process(inputs) ⇒ Object
-
.reserved?(name) ⇒ Boolean
Checking ‘syscall` is the result of what appears to be a bug in Ruby.
Instance Method Summary collapse
-
#group(name) ⇒ Hash
Returns inputs from the group name given.
-
#initialize ⇒ Inputs
constructor
A new instance of Inputs.
-
#store(key, value, groups = []) ⇒ Object
Associates the ‘value` with the `key`.
Constructor Details
#initialize ⇒ Inputs
Returns a new instance of Inputs.
53 54 55 56 57 58 |
# File 'lib/active_interaction/inputs.rb', line 53 def initialize @groups = {} @groups.default_proc = ->(hash, key) { hash[key] = [] } super(@inputs = {}) end |
Class Method Details
.process(inputs) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/active_interaction/inputs.rb', line 31 def process(inputs) inputs.stringify_keys.sort.each_with_object({}) do |(k, v), h| next if reserved?(k) if (group = GROUPED_INPUT_PATTERN.match(k)) assign_to_grouped_input!(h, group[:key], group[:index], v) else h[k.to_sym] = v end end end |
.reserved?(name) ⇒ Boolean
Checking ‘syscall` is the result of what appears to be a bug in Ruby. bugs.ruby-lang.org/issues/15597
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_interaction/inputs.rb', line 18 def reserved?(name) name.to_s.start_with?('_interaction_') || name == :syscall || ( Base.method_defined?(name) && !Object.method_defined?(name) ) || ( Base.private_method_defined?(name) && !Object.private_method_defined?(name) ) end |
Instance Method Details
#group(name) ⇒ Hash
Returns inputs from the group name given.
91 92 93 |
# File 'lib/active_interaction/inputs.rb', line 91 def group(name) @inputs.select { |k, _| @groups[name].include?(k) } end |
#store(key, value, groups = []) ⇒ Object
Associates the ‘value` with the `key`. Allows the `key`/`value` pair to
be associated with one or more groups.
74 75 76 77 78 79 80 |
# File 'lib/active_interaction/inputs.rb', line 74 def store(key, value, groups = []) groups.each do |group| @groups[group] << key end super(key, value) end |