Class: Foobara::CommandConnectors::ShCliConnector::InputsParser::Option::Attributes

Inherits:
Option
  • Object
show all
Defined in:
foobara-sh-cli-connector-1.1.4/src/sh_cli_connector/inputs_parser/option/attributes.rb

Class Method Summary collapse

Class Method Details

.applicable?(attribute_type) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'src/sh_cli_connector/inputs_parser/option/attributes.rb', line 8

def applicable?(attribute_type)
  attribute_type.extends?(BuiltinTypes[:attributes])
end

.attribute_to_options(attribute_name, attribute_type:, prefix:, is_required:, default:, always_prefix_inputs:) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'src/sh_cli_connector/inputs_parser/option/attributes.rb', line 12

def attribute_to_options(
  attribute_name,
  attribute_type:,
  prefix:,
  is_required:,
  default:,
  always_prefix_inputs:
)
  sub_required_attributes = if is_required
                              attribute_type.declaration_data[:required]
                            end || []

  defaults = attribute_type.declaration_data[:defaults] || {}

  attribute_type.element_types.map do |sub_attribute_name, sub_attribute_type|
    Option.attribute_to_options(
      sub_attribute_name,
      attribute_type: sub_attribute_type,
      prefix: [*prefix, *attribute_name],
      is_required: is_required && sub_required_attributes.include?(sub_attribute_name),
      default: defaults[sub_attribute_name],
      always_prefix_inputs:
    )
  end.flatten
end