Class: ViewComponent::Storybook::MethodArgs::DryInitializerComponentConstructorArgs::DryConstructorParametersNames

Inherits:
MethodParametersNames
  • Object
show all
Defined in:
lib/view_component/storybook/method_args/dry_initializer_component_constructor_args.rb

Overview

Method Parameters names that are dry-initialize aware THe main difference is that Dry Initializer keyword args cannot be deduced from the constructor initialize params Instead we have to introspect the dry_initializer config for the option definitions

Constant Summary

Constants inherited from MethodParametersNames

MethodParametersNames::ARG_TYPES, MethodParametersNames::KWARG_REST, MethodParametersNames::KWARG_TYPES, MethodParametersNames::REQ_ARG_TYPE, MethodParametersNames::REQ_KWARG_TYPE, MethodParametersNames::REST

Instance Attribute Summary collapse

Attributes inherited from MethodParametersNames

#target_method

Instance Method Summary collapse

Methods inherited from MethodParametersNames

#arg_name, #covers_required_kwargs?, #include_kwarg?, #max_arg_count, #min_arg_count

Constructor Details

#initialize(component_class) ⇒ DryConstructorParametersNames

Returns a new instance of DryConstructorParametersNames.



18
19
20
21
# File 'lib/view_component/storybook/method_args/dry_initializer_component_constructor_args.rb', line 18

def initialize(component_class)
  super(component_class.instance_method(INITIALIZE_METHOD))
  @dry_initializer = component_class.dry_initializer
end

Instance Attribute Details

#dry_initializerObject (readonly)

Returns the value of attribute dry_initializer.



16
17
18
# File 'lib/view_component/storybook/method_args/dry_initializer_component_constructor_args.rb', line 16

def dry_initializer
  @dry_initializer
end

Instance Method Details

#req_kwarg_namesObject

Required keywords are the only thing we need. We could define kwarg_names similarly but wihout the ‘optional` check. However, dry-initializer always ends has supports_keyrest? == true so kwarg_names isn’t needed



26
27
28
29
30
# File 'lib/view_component/storybook/method_args/dry_initializer_component_constructor_args.rb', line 26

def req_kwarg_names
  @req_kwarg_names ||= dry_initializer.definitions.map do |name, definition|
    name if definition.option && !definition.optional
  end.compact
end