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, HttpCookiePersistor, 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



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

def added(model, index)
end

#async?Boolean

return true if this persistor is asynchronus and needs to return Promises.

Returns:



45
46
47
# File 'lib/volt/models/persistors/base.rb', line 45

def async?
  false
end

#auto_generate_idObject

Specify if this collection should auto-generate id’s



39
40
41
# File 'lib/volt/models/persistors/base.rb', line 39

def auto_generate_id
  false
end

#changed(attribute_name) ⇒ Object

Method that is called when data on the model changes.



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

def changed(attribute_name)
end

#clearObject

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



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

def clear
end

#event_added(event, first, first_for_event) ⇒ Object



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

def event_added(event, first, first_for_event)
end

#event_removed(event, last, last_for_event) ⇒ Object



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

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



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

def removed(attribute_name)
  changed(attribute_name)
end

#root_modelObject

Find the root for this model



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/volt/models/persistors/base.rb', line 50

def root_model
  node = @model

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

  node
end