couchrest_model/lib/database.rb

32 lines
559 B
Ruby
Raw Normal View History

2008-03-18 19:37:10 +01:00
class CouchRest
class Database
attr_accessor :host, :name
def initialize host, name
@name = name
@host = host
2008-03-19 16:57:20 +01:00
@root = "#{host}/#{name}"
2008-03-18 19:37:10 +01:00
end
2008-03-19 16:57:20 +01:00
def documents
view "_all_docs"
end
def view name
CouchRest.get "#{@root}/#{name}"
end
def save doc
if doc['_id']
url = doc['_id']
CouchRest.put "#{@root}/#{doc['_id']}", doc
else
CouchRest.post "#{@root}", doc
end
end
2008-03-18 19:37:10 +01:00
def delete!
2008-03-19 16:57:20 +01:00
CouchRest.delete @root
2008-03-18 19:37:10 +01:00
end
end
end