class Plaster::WrappingList
A list of entry values, each stored in an attribute of an instance of a specified struct-like wrapper class. This allows the list to apply the same enforcement and/or transformation that the wrapper’s attribute write/read process does.
Attributes
wrapper_attrib[R]
wrapper_class[R]
inner_array[R]
Public Class Methods
new()
click to toggle source
# File lib/plaster/wrapping_list.rb, line 32 def initialize @inner_array = [] end
wrapper_attrib_writer()
click to toggle source
# File lib/plaster/wrapping_list.rb, line 13 def wrapper_attrib_writer @wrapper_attrib_writer ||= :"#{wrapper_attrib}=" end
Private Class Methods
wrap_each(klass, attrib)
click to toggle source
Called in the body of a subclass definition to specify the wrapper class and attribute name in which to store each entry.
# File lib/plaster/wrapping_list.rb, line 22 def wrap_each(klass, attrib) @wrapper_class = klass @wrapper_attrib = attrib end
Public Instance Methods
<<(value)
click to toggle source
# File lib/plaster/wrapping_list.rb, line 67 def <<(value) wrapper = self.class.wrapper_class.new wrapper.send self.class.wrapper_attrib_writer, value inner_array << wrapper self end
[](index)
click to toggle source
# File lib/plaster/wrapping_list.rb, line 54 def [](index) wrapper = inner_array[index] wrapper.send self.class.wrapper_attrib end
[]=(index, value)
click to toggle source
# File lib/plaster/wrapping_list.rb, line 40 def []=(index, value) old_length = inner_array.length wrapper = ( inner_array[index] ||= self.class.wrapper_class.new ) wrapper.send self.class.wrapper_attrib_writer, value if index > old_length (old_length...index).each do |fill_idx| inner_array[fill_idx] = self.class.wrapper_class.new end end value end
each() { |value| ... }
click to toggle source
# File lib/plaster/wrapping_list.rb, line 59 def each return Enumerator.new(self, :each) unless block_given? inner_array.each do |wrapper| value = wrapper.send(self.class.wrapper_attrib) yield value end end
model_deconstruct()
click to toggle source
# File lib/plaster/wrapping_list.rb, line 36 def model_deconstruct Plaster.deconstruct( to_a ) end
push(*values)
click to toggle source
# File lib/plaster/wrapping_list.rb, line 74 def push(*values) values.each do |value| self << value end end