Class: RelaxDB::AllDelegator
- Inherits:
-
Delegator
- Object
- Delegator
- RelaxDB::AllDelegator
- Defined in:
- lib/relaxdb/all_delegator.rb
Overview
The AllDelegator allows clients to query CouchDB in a natural way
FooDoc.all - returns all docs in CouchDB of type FooDoc
FooDoc.all.size - issues a query to a reduce function that returns the total number of docs for that class
FooDoc.all.destroy! - TODO - better description
Instance Method Summary collapse
- #__getobj__ ⇒ Object
- #__setobj__(obj) ⇒ Object
- #destroy! ⇒ Object
-
#initialize(class_name, params) ⇒ AllDelegator
constructor
A new instance of AllDelegator.
- #load! ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(class_name, params) ⇒ AllDelegator
Returns a new instance of AllDelegator.
11 12 13 14 15 |
# File 'lib/relaxdb/all_delegator.rb', line 11 def initialize(class_name, params) super([]) @class_name = class_name @params = params end |
Instance Method Details
#__getobj__ ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/relaxdb/all_delegator.rb', line 17 def __getobj__ unless @ids params = {:raw => true}.merge @params result = RelaxDB.rf_view "#{@class_name}_all", params @ids = RelaxDB.ids_from_view result end @ids end |
#__setobj__(obj) ⇒ Object
26 27 28 |
# File 'lib/relaxdb/all_delegator.rb', line 26 def __setobj__ obj # Intentionally empty end |
#destroy! ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/relaxdb/all_delegator.rb', line 40 def destroy! load! @objs.each { |o| o.data["_deleted"] = true } # Direct post rather than bulk save as we don't want validators to be run resp = RelaxDB.db.post("_bulk_docs", {"docs" => @objs}.to_json) JSON.parse resp.body end |