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

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.



25
26
27
# File 'lib/dry/auto_inject/method_parameters.rb', line 25

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.



23
24
25
# File 'lib/dry/auto_inject/method_parameters.rb', line 23

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.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dry/auto_inject/method_parameters.rb', line 7

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)


51
# File 'lib/dry/auto_inject/method_parameters.rb', line 51

def empty? = parameters.empty?

#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)


49
# File 'lib/dry/auto_inject/method_parameters.rb', line 49

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

#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.



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

def keyword_names
  @keyword_names ||= parameters.each_with_object(::Set.new) do |(type, name), names|
    names << name if type == :key || type == :keyreq
  end
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.



53
# File 'lib/dry/auto_inject/method_parameters.rb', line 53

def length = parameters.length

#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)


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/dry/auto_inject/method_parameters.rb', line 55

def pass_through?
  return false if parameters.empty?
  return true if parameters.any? { |param| param in [:keyrest, :__auto_inject_kwargs__] }

  parameters.all? do |param|
    case param
    in [:rest, :*] | [:keyrest, :**]
      true
    in [:rest | :req | :opt | :keyrest | :keyreq | :key | :block, _]
      false
    in [:nokey]
      false
    else
      true
    end
  end
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)


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

def sequential_arguments?
  return @sequential_arguments if defined? @sequential_arguments

  @sequential_arguments = parameters.any? do |type, _|
    type == :req || type == :opt
  end
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)


29
30
31
32
33
# File 'lib/dry/auto_inject/method_parameters.rb', line 29

def splat?
  return @splat if defined? @splat

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