Sha256: 6383fc1839c0ae27bf862b554ed36d0a141df526c5bf00d65a5d09fe676a5668

Contents?: true

Size: 1.15 KB

Versions: 28

Compression:

Stored size: 1.15 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 __serialize__(entity)
        # TODO: not implemented yet
      end

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

    end

  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
locomotivecms_steam-1.3.0 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.3.0.rc2 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.1.2 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.2.1 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.3.0.rc1 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.2.0 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.2.0.rc3 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.2.0.rc2 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.2.0.rc1 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.2.0.beta1 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.1.1 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.1.0 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.1.0.rc3 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.1.0.rc2 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.1.0.rc1 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.0.1 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.0.0 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.0.0.rc10 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.0.0.rc9 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.0.0.rc8 lib/locomotive/steam/models/associations/embedded.rb