Class: MongoMapper::Document::VeneerInterface::ClassWrapper
Constant Summary
collapse
- PRIMARY_KEYS =
[:_id]
Instance Attribute Summary
#klass, #opts
Class Method Summary
collapse
Instance Method Summary
collapse
#all, #create, #create!, #first, inherited, #initialize, #max, #min, subclasses, #sum, #validators_on
Class Method Details
.model_classes ⇒ Object
9
10
11
|
# File 'lib/veneer/adapters/mongomapper/class_wrapper.rb', line 9
def self.model_classes
::MongoMapper::Document.descendants
end
|
Instance Method Details
#collection_associations ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/veneer/adapters/mongomapper/class_wrapper.rb', line 17
def collection_associations
@collection_associations ||= begin
klass.associations.inject([]) do |ary, (name, assoc)|
if assoc.is_a? ::MongoMapper::Plugins::Associations::ManyAssociation
ary << {
:name => name,
:class => assoc.class_name.constantize
}
end
ary
end
end
end
|
#count(opts = {}) ⇒ Object
77
78
79
|
# File 'lib/veneer/adapters/mongomapper/class_wrapper.rb', line 77
def count(opts={})
opts[:conditions].nil? ? klass.count : klass.count(opts[:conditions])
end
|
#destroy_all ⇒ Object
73
74
75
|
# File 'lib/veneer/adapters/mongomapper/class_wrapper.rb', line 73
def destroy_all
klass.destroy_all
end
|
#find_first(opts) ⇒ Object
81
82
83
|
# File 'lib/veneer/adapters/mongomapper/class_wrapper.rb', line 81
def find_first(opts)
klass.first(opts)
end
|
#find_many(opts) ⇒ Object
85
86
87
|
# File 'lib/veneer/adapters/mongomapper/class_wrapper.rb', line 85
def find_many(opts)
klass.all(opts)
end
|
#member_associations ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/veneer/adapters/mongomapper/class_wrapper.rb', line 31
def member_associations
@member_associations ||= begin
types = [::MongoMapper::Plugins::Associations::BelongsToAssociation,
::MongoMapper::Plugins::Associations::ManyAssociation]
klass.associations.inject([]) do |ary, (name, assoc)|
if types.include?(assoc.class)
ary << {
:name => name,
:class => assoc.class_name.constantize
}
end
ary
end
end
end
|
#new(opts = {}) ⇒ Object
13
14
15
|
# File 'lib/veneer/adapters/mongomapper/class_wrapper.rb', line 13
def new(opts = {})
::Kernel::Veneer(klass.new(opts))
end
|
#properties ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/veneer/adapters/mongomapper/class_wrapper.rb', line 47
def properties
@properties ||= begin
klass.keys.map do |property|
property = property[1]
name = property.name.to_sym
::MongoMapper::Document::VeneerInterface::Property.new(
self,
{
:name => name,
:type => property.type,
:constraints => {
:length => property.options[:length],
:nullable? => nil,
:precision => nil,
},
:primary => primary_keys.include?(name),
}
)
end
end
end
|