Class: ViewComponent::Storybook::MethodArgs::MethodParametersNames
- Inherits:
-
Object
- Object
- ViewComponent::Storybook::MethodArgs::MethodParametersNames
show all
- Defined in:
- lib/view_component/storybook/method_args/method_parameters_names.rb
Constant Summary
collapse
- REQ_KWARG_TYPE =
:keyreq
- KWARG_TYPES =
[REQ_KWARG_TYPE, :key].freeze
- REQ_ARG_TYPE =
:req
- ARG_TYPES =
[REQ_ARG_TYPE, :opt].freeze
- KWARG_REST =
:keyrest
- REST =
:rest
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of MethodParametersNames.
16
17
18
|
# File 'lib/view_component/storybook/method_args/method_parameters_names.rb', line 16
def initialize(target_method)
@target_method = target_method
end
|
Instance Attribute Details
#target_method ⇒ Object
Returns the value of attribute target_method.
14
15
16
|
# File 'lib/view_component/storybook/method_args/method_parameters_names.rb', line 14
def target_method
@target_method
end
|
Instance Method Details
#arg_name(pos) ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/view_component/storybook/method_args/method_parameters_names.rb', line 20
def arg_name(pos)
if pos < named_arg_count
arg_names[pos]
else
offset_pos = pos - named_arg_count
"#{rest_arg_name}#{offset_pos}".to_sym
end
end
|
#covers_required_kwargs?(names) ⇒ Boolean
33
34
35
|
# File 'lib/view_component/storybook/method_args/method_parameters_names.rb', line 33
def covers_required_kwargs?(names)
names.to_set >= req_kwarg_names.to_set
end
|
#include_kwarg?(kwarg_name) ⇒ Boolean
29
30
31
|
# File 'lib/view_component/storybook/method_args/method_parameters_names.rb', line 29
def include_kwarg?(kwarg_name)
supports_keyrest? || kwarg_names.include?(kwarg_name)
end
|
#max_arg_count ⇒ Object
37
38
39
|
# File 'lib/view_component/storybook/method_args/method_parameters_names.rb', line 37
def max_arg_count
supports_rest? ? Float::INFINITY : named_arg_count
end
|
#min_arg_count ⇒ Object
41
42
43
|
# File 'lib/view_component/storybook/method_args/method_parameters_names.rb', line 41
def min_arg_count
req_arg_count
end
|
#req_kwarg_names ⇒ Object
45
46
47
48
49
|
# File 'lib/view_component/storybook/method_args/method_parameters_names.rb', line 45
def req_kwarg_names
@req_kwarg_names ||= parameters.map do |type, name|
name if type == REQ_KWARG_TYPE
end.compact
end
|