Sha256: 1cbf131bea157370460350dbdf2a49065a3caef995717f667ecc697cdc481944

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

require_relative "../share/compares_safely"

module Mocktail
  class TransformsParams
    def initialize
      @compares_safely = ComparesSafely.new
    end

    def transform(dry_call)
      params = dry_call.original_method.parameters

      Signature.new(
        positional_params: Params.new(
          all: params.select { |t, _|
            [:req, :opt, :rest].any? { |param_type| @compares_safely.compare(t, param_type) }
          }.map { |_, name| name },
          required: params.select { |t, _| @compares_safely.compare(t, :req) }.map { |_, n| n },
          optional: params.select { |t, _| @compares_safely.compare(t, :opt) }.map { |_, n| n },
          rest: params.find { |t, _| @compares_safely.compare(t, :rest) } & [1]
        ),
        positional_args: dry_call.args,

        keyword_params: Params.new(
          all: params.select { |type, _|
            [:keyreq, :key, :keyrest].include?(type)
          }.map { |_, name| name },
          required: params.select { |t, _| @compares_safely.compare(t, :keyreq) }.map { |_, n| n },
          optional: params.select { |t, _| @compares_safely.compare(t, :key) }.map { |_, n| n },
          rest: params.find { |t, _| @compares_safely.compare(t, :keyrest) } & [1]
        ),
        keyword_args: dry_call.kwargs,

        block_param: params.find { |t, _| @compares_safely.compare(t, :block) } & [1],
        block_arg: dry_call.block
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mocktail-1.1.2 lib/mocktail/simulates_argument_error/transforms_params.rb