Sha256: bab6d123d9d023f959ae097500ccf9226655f94b565bb1cf8314171a63312059

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 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.lookup_matching_domain_mapper!(
              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

1 entries across 1 versions & 1 rubygems

Version Path
foobara-0.0.37 projects/command/src/concerns/domain_mappers.rb