Class: Vayacondios::EventDocument
- Defined in:
- lib/vayacondios/server/model/event_document.rb
Overview
The event model
Event documents are key-value pairs, represented in JSON. A document consists of a primary key called the topic (_id in mongodb). It belongs to a collection named "#organization_name.##topic.events"
Note: mongodb is passed in beacuse Goliath makes Thread lookups will not work while Goliath is in a streaming context.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#organization ⇒ Object
readonly
Returns the value of attribute organization.
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
Class Method Summary collapse
Instance Method Summary collapse
- #destroy(document) ⇒ Object
- #find ⇒ Object
-
#initialize(mongodb, options = {}) ⇒ EventDocument
constructor
A new instance of EventDocument.
- #update(document) ⇒ Object
Methods inherited from Document
Constructor Details
#initialize(mongodb, options = {}) ⇒ EventDocument
Returns a new instance of EventDocument.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vayacondios/server/model/event_document.rb', line 15 def initialize(mongodb, = {}) super @mongo = mongodb = () @body = nil @id = format_id([:id]) @mongo = mongodb collection_name = [organization, topic, 'events'].join('.') @collection = @mongo.collection(collection_name) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
13 14 15 |
# File 'lib/vayacondios/server/model/event_document.rb', line 13 def body @body end |
#organization ⇒ Object (readonly)
Returns the value of attribute organization.
13 14 15 |
# File 'lib/vayacondios/server/model/event_document.rb', line 13 def organization @organization end |
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
13 14 15 |
# File 'lib/vayacondios/server/model/event_document.rb', line 13 def topic @topic end |
Class Method Details
.create(mongodb, document, options = {}) ⇒ Object
28 29 30 |
# File 'lib/vayacondios/server/model/event_document.rb', line 28 def self.create(mongodb, document, ={}) self.new(mongodb, ).update(document) end |
.find(mongodb, options = {}) ⇒ Object
32 33 34 |
# File 'lib/vayacondios/server/model/event_document.rb', line 32 def self.find(mongodb, ={}) self.new(mongodb, ).find end |
Instance Method Details
#destroy(document) ⇒ Object
62 63 64 |
# File 'lib/vayacondios/server/model/event_document.rb', line 62 def destroy(document) super end |
#find ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vayacondios/server/model/event_document.rb', line 36 def find result = @collection.find_one({_id: @id}) if result.present? result.delete("_id") result['_timestamp'] = result.delete("t") result.merge! result.delete("d") if result["d"].present? @body = result self else nil end end |
#update(document) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/vayacondios/server/model/event_document.rb', line 49 def update(document) document = to_mongo(document) @body = document[:d] if @id @collection.update({:_id => @id}, document, {upsert: true}) else @collection.insert(document) end self end |