Class: ArrayModel

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ModelWrapper

#wrap_value, #wrap_values

Methods inherited from ReactiveArray

#==, #[]=, #delete, #delete_at, #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.



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

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.



6
7
8
# File 'lib/volt/models/array_model.rb', line 6

def options
  @options
end

#parentObject (readonly)

Returns the value of attribute parent.



6
7
8
# File 'lib/volt/models/array_model.rb', line 6

def parent
  @parent
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/volt/models/array_model.rb', line 6

def path
  @path
end

#persistorObject (readonly)

Returns the value of attribute persistor.



6
7
8
# File 'lib/volt/models/array_model.rb', line 6

def persistor
  @persistor
end

Instance Method Details

#+(*args) ⇒ Object

Make sure it gets wrapped



41
42
43
44
# File 'lib/volt/models/array_model.rb', line 41

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

#<<(*args) ⇒ Object

Make sure it gets wrapped



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

def <<(*args)
  args = wrap_values(args)
  
  super(*args)
  
  @persistor.added(args[0]) if @persistor
end

#attributesObject



21
22
23
# File 'lib/volt/models/array_model.rb', line 21

def attributes
  self
end

#inject(*args) ⇒ Object

Make sure it gets wrapped



35
36
37
38
# File 'lib/volt/models/array_model.rb', line 35

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

#new_array_model(*args) ⇒ Object



50
51
52
# File 'lib/volt/models/array_model.rb', line 50

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

#new_model(*args) ⇒ Object



46
47
48
# File 'lib/volt/models/array_model.rb', line 46

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