Sha256: 68a415efb0cd4746241eadd610360bf844fd1cbab993ea63b04de59ed819c9a9

Contents?: true

Size: 1.34 KB

Versions: 21

Compression:

Stored size: 1.34 KB

Contents

# encoding: utf-8
module Mongoid # :nodoc:
  module Relations #:nodoc:

    # The reflections module provides convenience methods that can retrieve
    # useful information about associations.
    module Reflections
      extend ActiveSupport::Concern

      included do

        delegate \
          :reflect_on_association,
          :reflect_on_all_associations, :to => "self.class"
      end

      module ClassMethods #:nodoc

        # Returns the relation metadata for the supplied name.
        #
        # @example Find relation metadata by name.
        #   Person.reflect_on_association(:addresses)
        #
        # @param [ String, Symbol ] name The name of the relation to find.
        #
        # @return [ Metadata ] The matching relation metadata.
        def reflect_on_association(name)
          relations[name.to_s]
        end

        # Returns all relation metadata for the supplied macros.
        #
        # @example Find multiple relation metadata by macro.
        #   Person.reflect_on_all_associations(:embeds_many)
        #
        # @param [ Array<String, Symbol> ] *macros The relation macros.
        #
        # @return [ Array<Metadata> ] The matching relation metadata.
        def reflect_on_all_associations(*macros)
          relations.values.select { |meta| macros.include?(meta.macro) }
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 3 rubygems

Version Path
mongoid-2.1.7 lib/mongoid/relations/reflections.rb
mongoid-2.1.6 lib/mongoid/relations/reflections.rb
mongoid-2.1.5 lib/mongoid/relations/reflections.rb
mongoid-2.1.4 lib/mongoid/relations/reflections.rb
mongoid-2.1.3 lib/mongoid/relations/reflections.rb
mongoid-2.1.2 lib/mongoid/relations/reflections.rb
mongoid-2.1.1 lib/mongoid/relations/reflections.rb
mongoid-2.1.0 lib/mongoid/relations/reflections.rb
mongoid-braxton-2.0.2 lib/mongoid/relations/reflections.rb
mongoid-2.0.2 lib/mongoid/relations/reflections.rb
mongoid-2.0.1 lib/mongoid/relations/reflections.rb
mongoid-2.0.0 lib/mongoid/relations/reflections.rb
mongoid-2.0.0.rc.8 lib/mongoid/relations/reflections.rb
mongoid-2.0.0.rc.7 lib/mongoid/relations/reflections.rb
stonegao-mongoid-2.0.0.rc.6 lib/mongoid/relations/reflections.rb
mongoid-2.0.0.rc.6 lib/mongoid/relations/reflections.rb
mongoid-2.0.0.rc.5 lib/mongoid/relations/reflections.rb
mongoid-2.0.0.rc.4 lib/mongoid/relations/reflections.rb
mongoid-2.0.0.rc.3 lib/mongoid/relations/reflections.rb
mongoid-2.0.0.rc.2 lib/mongoid/relations/reflections.rb