Class: Condition::Storage::Mongo

Inherits:
Object
  • Object
show all
Defined in:
lib/condition/storage/mongo.rb

Instance Method Summary collapse

Constructor Details

#initialize(db) ⇒ Mongo

Returns a new instance of Mongo.



6
7
8
# File 'lib/condition/storage/mongo.rb', line 6

def initialize(db)
  @db = db
end

Instance Method Details

#all(param_item) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/condition/storage/mongo.rb', line 10

def all(param_item)
  list = @db[param_item.name].find()
  res = []
  list.each do |row|
    hash = {}
    row.each do |k, v|
      hash[k.to_sym] = v
    end
    res << hash
  end
  res
end

#delete(param_item) ⇒ Object



23
24
25
# File 'lib/condition/storage/mongo.rb', line 23

def delete(param_item)
  @db[param_item.name].remove()
end

#exec_after(param_item) ⇒ Object



34
35
36
37
38
# File 'lib/condition/storage/mongo.rb', line 34

def exec_after(param_item)
  param_item.options.each do |key|
    # nothing
  end
end

#insert(param_item, default) ⇒ Object



27
28
29
30
31
32
# File 'lib/condition/storage/mongo.rb', line 27

def insert(param_item, default)
  default_item = default.item(param_item.name) if default
  param_item.values.each do |it|
    @db[param_item.name].insert(default_item ? default_item.value.merge(it) : it)
  end
end