Class: Persistors::Store
- Defined in:
- lib/volt/models/persistors/store.rb
Direct Known Subclasses
Instance Method Summary collapse
- #change_channel_connection(add_or_remove, event = nil, scope = nil) ⇒ Object
-
#initialize(model, tasks = nil) ⇒ Store
constructor
A new instance of Store.
-
#read_new_model(method_name) ⇒ Object
On stores, we store the model so we don’t have to look it up every time we do a read.
Methods inherited from Base
#added, #changed, #event_added, #event_removed, #loaded, #removed
Constructor Details
#initialize(model, tasks = nil) ⇒ Store
Returns a new instance of Store.
5 6 7 8 9 |
# File 'lib/volt/models/persistors/store.rb', line 5 def initialize(model, tasks=nil) @model = model @is_tracking = false @tasks = tasks end |
Instance Method Details
#change_channel_connection(add_or_remove, event = nil, scope = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/volt/models/persistors/store.rb', line 11 def change_channel_connection(add_or_remove, event=nil, scope=nil) if (@model.attributes && @model.path.size > 1) || @model.is_a?(ArrayModel) channel_name = self.channel_name.to_s channel_name += "-#{event}" if event puts "Event #{add_or_remove}: #{channel_name} -- #{@model.attributes.inspect}" @tasks.call('ChannelTasks', "#{add_or_remove}_listener", channel_name, scope) end end |
#read_new_model(method_name) ⇒ Object
On stores, we store the model so we don’t have to look it up every time we do a read.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/volt/models/persistors/store.rb', line 24 def read_new_model(method_name) # On stores, plural associations are automatically assumed to be # collections. = @model..merge(parent: @model, path: @model.path + [method_name]) if method_name.plural? model = @model.new_array_model([], ) else model = @model.new_model(nil, ) end @model.attributes ||= {} @model.attributes[method_name] = model # if model.is_a?(StoreArray)# && model.state == :not_loaded # model.load! # end return model end |