Class: Dry::AutoInject::MethodParameters Private
- Inherits:
-
Object
- Object
- Dry::AutoInject::MethodParameters
- 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
- #parameters ⇒ Object readonly private
Class Method Summary collapse
- .of(obj, name) ⇒ Object private
Instance Method Summary collapse
- #empty? ⇒ Boolean private
-
#initialize(parameters) ⇒ MethodParameters
constructor
private
A new instance of MethodParameters.
- #keyword?(name) ⇒ Boolean private
- #keyword_names ⇒ Object private
- #length ⇒ Object private
- #pass_through? ⇒ Boolean private
- #sequential_arguments? ⇒ Boolean private
- #splat? ⇒ Boolean private
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
#parameters ⇒ Object (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.
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.
58 59 60 |
# File 'lib/dry/auto_inject/method_parameters.rb', line 58 def keyword?(name) keyword_names.include?(name) end |
#keyword_names ⇒ 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.
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 |
#length ⇒ 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.
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.
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.
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.
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 |