Class: Vayacondios::EventHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/vayacondios/server/handlers/event_handler.rb

Class Method Summary collapse

Instance Method Summary collapse

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

Raises:



27
28
29
30
31
# File 'lib/vayacondios/server/handlers/event_handler.rb', line 27

def self.find(mongodb, options)
  existing_document = EventDocument.find(mongodb, options)
  raise Error::NotFound.new unless existing_document
  existing_document
end

Instance Method Details

#update(document, options = {}) ⇒ Object

Raises:



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, options={})
  raise Error::BadRequest.new unless options[:topic]
  raise Error::BadRequest.new if options[:id] && /\W/ =~ options[:id]

  existing_document = EventDocument.find(@mongo, options)
  if existing_document
    existing_document.update(document)
  else
    existing_document = EventDocument.create(@mongo, document, options)
  end
  existing_document.body
end