Class: ParamsReady::Parameter::EnumSetParameterDefinition
- Inherits:
-
AbstractStructParameterDefinition
- Object
- AbstractDefinition
- Definition
- AbstractStructParameterDefinition
- ParamsReady::Parameter::EnumSetParameterDefinition
- Defined in:
- lib/params_ready/parameter/enum_set_parameter.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Attributes inherited from AbstractStructParameterDefinition
Attributes inherited from Definition
Attributes inherited from AbstractDefinition
Instance Method Summary collapse
- #add_child(child, value:) ⇒ Object
- #ensure_canonical(set) ⇒ Object
-
#initialize(*args, type: :boolean, **opts) ⇒ EnumSetParameterDefinition
constructor
A new instance of EnumSetParameterDefinition.
Methods inherited from AbstractStructParameterDefinition
#child_definition, #duplicate_value, #freeze_value, #has_child?, #infer_default, #set_default
Methods inherited from Definition
#canonical_default, #default_defined?, #fetch_callable_default, #fetch_default, #finish, #memoize?, #name_for_formatter, #no_input?, #no_output?, #postprocess, #preprocess, #restricted_for_format?, #set_local, #set_no_input, #set_postprocessor, #set_preprocessor
Methods inherited from AbstractDefinition
#create, #finish, #from_hash, #from_input, #normalize_alternative_name, #parameter_class
Methods included from Extensions::Freezer
#freeze_variable, #freeze_variables, #variables_to_freeze
Methods included from Extensions::Finalizer
Methods included from Extensions::ClassReaderWriter
Methods included from Extensions::LateInit
Methods included from Extensions::Collection
Methods included from Extensions::Finalizer::InstanceMethods
Methods included from Extensions::Freezer::InstanceMethods
Constructor Details
#initialize(*args, type: :boolean, **opts) ⇒ EnumSetParameterDefinition
Returns a new instance of EnumSetParameterDefinition.
67 68 69 70 71 |
# File 'lib/params_ready/parameter/enum_set_parameter.rb', line 67 def initialize(*args, type: :boolean, **opts) @type = type @values = {} super *args, **opts end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
61 62 63 |
# File 'lib/params_ready/parameter/enum_set_parameter.rb', line 61 def type @type end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
61 62 63 |
# File 'lib/params_ready/parameter/enum_set_parameter.rb', line 61 def values @values end |
Instance Method Details
#add_child(child, value:) ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/params_ready/parameter/enum_set_parameter.rb', line 90 def add_child(child, value:) value = value.nil? ? child.name : value if @values.key(value).nil? @values[child.name] = value else raise ParamsReadyError, "Value '#{value}' already taken by '#{@values.key(value)}'" end super child end |
#ensure_canonical(set) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/params_ready/parameter/enum_set_parameter.rb', line 73 def ensure_canonical(set) raise ParamsReadyError, "Unexpected default type: #{set.class.name}" unless set.is_a?(Set) context = Format.instance(:backend) value, _validator = try_canonicalize set, context, nil, freeze: true return value if value.length == set.length extra_keys = set.reject do |key| value.key?(key) || value.key?(key.to_s) end.map do |key| "'#{key.to_s}'" end.join(", ") raise ParamsReadyError, "extra elements found -- #{extra_keys}" if extra_keys.length > 0 value end |