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.

[[:rest]]
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.



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

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.



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

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.

see bugs.ruby-lang.org/issues/13973



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dry/auto_inject/method_parameters.rb', line 27

def self.of(obj, name)
  Enumerator.new do |y|
    begin
      method = obj.instance_method(name)
    rescue NameError
    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)


77
78
79
# File 'lib/dry/auto_inject/method_parameters.rb', line 77

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)


73
74
75
# File 'lib/dry/auto_inject/method_parameters.rb', line 73

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.



67
68
69
70
71
# File 'lib/dry/auto_inject/method_parameters.rb', line 67

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.



81
82
83
# File 'lib/dry/auto_inject/method_parameters.rb', line 81

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)


85
86
87
# File 'lib/dry/auto_inject/method_parameters.rb', line 85

def pass_through?
  parameters.eql?(PASS_THROUGH)
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)


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

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)


55
56
57
58
# File 'lib/dry/auto_inject/method_parameters.rb', line 55

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