Class: Mocktail::TransformsParams
- Inherits:
-
Object
- Object
- Mocktail::TransformsParams
- Extended by:
- T::Sig
- Defined in:
- lib/mocktail/simulates_argument_error/transforms_params.rb,
lib/mocktail/sorbet/mocktail/simulates_argument_error/transforms_params.rb
Instance Method Summary collapse
-
#initialize ⇒ TransformsParams
constructor
A new instance of TransformsParams.
- #transform(dry_call, params: nil) ⇒ Object
Constructor Details
#initialize ⇒ TransformsParams
Returns a new instance of TransformsParams.
7 8 9 |
# File 'lib/mocktail/simulates_argument_error/transforms_params.rb', line 7 def initialize @grabs_original_method_parameters = GrabsOriginalMethodParameters.new end |
Instance Method Details
#transform(dry_call, params: nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mocktail/simulates_argument_error/transforms_params.rb', line 11 def transform(dry_call, params: nil) params ||= @grabs_original_method_parameters.grab(dry_call.original_method) params = name_unnamed_params(params) Signature.new( positional_params: Params.new( all: params.select { |t, _| [:req, :opt, :rest].any? { |param_type| Bind.call(t, :==, param_type) } }.map { |pair| pair.fetch(1) }, required: params.select { |t, _| Bind.call(t, :==, :req) }.map { |pair| pair.fetch(1) }, optional: params.select { |t, _| Bind.call(t, :==, :opt) }.map { |pair| pair.fetch(1) }, rest: params.find { |t, _| Bind.call(t, :==, :rest) }&.last ), positional_args: dry_call.args, keyword_params: Params.new( all: params.select { |type, _| [:keyreq, :key, :keyrest].include?(type) }.map { |pair| pair.fetch(1) }, required: params.select { |t, _| Bind.call(t, :==, :keyreq) }.map { |pair| pair.fetch(1) }, optional: params.select { |t, _| Bind.call(t, :==, :key) }.map { |pair| pair.fetch(1) }, rest: params.find { |t, _| Bind.call(t, :==, :keyrest) }&.last ), keyword_args: dry_call.kwargs, block_param: params.find { |t, _| Bind.call(t, :==, :block) }&.last, block_arg: dry_call.block ) end |