module ParamsReady::Parameter::ArrayParameter::ArrayLike
Public Instance Methods
[](index)
click to toggle source
# File lib/params_ready/parameter/array_parameter.rb, line 22 def [](index) if index == :cnt || index == 'cnt' count = ValueParameterBuilder.instance(:cnt, :integer).build.create count.set_value(self.length) count.freeze count else element(index) end end
[]=(index, value)
click to toggle source
# File lib/params_ready/parameter/array_parameter.rb, line 16 def []=(index, value) init_for_write c = element(index) c.set_value value end
Protected Instance Methods
child_for_update(path)
click to toggle source
# File lib/params_ready/parameter/array_parameter.rb, line 41 def child_for_update(path) index, *child_path = path child = element(index) raise ParamsReadyError, "No element at index '#{index}' in '#{name}'" if child.nil? [child, index, child_path] end
populate_with(array, freeze = false, replacement = {})
click to toggle source
# File lib/params_ready/parameter/array_parameter.rb, line 48 def populate_with(array, freeze = false, replacement = {}) @value = [] array.each_with_index do |element, index| incoming = replacement[index] || element own = if freeze && incoming.frozen? incoming else incoming.dup end own.freeze if freeze @value << own end self.freeze if freeze self end
updated_clone(index, updated_child)
click to toggle source
# File lib/params_ready/parameter/array_parameter.rb, line 35 def updated_clone(index, updated_child) clone = definition.create clone.populate_with(bare_value, frozen?, { index => updated_child }) clone end