Sha256: 63d13f99c71d31c1872cb406a74bc733402687271480989af9ff6b61d0322576

Contents?: true

Size: 1.26 KB

Versions: 50

Compression:

Stored size: 1.26 KB

Contents

module Locomotive::Steam
  module Models

    class ReferencedAssociation

      attr_reader :repository

      def initialize(repository_klass, scope, adapter, options = {}, &block)
        # build a new instance of the target repository
        @repository = repository_klass.new(adapter)

        # Note: if we change the locale of the parent repository, that won't
        # reflect in that repository
        @repository.scope = scope.dup

        # the block will executed when a method of the target will be called
        @block = block_given? ? block : nil

        @options = options
      end

      def __name__
        @options[:association_name]
      end

      def __attach__(entity)
        @entity = entity
      end

      def __load__
        # needs implementation
      end

      def __serialize__(entity)
        # needs implementation
      end

      def __call_block_once__
        # setup the repository if custom configuration from the
        # repository for instance.
        if @block
          @block.call(@repository, @options)
          @block = nil # trick to call it only once
        end
      end

      def method_missing(name, *args, &block)
        __call_block_once__

        __load__.try(:send, name, *args, &block)
      end

    end

  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
locomotivecms_steam-1.8.0.alpha2 lib/locomotive/steam/models/associations/referenced.rb
locomotivecms_steam-1.8.0.alpha1 lib/locomotive/steam/models/associations/referenced.rb
locomotivecms_steam-1.7.1 lib/locomotive/steam/models/associations/referenced.rb
locomotivecms_steam-1.7.0 lib/locomotive/steam/models/associations/referenced.rb
locomotivecms_steam-1.6.1 lib/locomotive/steam/models/associations/referenced.rb
locomotivecms_steam-1.6.0 lib/locomotive/steam/models/associations/referenced.rb
locomotivecms_steam-1.6.0.rc1 lib/locomotive/steam/models/associations/referenced.rb
locomotivecms_steam-1.6.0.beta1 lib/locomotive/steam/models/associations/referenced.rb
locomotivecms_steam-1.5.3 lib/locomotive/steam/models/associations/referenced.rb
locomotivecms_steam-1.5.2 lib/locomotive/steam/models/associations/referenced.rb
locomotivecms_steam-1.5.1 lib/locomotive/steam/models/associations/referenced.rb
locomotivecms_steam-1.5.0 lib/locomotive/steam/models/associations/referenced.rb
locomotivecms_steam-1.5.0.rc1 lib/locomotive/steam/models/associations/referenced.rb
locomotivecms_steam-1.5.0.rc0 lib/locomotive/steam/models/associations/referenced.rb
locomotivecms_steam-1.5.0.beta3 lib/locomotive/steam/models/associations/referenced.rb
locomotivecms_steam-1.5.0.beta2 lib/locomotive/steam/models/associations/referenced.rb
locomotivecms_steam-1.5.0.beta1 lib/locomotive/steam/models/associations/referenced.rb
locomotivecms_steam-1.4.1 lib/locomotive/steam/models/associations/referenced.rb
locomotivecms_steam-1.4.0 lib/locomotive/steam/models/associations/referenced.rb
locomotivecms_steam-1.4.0.rc2 lib/locomotive/steam/models/associations/referenced.rb