Sha256: 5e4bcb6f817be6be7311a9f286c2b7d16142ebd116d5ab9f2b461ab2db717e6b

Contents?: true

Size: 1.2 KB

Versions: 24

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

24 entries across 24 versions & 1 rubygems

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