Class: ParamsReady::Parameter::PolymorphParameter
Instance Attribute Summary
#definition
Instance Method Summary
collapse
#marshal
#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
#==, #dup, #initialize, #inspect, intent_for_children, #match?, #populate, #to_hash, #update_if_applicable, #update_in
#freeze_variable, #freeze_variables, #variables_to_freeze
Methods included from FromHash
#set_from_hash
#freeze
Instance Method Details
#[](key) ⇒ Object
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_on ⇒ Object
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_type ⇒ Object
35
36
37
|
# File 'lib/params_ready/parameter/polymorph_parameter.rb', line 35
def to_type
bare_value
end
|
#type ⇒ Object
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
|