Sha256: 7cabbaea5b24a0480345e4ca9d2eebb615ba9131fe3f0b3ae2460790451c80bf

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

require 'locomotive/steam/adapters/memory'
require 'morphine'

module Locomotive::Steam
  module Models

    # Note: represents an embedded collection
    class EmbeddedAssociation

      include Morphine

      register :adapter do
        Locomotive::Steam::MemoryAdapter.new(nil)
      end

      # use the scope from the parent repository
      # one of the benefits is that if we change the current locale
      # of the parent repository, that will change the local repository
      # as well.
      def initialize(repository_klass, collection, scope, options = {})
        adapter.collection = collection || []

        @repository = repository_klass.new(adapter)
        @repository.scope = scope

        @options = options
      end

      # In order to keep track of the entity which owns
      # the association.
      def __attach__(entity)
        name = @options[:mapper_name].to_s.singularize.to_sym
        @repository.send(:"#{name}=", entity)
      end

      def method_missing(name, *args, &block)
        @repository.send(name, *args, &block)
      end

    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
locomotivecms_steam-1.0.0.pre.alpha.3 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.0.0.pre.alpha.2 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.0.0.pre.alpha.1 lib/locomotive/steam/models/associations/embedded.rb