Class: Dao::Db::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/dao/db.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, db) ⇒ Collection

Returns a new instance of Collection.



24
25
26
27
# File 'lib/dao/db.rb', line 24

def initialize(name, db)
  @name = name.to_s
  @db = db
end

Instance Method Details

#[](id) ⇒ Object



43
44
45
# File 'lib/dao/db.rb', line 43

def [](id)
  find(id)
end

#allObject



39
40
41
# File 'lib/dao/db.rb', line 39

def all
  find(:all)
end

#delete(id) ⇒ Object



47
48
49
# File 'lib/dao/db.rb', line 47

def delete(id)
  @db.delete(@name, id)
end

#find(id = :all) ⇒ Object



35
36
37
# File 'lib/dao/db.rb', line 35

def find(id = :all)
  @db.find(@name, id)
end

#save(data = {}) ⇒ Object Also known as: create, update



29
30
31
# File 'lib/dao/db.rb', line 29

def save(data = {})
  @db.save(@name, data)
end

#to_hashObject



51
52
53
# File 'lib/dao/db.rb', line 51

def to_hash
  transaction{|y| y[@name]}
end

#to_yaml(*args, &block) ⇒ Object



55
56
57
# File 'lib/dao/db.rb', line 55

def to_yaml(*args, &block)
  Hash.new.update(to_hash).to_yaml(*args, &block)
end

#transaction(*args, &block) ⇒ Object



59
60
61
# File 'lib/dao/db.rb', line 59

def transaction(*args, &block)
  @db.ystore.transaction(*args, &block)
end