class ViewComponent::Storybook::MethodArgs::MethodParametersNames

Constants

ARG_TYPES
KWARG_REST
KWARG_TYPES
REQ_ARG_TYPE
REQ_KWARG_TYPE
REST

Attributes

target_method[R]

Public Class Methods

new(target_method) click to toggle source
# File lib/view_component/storybook/method_args/method_parameters_names.rb, line 16
def initialize(target_method)
  @target_method = target_method
end

Public Instance Methods

arg_name(pos) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/view_component/storybook/method_args/method_parameters_names.rb, line 41
def min_arg_count
  req_arg_count
end
req_kwarg_names() click to toggle source
# 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

Private Instance Methods

arg_names() click to toggle source
# File lib/view_component/storybook/method_args/method_parameters_names.rb, line 63
def arg_names
  @arg_names ||= parameters.map do |type, name|
    name if ARG_TYPES.include?(type)
  end.compact
end
kwarg_names() click to toggle source
# File lib/view_component/storybook/method_args/method_parameters_names.rb, line 57
def kwarg_names
  @kwarg_names ||= parameters.map do |type, name|
    name if KWARG_TYPES.include?(type)
  end.compact.to_set
end
named_arg_count() click to toggle source
# File lib/view_component/storybook/method_args/method_parameters_names.rb, line 75
def named_arg_count
  @named_arg_count ||= arg_names.count
end
parameters() click to toggle source
# File lib/view_component/storybook/method_args/method_parameters_names.rb, line 53
def parameters
  @parameters ||= target_method.parameters
end
req_arg_count() click to toggle source
# File lib/view_component/storybook/method_args/method_parameters_names.rb, line 79
def req_arg_count
  @req_arg_count ||= req_arg_names.count
end
req_arg_names() click to toggle source
# File lib/view_component/storybook/method_args/method_parameters_names.rb, line 69
def req_arg_names
  @req_arg_names ||= parameters.map do |type, name|
    name if type == REQ_ARG_TYPE
  end.compact
end
rest_arg_name() click to toggle source
# File lib/view_component/storybook/method_args/method_parameters_names.rb, line 83
def rest_arg_name
  @rest_arg_name ||= parameters.map { |type, name| name if type == REST }.first
end
supports_keyrest?() click to toggle source
# File lib/view_component/storybook/method_args/method_parameters_names.rb, line 87
def supports_keyrest?
  @supports_keyrest ||= parameters.map(&:first).include?(KWARG_REST)
end
supports_rest?() click to toggle source
# File lib/view_component/storybook/method_args/method_parameters_names.rb, line 91
def supports_rest?
  @supports_rest ||= parameters.map(&:first).include?(REST)
end