Class: ParamsReady::Parameter::PolymorphParameter

Inherits:
Parameter show all
Includes:
Marshaller::ParameterModule, ComplexParameter
Defined in:
lib/params_ready/parameter/polymorph_parameter.rb

Instance Attribute Summary

Attributes inherited from AbstractParameter

#definition

Instance Method Summary collapse

Methods included from Marshaller::ParameterModule

#marshal

Methods included from ComplexParameter

#update_child

Methods inherited from Parameter

#allows_undefined?, #definite_default?, #eligible_for_output?, #find_in_hash, #format, #format_self_permitted, #freeze, #hash, #hash_key, #initialize, #inspect_content, #is_default?, #is_definite?, #is_nil?, #is_undefined?, #memo, #memo!, #nil_default?, #populate_other, #set_from_input, #set_value, #to_hash_if_eligible, #unwrap, #unwrap_or, #wrap_output

Methods inherited from AbstractParameter

#==, #dup, #initialize, #inspect, intent_for_children, #match?, #populate, #to_hash, #update_if_applicable, #update_in

Methods included from Extensions::Freezer

#freeze_variable, #freeze_variables, #variables_to_freeze

Methods included from FromHash

#set_from_hash

Methods included from Extensions::Freezer::InstanceMethods

#freeze

Constructor Details

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

Instance Method Details

#[](key) ⇒ Object

Raises:



39
40
41
42
43
44
45
46
47
48
# File 'lib/params_ready/parameter/polymorph_parameter.rb', line 39

def [](key)
  raise ParamsReadyError, "Type '#{key}' is not set, current type: nil" if is_nil?

  param = bare_value
  if param.name != key
    raise ParamsReadyError, "Type '#{key}' is not set, current type: '#{param.name}'"
  else
    param
  end
end

#permission_depends_onObject



18
19
20
21
22
# File 'lib/params_ready/parameter/polymorph_parameter.rb', line 18

def permission_depends_on
  type = to_type
  return [] if type.nil?
  [type]
end

#set_value_as(value, type, context = Format.instance(:backend), validator = nil) ⇒ Object



24
25
26
27
28
# File 'lib/params_ready/parameter/polymorph_parameter.rb', line 24

def set_value_as(value, type, context = Format.instance(:backend), validator = nil)
  parameter = types[type].create
  parameter.set_value value, context, validator
  @value = parameter
end

#to_typeObject



35
36
37
# File 'lib/params_ready/parameter/polymorph_parameter.rb', line 35

def to_type
  bare_value
end

#typeObject



30
31
32
33
# File 'lib/params_ready/parameter/polymorph_parameter.rb', line 30

def type
  return nil unless is_definite?
  bare_value.name
end