Class: Mongoid::Associations::Options
- Defined in:
- lib/mongoid/associations/options.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#extension ⇒ Object
Returns the extension if it exists, nil if not.
-
#extension? ⇒ Boolean
Returns true is the options have extensions.
-
#foreign_key ⇒ Object
Return the foreign key based off the association name.
-
#initialize(attributes = {}) ⇒ Options
constructor
Create the new
Options
object, which provides convenience methods for accessing values out of an optionsHash
. -
#inverse_of ⇒ Object
Returns the name of the inverse_of association.
-
#klass ⇒ Object
Return a
Class
for the options. -
#name ⇒ Object
Returns the association name of the options.
-
#polymorphic ⇒ Object
Returns whether or not this association is polymorphic.
-
#stored_as ⇒ Object
Used with has_many_related to save as array of ids.
Constructor Details
#initialize(attributes = {}) ⇒ Options
Create the new Options
object, which provides convenience methods for accessing values out of an options Hash
.
8 9 10 |
# File 'lib/mongoid/associations/options.rb', line 8 def initialize(attributes = {}) @attributes = attributes end |
Instance Method Details
#extension ⇒ Object
Returns the extension if it exists, nil if not.
13 14 15 |
# File 'lib/mongoid/associations/options.rb', line 13 def extension @attributes[:extend] end |
#extension? ⇒ Boolean
Returns true is the options have extensions.
18 19 20 |
# File 'lib/mongoid/associations/options.rb', line 18 def extension? !extension.nil? end |
#foreign_key ⇒ Object
Return the foreign key based off the association name.
23 24 25 26 |
# File 'lib/mongoid/associations/options.rb', line 23 def foreign_key key = @attributes[:foreign_key] || klass.name.to_s.foreign_key key.to_s end |
#inverse_of ⇒ Object
Returns the name of the inverse_of association
29 30 31 |
# File 'lib/mongoid/associations/options.rb', line 29 def inverse_of @attributes[:inverse_of] end |
#klass ⇒ Object
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.
36 37 38 39 |
# File 'lib/mongoid/associations/options.rb', line 36 def klass class_name = @attributes[:class_name] class_name ? class_name.constantize : name.to_s.classify.constantize end |
#name ⇒ Object
Returns the association name of the options.
42 43 44 |
# File 'lib/mongoid/associations/options.rb', line 42 def name @attributes[:name].to_s end |
#polymorphic ⇒ Object
Returns whether or not this association is polymorphic.
47 48 49 |
# File 'lib/mongoid/associations/options.rb', line 47 def polymorphic @attributes[:polymorphic] == true end |
#stored_as ⇒ Object
Used with has_many_related to save as array of ids.
52 53 54 |
# File 'lib/mongoid/associations/options.rb', line 52 def stored_as @attributes[:stored_as] end |