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, #async?, #auto_generate_id, #changed, #clear, #event_added, #event_removed, #loaded, #removed, #root_model

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

#clear_identity_mapObject



40
41
42
# File 'lib/volt/models/persistors/store.rb', line 40

def clear_identity_map
  @@identity_map.clear
end

#inspectObject



44
45
46
# File 'lib/volt/models/persistors/store.rb', line 44

def inspect
  "<#{self.class}:#{object_id}>"
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.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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
    options[:persistor] = @model.persistor
    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