Class: Dry::AutoInject::MethodParameters Private

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/auto_inject/method_parameters.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

PASS_THROUGH =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

[
  [%i[rest]],
  [%i[rest], %i[keyrest]],
  [%i[rest *]],
  [%i[rest *], %i[keyrest **]]
].freeze
EMPTY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

new([])

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameters) ⇒ MethodParameters

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MethodParameters.



34
35
36
# File 'lib/dry/auto_inject/method_parameters.rb', line 34

def initialize(parameters)
  @parameters = parameters
end

Instance Attribute Details

#parametersObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



32
33
34
# File 'lib/dry/auto_inject/method_parameters.rb', line 32

def parameters
  @parameters
end

Class Method Details

.of(obj, name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dry/auto_inject/method_parameters.rb', line 16

def self.of(obj, name)
  Enumerator.new do |y|
    begin
      method = obj.instance_method(name)
    rescue ::NameError # rubocop: disable Lint/SuppressedException
    end

    loop do
      break if method.nil?

      y << MethodParameters.new(method.parameters)
      method = method.super_method
    end
  end
end

Instance Method Details

#empty?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


62
63
64
# File 'lib/dry/auto_inject/method_parameters.rb', line 62

def empty?
  parameters.empty?
end

#keyword?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


58
59
60
# File 'lib/dry/auto_inject/method_parameters.rb', line 58

def keyword?(name)
  keyword_names.include?(name)
end

#keyword_namesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



52
53
54
55
56
# File 'lib/dry/auto_inject/method_parameters.rb', line 52

def keyword_names
  @keyword_names ||= parameters.each_with_object(Set.new) { |(type, name), names|
    names << name if type == :key || type == :keyreq
  }
end

#lengthObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



66
67
68
# File 'lib/dry/auto_inject/method_parameters.rb', line 66

def length
  parameters.length
end

#pass_through?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


70
71
72
# File 'lib/dry/auto_inject/method_parameters.rb', line 70

def pass_through?
  PASS_THROUGH.include?(parameters)
end

#sequential_arguments?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


44
45
46
47
48
49
50
# File 'lib/dry/auto_inject/method_parameters.rb', line 44

def sequential_arguments?
  return @sequential_arguments if defined? @sequential_arguments

  @sequential_arguments = parameters.any? { |type, _|
    type == :req || type == :opt
  }
end

#splat?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


38
39
40
41
42
# File 'lib/dry/auto_inject/method_parameters.rb', line 38

def splat?
  return @splat if defined? @splat

  @splat = parameters.any? { |type, _| type == :rest }
end