Class: Loco::RecordArray

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
lib/motion-loco/record_array.rb

Instance Method Summary collapse

Methods included from Observable

#init, #register_observer, #remove_all_observers, #remove_observer, #set_properties, #update_attributes

Constructor Details

#initialize(properties = {}) ⇒ RecordArray

Returns a new instance of RecordArray.



27
28
29
30
31
32
# File 'lib/motion-loco/record_array.rb', line 27

def initialize(properties={})
  super
  self.content = Array.new
  self.length = 0
  self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



51
52
53
# File 'lib/motion-loco/record_array.rb', line 51

def method_missing(method, *args, &block)
  self.content.send(method, *args, &block)
end

Instance Method Details

#<<(record) ⇒ Object



14
15
16
# File 'lib/motion-loco/record_array.rb', line 14

def <<(record)
  self.addObjectsFromArray([record])
end

#addObjectsFromArray(objects) ⇒ Object



18
19
20
21
22
23
24
25
# 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) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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