Class: MongoMapper::Plugins::Associations::Base
- Inherits:
-
Object
- Object
- MongoMapper::Plugins::Associations::Base
show all
- Defined in:
- lib/mongo_mapper/plugins/associations/base.rb
Constant Summary
collapse
- AssociationOptions =
Options that should not be considered MongoDB query options/criteria
[:as, :class, :class_name, :dependent, :extend, :foreign_key, :in, :polymorphic, :autosave, :touch]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, options = {}, &extension) ⇒ Base
Returns a new instance of Base.
11
12
13
14
15
16
|
# File 'lib/mongo_mapper/plugins/associations/base.rb', line 11
def initialize(name, options={}, &extension)
@name, @options, @query_options, @original_options = name.to_sym, {}, {}, options
options.symbolize_keys!
options[:extend] = modularized_extensions(extension, options[:extend])
separate_options_and_conditions
end
|
Instance Attribute Details
Returns the value of attribute name.
6
7
8
|
# File 'lib/mongo_mapper/plugins/associations/base.rb', line 6
def name
@name
end
|
Returns the value of attribute options.
6
7
8
|
# File 'lib/mongo_mapper/plugins/associations/base.rb', line 6
def options
@options
end
|
#query_options ⇒ Object
Returns the value of attribute query_options.
6
7
8
|
# File 'lib/mongo_mapper/plugins/associations/base.rb', line 6
def query_options
@query_options
end
|
Instance Method Details
50
51
52
|
# File 'lib/mongo_mapper/plugins/associations/base.rb', line 50
def as
@options[:as] || self.name
end
|
30
31
32
|
# File 'lib/mongo_mapper/plugins/associations/base.rb', line 30
def as?
!!@options[:as]
end
|
69
70
71
|
# File 'lib/mongo_mapper/plugins/associations/base.rb', line 69
def autosave?
raise NotImplementedError
end
|
#class_name ⇒ Object
18
19
20
|
# File 'lib/mongo_mapper/plugins/associations/base.rb', line 18
def class_name
@class_name ||= options[:class_name] || name.to_s.camelize
end
|
#embeddable? ⇒ Boolean
38
39
40
|
# File 'lib/mongo_mapper/plugins/associations/base.rb', line 38
def embeddable?
klass.embeddable?
end
|
#foreign_key ⇒ Object
54
55
56
|
# File 'lib/mongo_mapper/plugins/associations/base.rb', line 54
def foreign_key
@options[:foreign_key] || "#{name}_id"
end
|
34
35
36
|
# File 'lib/mongo_mapper/plugins/associations/base.rb', line 34
def in_array?
!!@options[:in]
end
|
58
59
60
|
# File 'lib/mongo_mapper/plugins/associations/base.rb', line 58
def ivar
@ivar ||= "@_#{name}"
end
|
22
23
24
|
# File 'lib/mongo_mapper/plugins/associations/base.rb', line 22
def klass
@klass ||= options[:class] || class_name.constantize
end
|
#polymorphic? ⇒ Boolean
26
27
28
|
# File 'lib/mongo_mapper/plugins/associations/base.rb', line 26
def polymorphic?
!!@options[:polymorphic]
end
|
#proxy_class ⇒ Object
62
63
64
|
# File 'lib/mongo_mapper/plugins/associations/base.rb', line 62
def proxy_class
raise NotImplementedError
end
|
#setup(model) ⇒ Object
66
67
|
# File 'lib/mongo_mapper/plugins/associations/base.rb', line 66
def setup(model)
end
|
42
43
44
|
# File 'lib/mongo_mapper/plugins/associations/base.rb', line 42
def touch?
!!@options[:touch]
end
|
#type_key_name ⇒ Object
46
47
48
|
# File 'lib/mongo_mapper/plugins/associations/base.rb', line 46
def type_key_name
"_type"
end
|