Sha256: 019d31c9840f6f011a820f84f99c9c21112f808f067af28db37c1081625f7f53

Contents?: true

Size: 1.48 KB

Versions: 27

Compression:

Stored size: 1.48 KB

Contents

module Foobara
  class Command
    module Concerns
      module InputsType
        include Concern

        module ClassMethods
          def inputs(...)
            old_inputs_type = inputs_type

            old_inputs_type&.possible_errors&.each do |possible_error|
              unregister_possible_error_if_registered(possible_error)
            end

            type = type_for_declaration(...)

            if type.extends?(BuiltinTypes[:model]) && !type.extends?(BuiltinTypes[:entity])
              type = type.element_types
            end

            @inputs_type = type

            register_possible_input_errors

            @inputs_type
          end

          def inputs_type
            return @inputs_type if defined?(@inputs_type)

            @inputs_type = if superclass < Foobara::Command
                             superclass.inputs_type
                           end
          end

          def raw_inputs_type_declaration
            inputs_type.raw_declaration_data
          end

          def inputs_type_declaration
            inputs_type.declaration_data
          end

          private

          def register_possible_input_errors
            # TODO: let's derive these at runtime and memoize...
            inputs_type.possible_errors.each do |possible_error|
              register_possible_error_class(possible_error)
            end
          end
        end

        foobara_delegate :inputs_type, :raw_inputs_type_declaration, to: :class
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
foobara-0.0.7 projects/command/src/concerns/inputs_type.rb
foobara-0.0.6 projects/command/src/concerns/inputs_type.rb
foobara-0.0.5 projects/command/src/concerns/inputs_type.rb
foobara-0.0.4 projects/command/src/concerns/inputs_type.rb
foobara-0.0.3 projects/command/src/concerns/inputs_type.rb
foobara-0.0.2 projects/command/src/concerns/inputs_type.rb
foobara-0.0.1 projects/command/src/concerns/inputs_type.rb