Sha256: 1ebaa1691bae0b26c7a528ec324683f5c0299e44d6ca2335d6dcc9d98423d03f

Contents?: true

Size: 1018 Bytes

Versions: 2

Compression:

Stored size: 1018 Bytes

Contents

# encoding: utf-8

module ROM
  class Session

    # @api private
    class Mapper < ROM::Mapper
      include Proxy, Concord::Public.new(:mapper, :tracker, :identity_map)

      # @api private
      def self.build(mapper, tracker)
        new(mapper, tracker, IdentityMap.build)
      end

      # @api private
      def dirty?(object)
        identity_map.fetch_tuple(identity(object)) != dump(object)
      end

      # @api private
      def load(tuple)
        identity = mapper.identity_from_tuple(tuple)
        identity_map.fetch_object(identity) { load_and_track(identity, tuple) }
      end

      # @api private
      def store_in_identity_map(object)
        identity_map.store(identity(object), object, dump(object))
      end

      private

      # @api private
      def load_and_track(identity, tuple)
        object = mapper.load(tuple)
        tracker.store_persisted(object, self)
        identity_map.store(identity, object, tuple)[identity]
      end

    end # Mapper

  end # Session
end # ROM

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rom-session-0.1.1 lib/rom/session/mapper.rb
rom-session-0.1.0 lib/rom/session/mapper.rb