Sha256: c5c0349cb94456325eedf6ca62753286f32012ad7a8b4553d34bc403af2b1cd9

Contents?: true

Size: 950 Bytes

Versions: 5

Compression:

Stored size: 950 Bytes

Contents

require 'volt/models/persistors/base'
require 'volt/models/persistors/model_identity_map'

module Persistors
  class Store < Base

    @@identity_map = ModelIdentityMap.new

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

      @saved = false
    end

    def saved?
      @saved
    end

    # On stores, we store the model so we don't have to look it up
    # every time we do a read.
    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


      return model
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
volt-0.8.14 lib/volt/models/persistors/store.rb
volt-0.8.13 lib/volt/models/persistors/store.rb
volt-0.8.11 lib/volt/models/persistors/store.rb
volt-0.8.10 lib/volt/models/persistors/store.rb
volt-0.8.9 lib/volt/models/persistors/store.rb