Class: Volt::Persistors::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/volt/models/persistors/base.rb

Overview

Implements the base persistor functionality.

Direct Known Subclasses

Cookies, Flash, LocalStore, Page, Params, Store

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Base

Returns a new instance of Base.



5
6
7
# File 'lib/volt/models/persistors/base.rb', line 5

def initialize(model)
  @model = model
end

Instance Method Details

#added(model, index) ⇒ Object



16
17
# File 'lib/volt/models/persistors/base.rb', line 16

def added(model, index)
end

#auto_generate_idObject

Specify if this collection should auto-generate id’s



35
36
37
# File 'lib/volt/models/persistors/base.rb', line 35

def auto_generate_id
  false
end

#changed(attribute_name) ⇒ Object



13
14
# File 'lib/volt/models/persistors/base.rb', line 13

def changed(attribute_name)
end

#clearObject

Called when the model is cleared (all child models removed)



25
26
# File 'lib/volt/models/persistors/base.rb', line 25

def clear
end

#event_added(event, first, first_for_event) ⇒ Object



28
29
# File 'lib/volt/models/persistors/base.rb', line 28

def event_added(event, first, first_for_event)
end

#event_removed(event, last, last_for_event) ⇒ Object



31
32
# File 'lib/volt/models/persistors/base.rb', line 31

def event_removed(event, last, last_for_event)
end

#loaded(initial_state = nil) ⇒ Object



9
10
11
# File 'lib/volt/models/persistors/base.rb', line 9

def loaded(initial_state = nil)
  @model.change_state_to(:loaded_state, initial_state || :loaded)
end

#removed(attribute_name) ⇒ Object

For removed, the default action is to call changed for it



20
21
22
# File 'lib/volt/models/persistors/base.rb', line 20

def removed(attribute_name)
  changed(attribute_name)
end

#root_modelObject

Find the root for this model



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/volt/models/persistors/base.rb', line 40

def root_model
  node = @model

  loop do
    parent = node.parent
    if parent
      node = parent
    else
      break
    end
  end

  node
end