Module: Foobara::CommandPatternImplementation::Concerns::Inputs

Includes:
Foobara::Concern
Included in:
Foobara::CommandPatternImplementation
Defined in:
foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/inputs.rb

Defined Under Namespace

Classes: UnexpectedInputValidationError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Foobara::Concern

foobara_class_methods_module_for, foobara_concern?, included

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/inputs.rb', line 16

def method_missing(method_name, *args, &)
  if respond_to_missing_for_inputs?(method_name)
    inputs[method_name]
  else
    # :nocov:
    super
    # :nocov:
  end
end

Instance Attribute Details

#inputsObject (readonly)

Returns the value of attribute inputs.



9
10
11
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/inputs.rb', line 9

def inputs
  @inputs
end

#raw_inputsObject (readonly)

Returns the value of attribute raw_inputs.



9
10
11
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/inputs.rb', line 9

def raw_inputs
  @raw_inputs
end

Instance Method Details

#cast_and_validate_inputsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/inputs.rb', line 36

def cast_and_validate_inputs
  if inputs_type.nil? && (raw_inputs.nil? || raw_inputs.empty?)
    @inputs = {}
    return
  end

  outcome = inputs_type.runner(raw_inputs).process_value

  if outcome.success?
    @inputs = outcome.result
  else
    outcome.errors.each do |error|
      if error.is_a?(Value::DataError)
        add_input_error(error)
      else
        # :nocov:
        raise UnexpectedInputValidationError, "Unexpected input validation error: #{error}"
        # :nocov:
      end
    end
  end

  if outcome.success?
    @inputs = outcome.result
  end
end

#initialize(inputs = {}) ⇒ Object



11
12
13
14
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/inputs.rb', line 11

def initialize(inputs = {})
  @raw_inputs = inputs
  super()
end

#respond_to_missing?(method_name, private = false) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/inputs.rb', line 26

def respond_to_missing?(method_name, private = false)
  respond_to_missing_for_inputs?(method_name, private) || super
end

#respond_to_missing_for_inputs?(method_name, _private = false) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/inputs.rb', line 30

def respond_to_missing_for_inputs?(method_name, _private = false)
  inputs_type&.element_types&.key?(method_name)
end