Sha256: e742d9b5e75b50ee3e4f02178565f7deca73af62cd9c5541179d59afecb243c2

Contents?: true

Size: 1.27 KB

Versions: 33

Compression:

Stored size: 1.27 KB

Contents

# encoding: utf-8
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

      # Return the foreign key based off the association name.
      def foreign_key
        name.to_s.foreign_key
      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 the association name of the options.
      def name
        @attributes[:name]
      end

      # Returns the parent foreign key association name.
      def parent_key
        @attributes[:parent_key]
      end

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

    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
mongoid-1.1.1 lib/mongoid/associations/options.rb
mongoid-1.1.0 lib/mongoid/associations/options.rb
mongoid-1.0.6 lib/mongoid/associations/options.rb
mongoid-1.0.5 lib/mongoid/associations/options.rb
mongoid-1.0.4 lib/mongoid/associations/options.rb
mongoid-1.0.3 lib/mongoid/associations/options.rb
mongoid-1.0.2 lib/mongoid/associations/options.rb
mongoid-1.0.1 lib/mongoid/associations/options.rb
mongoid-1.0.0 lib/mongoid/associations/options.rb
mongoid-0.12.0 lib/mongoid/associations/options.rb
mongoid-0.11.9 lib/mongoid/associations/options.rb
mongoid-0.11.8 lib/mongoid/associations/options.rb
mongoid-0.11.7 lib/mongoid/associations/options.rb
mongoid-0.11.6 lib/mongoid/associations/options.rb
mongoid-0.11.5 lib/mongoid/associations/options.rb
mongoid-0.11.4 lib/mongoid/associations/options.rb
mongoid-0.11.3 lib/mongoid/associations/options.rb
mongoid-0.11.2 lib/mongoid/associations/options.rb
mongoid-0.11.1 lib/mongoid/associations/options.rb
mongoid-0.11.0 lib/mongoid/associations/options.rb