Sha256: d70392d028b3475d2123ce5820c9c9032855ec4cbdd15bdd854abb91834eabb5
Contents?: true
Size: 1.63 KB
Versions: 1
Compression:
Stored size: 1.63 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 # Returns the extension if it exists, nil if not. def extension @attributes[:extend] end # Returns true is the options have extensions. def extension? !extension.nil? end # Return the foreign key based off the association name. def foreign_key key = @attributes[:foreign_key] || klass.name.to_s.foreign_key key.to_s end # Returns the name of the inverse_of association def inverse_of @attributes[:inverse_of] end # Return a +Class+ for the options. See #class_name def klass class_name.constantize end # Return a +String+ representing the associated class_name. 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 class_name @attributes[:class_name] || name.to_s.classify end # Returns the association name of the options. def name @attributes[:name].to_s end # Returns whether or not this association is polymorphic. def polymorphic @attributes[:polymorphic] == true end # Used with has_many_related to save as array of ids. def stored_as @attributes[:stored_as] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mongoid-2.0.0.beta.5 | lib/mongoid/associations/options.rb |