Class: ArrayModel

Inherits:
ReactiveArray show all
Includes:
ModelHelpers, ModelWrapper
Defined in:
lib/volt/models/array_model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ModelHelpers

#deep_unwrap

Methods included from ModelWrapper

#wrap_value, #wrap_values

Methods inherited from ReactiveArray

#==, #[]=, #delete, #delete_at, #each, #insert, #inspect, #method_missing, #split_scope, #trigger_for_index!, #trigger_on_direct_listeners!, #trigger_size_change!

Methods included from ObjectTracking

#__setup_tracking

Methods included from ReactiveTags

included, #reactive_method_tag

Constructor Details

#initialize(array = [], options = {}) ⇒ ArrayModel

Returns a new instance of ArrayModel.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/volt/models/array_model.rb', line 10

def initialize(array=[], options={})
  @options = options
  @parent = options[:parent]
  @path = options[:path] || []
  @persistor = setup_persistor(options[:persistor])
  
  array = wrap_values(array)
  
  super(array)
  
  @persistor.loaded if @persistor
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ReactiveArray

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/volt/models/array_model.rb', line 8

def options
  @options
end

#parentObject (readonly)

Returns the value of attribute parent.



8
9
10
# File 'lib/volt/models/array_model.rb', line 8

def parent
  @parent
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/volt/models/array_model.rb', line 8

def path
  @path
end

#persistorObject (readonly)

Returns the value of attribute persistor.



8
9
10
# File 'lib/volt/models/array_model.rb', line 8

def persistor
  @persistor
end

Instance Method Details

#+(*args) ⇒ Object

Make sure it gets wrapped



43
44
45
46
# File 'lib/volt/models/array_model.rb', line 43

def +(*args)
  args = wrap_values(args)
  super(*args)
end

#<<(*args) ⇒ Object

Make sure it gets wrapped



28
29
30
31
32
33
34
# File 'lib/volt/models/array_model.rb', line 28

def <<(*args)
  args = wrap_values(args)
  
  super(*args)
  
  @persistor.added(args[0], @array.size-1) if @persistor
end

#attributesObject



23
24
25
# File 'lib/volt/models/array_model.rb', line 23

def attributes
  self
end

#inject(*args) ⇒ Object

Make sure it gets wrapped



37
38
39
40
# File 'lib/volt/models/array_model.rb', line 37

def inject(*args)
  args = wrap_values(args)
  super(*args)
end

#new_array_model(*args) ⇒ Object



52
53
54
# File 'lib/volt/models/array_model.rb', line 52

def new_array_model(*args)
  ArrayModel.new(*args)
end

#new_model(*args) ⇒ Object



48
49
50
# File 'lib/volt/models/array_model.rb', line 48

def new_model(*args)
  Model.new(*args)
end

#to_aObject

Convert the model to an array all of the way down



57
58
59
60
61
62
63
64
# File 'lib/volt/models/array_model.rb', line 57

def to_a
  array = []
  attributes.each do |value|      
    array << deep_unwrap(value)
  end
  
  return array
end