Class: Vayacondios::ItemsetHandler

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mongodb) ⇒ ItemsetHandler

Returns a new instance of ItemsetHandler.



14
15
16
# File 'lib/vayacondios/server/handlers/itemset_handler.rb', line 14

def initialize(mongodb)
  @mongo = mongodb
end

Class Method Details

.find(mongodb, options) ⇒ Object

Raises:



47
48
49
50
51
# File 'lib/vayacondios/server/handlers/itemset_handler.rb', line 47

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

Instance Method Details

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



40
41
42
43
44
45
# File 'lib/vayacondios/server/handlers/itemset_handler.rb', line 40

def destroy(document, options={})
  validate_options options
  
  existing_document = ItemsetDocument.find(@mongo, options)
  existing_document.destroy(document)
end

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



29
30
31
32
33
34
35
36
37
38
# File 'lib/vayacondios/server/handlers/itemset_handler.rb', line 29

def patch(document, options={})
  validate_options options

  existing_document = ItemsetDocument.find(@mongo, options)
  if existing_document
    existing_document.patch(document)
  else
    existing_document = ItemsetDocument.create(@mongo, document, options)
  end
end

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



18
19
20
21
22
23
24
25
26
27
# File 'lib/vayacondios/server/handlers/itemset_handler.rb', line 18

def update(document, options={})
  validate_options options

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