Sha256: 65658d98109e4319e7122d7df0d4ae46164cdcc21499be10521eea7f603e8869

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

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

module Volt
  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
        model
      end

      def clear_identity_map
        @@identity_map.clear
      end

      def inspect
        "<#{self.class}:#{object_id}>"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
volt-0.9.3.pre2 lib/volt/models/persistors/store.rb
volt-0.9.3.pre1 lib/volt/models/persistors/store.rb
volt-0.9.2 lib/volt/models/persistors/store.rb