Class: SonJay::ModelArray

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
ActsAsModel
Defined in:
lib/son_jay/model_array.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Methods included from ActsAsModel

included, #inspect, #sonj_content, #to_s

Constructor Details

#initializeModelArray

Returns a new instance of ModelArray.



21
22
23
# File 'lib/son_jay/model_array.rb', line 21

def initialize
  @entries = []
end

Class Attribute Details

.entry_classObject

Returns the value of attribute entry_class.



17
18
19
# File 'lib/son_jay/model_array.rb', line 17

def entry_class
  @entry_class
end

Instance Method Details

#additionalObject



29
30
31
32
33
# File 'lib/son_jay/model_array.rb', line 29

def additional
  entry = self.class.entry_class.new
  @entries << entry
  entry
end

#cloneObject



53
54
55
56
57
# File 'lib/son_jay/model_array.rb', line 53

def clone
  new_copy = super
  new_copy.instance_variable_set :@entries, @entries.clone unless new_copy.frozen?
  new_copy
end

#dupObject



47
48
49
50
51
# File 'lib/son_jay/model_array.rb', line 47

def dup
  new_copy = super
  new_copy.instance_variable_set :@entries, @entries.dup
  new_copy
end

#freezeObject



41
42
43
44
45
# File 'lib/son_jay/model_array.rb', line 41

def freeze
  super
  @entries.freeze
  self
end

#load_data(data) ⇒ Object



35
36
37
38
39
# File 'lib/son_jay/model_array.rb', line 35

def load_data(data)
  data.each do |entry_data|
    additional.model_content.load_data entry_data
  end
end

#model_contentObject



25
26
27
# File 'lib/son_jay/model_array.rb', line 25

def model_content
  self
end