class Loco::RecordArray
Public Class Methods
new(properties={})
click to toggle source
Calls superclass method
Loco::Observable::new
# File lib/motion-loco/record_array.rb, line 27 def initialize(properties={}) super self.content = Array.new self.length = 0 self end
Public Instance Methods
<<(record)
click to toggle source
# File lib/motion-loco/record_array.rb, line 14 def <<(record) self.addObjectsFromArray([record]) end
addObjectsFromArray(objects)
click to toggle source
# File lib/motion-loco/record_array.rb, line 18 def addObjectsFromArray(objects) objects.each do |object| object.send("#{self.belongs_to.class.to_s.underscore}=", self.belongs_to) if self.belongs_to end self.content.addObjectsFromArray(objects) update_properties self end
load(type, data=nil)
click to toggle source
# File lib/motion-loco/record_array.rb, line 34 def load(type, data=nil) if type.is_a? RecordArray self.content = type.content else self.item_class = type self.content.removeAllObjects data.each do |item_data| self.content.addObject(type.new(item_data)) end end update_properties self.is_loaded = true self end
method_missing(method, *args, &block)
click to toggle source
# File lib/motion-loco/record_array.rb, line 51 def method_missing(method, *args, &block) self.content.send(method, *args, &block) end
Private Instance Methods
update_properties()
click to toggle source
# File lib/motion-loco/record_array.rb, line 57 def update_properties self.length = self.content.length if self.belongs_to self.belongs_to.send("#{self.relationship[:has_many].to_s.singularize}_ids=", self.content.map(&:id)) end end