Module: Delayed::ShallowMongoid
- Defined in:
- lib/delayed/shallow_mongoid.rb,
lib/delayed/shallow_mongoid/mongoid.rb,
lib/delayed/shallow_mongoid/version.rb,
lib/delayed/shallow_mongoid/document_stub.rb
Defined Under Namespace
Modules: Errors
Classes: DocumentStub
Constant Summary
collapse
- VERSION =
'1.2.0'
Class Method Summary
collapse
Class Method Details
.dump(arg) ⇒ Object
8
9
10
11
12
13
14
15
16
|
# File 'lib/delayed/shallow_mongoid.rb', line 8
def self.dump(arg)
return arg unless arg.is_a?(::Mongoid::Document) && arg.persisted?
return arg if arg._updates.any? && !Delayed::Worker.delay_jobs
if arg.embedded?
Delayed::ShallowMongoid::DocumentStub.new(arg._root.class, arg._root._id.to_s, selector_from(arg))
else
Delayed::ShallowMongoid::DocumentStub.new(arg.class, arg._id.to_s)
end
end
|
7
8
9
10
11
12
13
|
# File 'lib/delayed/shallow_mongoid/mongoid.rb', line 7
def self.metadata(instance)
if Delayed::ShallowMongoid.mongoid3?
instance.metadata
else
instance.relation_metadata
end
end
|
.mongoid3? ⇒ Boolean
3
4
5
|
# File 'lib/delayed/shallow_mongoid/mongoid.rb', line 3
def self.mongoid3?
::Mongoid.const_defined? :Observer end
|
.selector_from(doc) ⇒ Object
The chain of relations allowing us to locate an embedded document. E.g., [‘images’, [‘find’, ‘4eef..678’], ‘width’]
35
36
37
38
39
40
41
42
43
|
# File 'lib/delayed/shallow_mongoid.rb', line 35
def self.selector_from(doc)
[].tap do |selector|
while doc._parent
selector.unshift ['find', doc._id.to_s] if Delayed::ShallowMongoid.metadata(doc).macro == :embeds_many
selector.unshift Delayed::ShallowMongoid.metadata(doc).key
doc = doc._parent
end
end
end
|