Class: MongoModel::Associations::Base::Definition
- Inherits:
-
Object
- Object
- MongoModel::Associations::Base::Definition
show all
- Defined in:
- lib/mongomodel/concerns/associations/base/definition.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(owner, name, options = {}) ⇒ Definition
Returns a new instance of Definition.
7
8
9
|
# File 'lib/mongomodel/concerns/associations/base/definition.rb', line 7
def initialize(owner, name, options={})
@owner, @name, @options = owner, name, options
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/mongomodel/concerns/associations/base/definition.rb', line 5
def name
@name
end
|
#options ⇒ Object
Returns the value of attribute options.
5
6
7
|
# File 'lib/mongomodel/concerns/associations/base/definition.rb', line 5
def options
@options
end
|
#owner ⇒ Object
Returns the value of attribute owner.
5
6
7
|
# File 'lib/mongomodel/concerns/associations/base/definition.rb', line 5
def owner
@owner
end
|
Class Method Details
.methods(&block) ⇒ Object
58
59
60
61
|
# File 'lib/mongomodel/concerns/associations/base/definition.rb', line 58
def self.methods(&block)
@methods = Proc.new if block_given?
@methods
end
|
.properties ⇒ Object
53
54
55
56
|
# File 'lib/mongomodel/concerns/associations/base/definition.rb', line 53
def self.properties
@properties = Proc.new if block_given?
@properties
end
|
Instance Method Details
#collection? ⇒ Boolean
41
42
43
|
# File 'lib/mongomodel/concerns/associations/base/definition.rb', line 41
def collection?
true
end
|
#define! ⇒ Object
15
16
17
18
19
20
|
# File 'lib/mongomodel/concerns/associations/base/definition.rb', line 15
def define!
owner.instance_exec(self, &self.class.properties) if self.class.properties
owner.instance_exec(self, &self.class.methods) if self.class.methods
self
end
|
#for(instance) ⇒ Object
11
12
13
|
# File 'lib/mongomodel/concerns/associations/base/definition.rb', line 11
def for(instance)
association_class.new(self, instance)
end
|
#klass ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/mongomodel/concerns/associations/base/definition.rb', line 22
def klass
case options[:class]
when Class
options[:class]
when String
options[:class].constantize
else
name.to_s.classify.constantize
end
end
|
#polymorphic? ⇒ Boolean
37
38
39
|
# File 'lib/mongomodel/concerns/associations/base/definition.rb', line 37
def polymorphic?
options[:polymorphic]
end
|
#scope ⇒ Object
45
46
47
|
# File 'lib/mongomodel/concerns/associations/base/definition.rb', line 45
def scope
klass.scoped.apply_finder_options(scope_options)
end
|
#scope_options ⇒ Object
49
50
51
|
# File 'lib/mongomodel/concerns/associations/base/definition.rb', line 49
def scope_options
options.slice(:conditions, :select, :offset, :limit, :order)
end
|
#singular_name ⇒ Object
33
34
35
|
# File 'lib/mongomodel/concerns/associations/base/definition.rb', line 33
def singular_name
name.to_s.singularize
end
|