Sha256: 309fa07914a38df4e06c73abcd320635594dd3f5f5d356e718a60e6fadf096af

Contents?: true

Size: 1.01 KB

Versions: 7

Compression:

Stored size: 1.01 KB

Contents

module Mongoid #:nodoc:
  module Associations #:nodoc:
    class Options #:nodoc:

      # Create the new +Options+ object, which provides convenience methods for
      # accessing values out of an options +Hash+.
      def initialize(attributes = {})
        @attributes = attributes
      end

      # Returns the association name of the options.
      def name
        @attributes[:name]
      end

      # Returns the name of the inverse_of association
      def inverse_of
        @attributes[:inverse_of]
      end

      # Return a +Class+ for the options. If a class_name was provided, then the
      # constantized class_name will be returned. If not, a constant based on the
      # association name will be returned.
      def klass
        class_name = @attributes[:class_name]
        class_name ? class_name.constantize : name.to_s.classify.constantize
      end

      # Returns whether or not this association is polymorphic.
      def polymorphic
        @attributes[:polymorphic] == true
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mongoid-0.9.2 lib/mongoid/associations/options.rb
mongoid-0.9.1 lib/mongoid/associations/options.rb
mongoid-0.9.0 lib/mongoid/associations/options.rb
mongoid-0.8.10 lib/mongoid/associations/options.rb
mongoid-0.8.9 lib/mongoid/associations/options.rb
mongoid-0.8.8 lib/mongoid/associations/options.rb
mongoid-0.8.7 lib/mongoid/associations/options.rb