Class: Vayacondios::Server::Stash
- Inherits:
-
Document
- Object
- Document
- Vayacondios::Server::Stash
show all
- Defined in:
- lib/vayacondios/server/models/stash.rb
Constant Summary
collapse
- LIMIT =
The default number of stashes returned when searching.
50
- SORT =
The default sort order when searching.
'_id'
- ORDER =
'asc'
Constants inherited
from Document
Document::Error
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Document
create, destroy, extract_query_options!, find, #format_response, #receive_organization, #sanitize_location_name, search
Class Method Details
.default_query_options ⇒ Object
Returned as an acknowledgement of the request when there is no better option (#destroy, #update_many, &c.) OK = true
35
36
37
|
# File 'lib/vayacondios/server/models/stash.rb', line 35
def self.default_query_options
{ limit: LIMIT, order: ORDER, sort: SORT }
end
|
Instance Method Details
#document ⇒ Object
46
47
48
|
# File 'lib/vayacondios/server/models/stash.rb', line 46
def document
{ _id: topic }.compact.merge(body || {})
end
|
#external_document ⇒ Object
65
66
67
|
# File 'lib/vayacondios/server/models/stash.rb', line 65
def external_document
{ topic: topic }.merge(body || {})
end
|
#from_document(doc) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/vayacondios/server/models/stash.rb', line 50
def from_document doc
d = {}.tap do |d|
d[:topic] = doc.delete(:_id)
doc = nil if doc.empty?
if body.nil?
new_body = doc
else
new_body = body.merge(doc || {})
end
d[:body] = new_body
end
receive! d
self
end
|
#location ⇒ String
The name of the collection this stash will store its data in.
42
43
44
|
# File 'lib/vayacondios/server/models/stash.rb', line 42
def location
[organization.to_s, 'stash'].join('.')
end
|
#prepare_create(document) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/vayacondios/server/models/stash.rb', line 75
def prepare_create document
if document.is_a? Hash
document.symbolize_keys!
raise Error.new ':topic is a reserved key and cannot be used in a stash document' if document.has_key?(:topic)
end
if id.blank?
raise Error.new 'If not including an Id, the document must be a Hash' unless document.is_a? Hash
receive!(body: document)
else
receive!(body: { id => document })
end
self
end
|
#prepare_destroy(query) ⇒ Object
94
95
96
97
98
|
# File 'lib/vayacondios/server/models/stash.rb', line 94
def prepare_destroy query
filter = query.merge(_id: topic).compact
receive!(filter: filter)
self
end
|
#prepare_find ⇒ Object
89
90
91
92
|
# File 'lib/vayacondios/server/models/stash.rb', line 89
def prepare_find
raise Error.new('Cannot find a stash without a topic') unless topic
self
end
|
#prepare_search(query) ⇒ Object
69
70
71
72
73
|
# File 'lib/vayacondios/server/models/stash.rb', line 69
def prepare_search query
filter = query.merge(_id: topic).compact
receive!(filter: filter)
self
end
|