Class: Vayacondios::EventHandler
- Inherits:
-
Object
- Object
- Vayacondios::EventHandler
- Defined in:
- lib/vayacondios/server/handlers/event_handler.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(mongodb) ⇒ EventHandler
constructor
A new instance of EventHandler.
- #update(document, options = {}) ⇒ Object
Constructor Details
#initialize(mongodb) ⇒ EventHandler
Returns a new instance of EventHandler.
10 11 12 |
# File 'lib/vayacondios/server/handlers/event_handler.rb', line 10 def initialize(mongodb) @mongo = mongodb end |
Class Method Details
.find(mongodb, options) ⇒ Object
27 28 29 30 31 |
# File 'lib/vayacondios/server/handlers/event_handler.rb', line 27 def self.find(mongodb, ) existing_document = EventDocument.find(mongodb, ) raise Error::NotFound.new unless existing_document existing_document end |
Instance Method Details
#update(document, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/vayacondios/server/handlers/event_handler.rb', line 14 def update(document, ={}) raise Error::BadRequest.new unless [:topic] raise Error::BadRequest.new if [:id] && /\W/ =~ [:id] existing_document = EventDocument.find(@mongo, ) if existing_document existing_document.update(document) else existing_document = EventDocument.create(@mongo, document, ) end existing_document.body end |