Sha256: d9142e2c423e0b30e4bdf3a6a80f1dc06d3789a197c98641236badd798e02b19

Contents?: true

Size: 1.43 KB

Versions: 26

Compression:

Stored size: 1.43 KB

Contents

module Foobara
  class Command
    module Concerns
      module Inputs
        include Concern

        attr_reader :inputs

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

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

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

        foobara_delegate :inputs_type, to: :class

        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
                # TODO: raise a real error
                # :nocov:
                raise "wtf"
                # :nocov:
              end
            end
          end

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

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
foobara-0.0.26 projects/command/src/concerns/inputs.rb
foobara-0.0.25 projects/command/src/concerns/inputs.rb
foobara-0.0.24 projects/command/src/concerns/inputs.rb
foobara-0.0.23 projects/command/src/concerns/inputs.rb
foobara-0.0.22 projects/command/src/concerns/inputs.rb
foobara-0.0.21 projects/command/src/concerns/inputs.rb
foobara-0.0.20 projects/command/src/concerns/inputs.rb
foobara-0.0.19 projects/command/src/concerns/inputs.rb
foobara-0.0.18 projects/command/src/concerns/inputs.rb
foobara-0.0.17 projects/command/src/concerns/inputs.rb
foobara-0.0.16 projects/command/src/concerns/inputs.rb
foobara-0.0.15 projects/command/src/concerns/inputs.rb
foobara-0.0.14 projects/command/src/concerns/inputs.rb
foobara-0.0.13 projects/command/src/concerns/inputs.rb
foobara-0.0.12 projects/command/src/concerns/inputs.rb
foobara-0.0.11 projects/command/src/concerns/inputs.rb
foobara-0.0.10 projects/command/src/concerns/inputs.rb
foobara-0.0.9 projects/command/src/concerns/inputs.rb
foobara-0.0.8 projects/command/src/concerns/inputs.rb
foobara-0.0.7 projects/command/src/concerns/inputs.rb