Class: Volt::Persistors::Store

Inherits:
Base show all
Defined in:
lib/volt/models/persistors/store.rb

Direct Known Subclasses

ArrayStore, ModelStore

Constant Summary collapse

@@identity_map =
ModelIdentityMap.new

Instance Method Summary collapse

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.



9
10
11
12
13
14
# File 'lib/volt/models/persistors/store.rb', line 9

def initialize(model, tasks = nil)
  @tasks = tasks
  @model = model

  @saved = false
end

Instance Method Details

#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.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/volt/models/persistors/store.rb', line 22

def read_new_model(method_name)
  # On stores, plural associations are automatically assumed to be
  # collections.
  options = @model.options.merge(parent: @model, path: @model.path + [method_name])
  if method_name.plural?
    model = @model.new_array_model([], options)
  else
    model                          = @model.new_model(nil, options)

    # TODO: Might not need to assign this
    @model.attributes              ||= {}
    @model.attributes[method_name] = model
  end
  model
end

#saved?Boolean

Returns:



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

def saved?
  @saved
end