Class: ParamsReady::Parameter::HashParameterDefinition

Inherits:
AbstractHashParameterDefinition show all
Defined in:
lib/params_ready/parameter/hash_parameter.rb

Instance Attribute Summary

Attributes inherited from AbstractHashParameterDefinition

#key_map, #names

Attributes inherited from Definition

#default

Attributes inherited from AbstractDefinition

#altn, #name

Instance Method Summary collapse

Methods inherited from AbstractHashParameterDefinition

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

Methods inherited from Definition

#canonical_default, #default_defined?, #duplicate_default, #finish, #initialize, #local?, #memoize?, #name_for_formatter, #no_output?, #postprocess, #preprocess, #set_local, #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::AbstractHashParameterDefinition

Instance Method Details

#add_map(hash) ⇒ Object



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

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:



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

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)


57
58
59
60
# File 'lib/params_ready/parameter/hash_parameter.rb', line 57

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