class ParamsReady::Parameter::PolymorphParameter
Public Instance Methods
[](key)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/params_ready/parameter/polymorph_parameter.rb, line 35 def to_type bare_value end
type()
click to toggle source
# File lib/params_ready/parameter/polymorph_parameter.rb, line 30 def type return nil unless is_definite? bare_value.name end
Protected Instance Methods
child_for_update(path)
click to toggle source
# File lib/params_ready/parameter/polymorph_parameter.rb, line 52 def child_for_update(path) type, *path = path [self[type], type, path] end
populate_with(value, freeze = false)
click to toggle source
# File lib/params_ready/parameter/polymorph_parameter.rb, line 63 def populate_with(value, freeze = false) @value = if freeze && value.frozen? value else value.dup end self.freeze if freeze self end
updated_clone(_child_name, updated)
click to toggle source
# File lib/params_ready/parameter/polymorph_parameter.rb, line 57 def updated_clone(_child_name, updated) clone = definition.create clone.populate_with(updated, frozen?) clone end