Sha256: 27b19b25fbd978c509ae3a29126c6af6d90378bfd8ffd486212ce877fbe9b377

Contents?: true

Size: 1.26 KB

Versions: 20

Compression:

Stored size: 1.26 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

      def respond_to_missing?(name, include_private = false)
        @repository.respond_to?(name) || super
      end

    end

  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
locomotivecms_steam-1.7.1 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.7.0 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.6.1 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.6.0 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.6.0.rc1 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.6.0.beta1 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.5.3 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.5.2 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.5.1 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.5.0 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.5.0.rc1 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.5.0.rc0 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.5.0.beta3 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.5.0.beta2 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.5.0.beta1 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.4.1 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.4.0 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.4.0.rc2 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.4.0.rc1 lib/locomotive/steam/models/associations/embedded.rb
locomotivecms_steam-1.4.0.pre.rc.1 lib/locomotive/steam/models/associations/embedded.rb