Class: Volt::Persistors::Base
- 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
- #added(model, index) ⇒ Object
-
#async? ⇒ Boolean
return true if this persistor is asynchronus and needs to return Promises.
-
#auto_generate_id ⇒ Object
Specify if this collection should auto-generate id’s.
-
#changed(attribute_name) ⇒ Object
Method that is called when data on the model changes.
-
#clear ⇒ Object
Called when the model is cleared (all child models removed).
- #event_added(event, first, first_for_event) ⇒ Object
- #event_removed(event, last, last_for_event) ⇒ Object
-
#initialize(model) ⇒ Base
constructor
A new instance of Base.
- #loaded(initial_state = nil) ⇒ Object
-
#removed(attribute_name) ⇒ Object
For removed, the default action is to call changed for it.
-
#root_model ⇒ Object
Find the root for this model.
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.
45 46 47 |
# File 'lib/volt/models/persistors/base.rb', line 45 def async? false end |
#auto_generate_id ⇒ Object
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 |
#clear ⇒ Object
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_model ⇒ Object
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 |