Class: ParamsReady::Parameter::StructParameterDefinition

Inherits:
AbstractStructParameterDefinition show all
Defined in:
lib/params_ready/parameter/struct_parameter.rb

Instance Attribute Summary

Attributes inherited from AbstractStructParameterDefinition

#key_map, #names

Attributes inherited from Definition

#default

Attributes inherited from AbstractDefinition

#altn, #name

Instance Method Summary collapse

Methods inherited from AbstractStructParameterDefinition

#add_child, #child_definition, #duplicate_value, #freeze_value, #has_child?, #infer_default, #initialize, #set_default

Methods inherited from Definition

#canonical_default, #default_defined?, #fetch_callable_default, #fetch_default, #finish, #initialize, #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, #initialize, #normalize_alternative_name, #parameter_class

Methods included from Extensions::Freezer

#freeze_variable, #freeze_variables, #variables_to_freeze

Methods included from Extensions::Finalizer

#obligatory, #obligatory!

Methods included from Extensions::ClassReaderWriter

#class_reader_writer

Methods included from Extensions::LateInit

#late_init

Methods included from Extensions::Collection

#collection

Methods included from Extensions::Finalizer::InstanceMethods

#finish

Methods included from Extensions::Freezer::InstanceMethods

#freeze

Constructor Details

This class inherits a constructor from ParamsReady::Parameter::AbstractStructParameterDefinition

Instance Method Details

#add_map(hash) ⇒ Object



51
52
53
54
55
56
# File 'lib/params_ready/parameter/struct_parameter.rb', line 51

def add_map(hash)
  @key_map ||= Helpers::KeyMap.new
  hash.each do |key, value|
    @key_map.map(key, to: value)
  end
end

#ensure_canonical(hash) ⇒ Object

Raises:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/params_ready/parameter/struct_parameter.rb', line 35

def ensure_canonical(hash)
  context = Format.instance(:backend)

  value, _validator = try_canonicalize hash, context, nil, freeze: true
  return value if value.length == hash.length

  extra_keys = hash.keys.select do |key|
    !value.key?(key)
  end.map do |key|
    "'#{key.to_s}'"
  end.join(", ")
  raise ParamsReadyError, "extra keys found -- #{extra_keys}" if extra_keys.length > 0
  value
end

#remap?(context) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
# File 'lib/params_ready/parameter/struct_parameter.rb', line 58

def remap?(context)
  return false if key_map.nil?
  context.remap?
end