Sha256: 5e4bcb6f817be6be7311a9f286c2b7d16142ebd116d5ab9f2b461ab2db717e6b

Contents?: true

Size: 1.2 KB

Versions: 25

Compression:

Stored size: 1.2 KB

Contents

module Foobara
  class Command
    module Concerns
      module DomainMappers
        include Concern

        def run_mapped_subcommand!(subcommand_class, *args)
          unmapped_inputs, has_result_type, result_type =
            case args.size
            when 1
              [args.first]
            when 2
              [args[1], true, args[0]]
            else
              # :nocov:
              raise ArgumentError,
                    "Wrong number of arguments: (#{args.size}. Expected 2 or 3 argument."
              # :nocov:
            end

          inputs = domain_map!(unmapped_inputs, to: subcommand_class, strict: true)

          result = run_subcommand!(subcommand_class, inputs)

          if has_result_type
            result_mapper = self.class.domain.foobara_domain_mapper_registry.lookup!(
              from: result,
              to: result_type,
              strict: true
            )

            result = result_mapper.map(result)
          end

          result
        end

        def domain_map(...)
          self.class.domain.foobara_domain_map(...)
        end

        def domain_map!(...)
          self.class.domain.foobara_domain_map!(...)
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

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