Sha256: 3be23f635de2af6753d5a95afdf31c4c29a729c94da59717fa0cd664eb038f3e

Contents?: true

Size: 922 Bytes

Versions: 8

Compression:

Stored size: 922 Bytes

Contents

module ROM
  class Repository
    # @api private
    class RelationReader < Module
      # @api private
      attr_reader :klass

      # @api private
      attr_reader :relations

      module InstanceMethods
        # @api private
        def set_relation(name)
          container.
            relations[name].
            with(auto_struct: auto_struct).
            struct_namespace(struct_namespace)
        end
      end

      # @api private
      def initialize(klass, relations)
        @klass = klass
        @relations = relations
        define_readers!
      end

      # @api private
      def included(klass)
        super
        klass.include(InstanceMethods)
      end

      private

      # @api private
      def define_readers!
        relations.each do |name|
          define_method(name) do
            @relations[name] ||= set_relation(name)
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rom-repository-2.0.2 lib/rom/repository/relation_reader.rb
rom-repository-2.0.1 lib/rom/repository/relation_reader.rb
rom-repository-2.0.0 lib/rom/repository/relation_reader.rb
rom-repository-2.0.0.rc2 lib/rom/repository/relation_reader.rb
rom-repository-2.0.0.rc1 lib/rom/repository/relation_reader.rb
rom-repository-2.0.0.beta3 lib/rom/repository/relation_reader.rb
rom-repository-2.0.0.beta2 lib/rom/repository/relation_reader.rb
rom-repository-2.0.0.beta1 lib/rom/repository/relation_reader.rb