Sha256: 019d31c9840f6f011a820f84f99c9c21112f808f067af28db37c1081625f7f53

Contents?: true

Size: 1.48 KB

Versions: 26

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

26 entries across 26 versions & 1 rubygems

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