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

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

Defined Under Namespace

Modules: ClassMethods 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



36
37
38
39
40
41
42
43
44
# File 'projects/command/src/command_pattern_implementation/concerns/inputs.rb', line 36

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.



29
30
31
# File 'projects/command/src/command_pattern_implementation/concerns/inputs.rb', line 29

def inputs
  @inputs
end

#raw_inputsObject (readonly)

Returns the value of attribute raw_inputs.



29
30
31
# File 'projects/command/src/command_pattern_implementation/concerns/inputs.rb', line 29

def raw_inputs
  @raw_inputs
end

Instance Method Details

#cast_and_validate_inputsObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'projects/command/src/command_pattern_implementation/concerns/inputs.rb', line 54

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



31
32
33
34
# File 'projects/command/src/command_pattern_implementation/concerns/inputs.rb', line 31

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

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

Returns:

  • (Boolean)


46
47
48
# File 'projects/command/src/command_pattern_implementation/concerns/inputs.rb', line 46

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)


50
51
52
# File 'projects/command/src/command_pattern_implementation/concerns/inputs.rb', line 50

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