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)
- - (Object) __getobj__
- - (Object) __setobj__(obj)
- - (Object) destroy!
-
- (AllDelegator) initialize(class_name, params)
constructor
A new instance of AllDelegator.
- - (Object) load!
- - (Object) size
Constructor Details
- (AllDelegator) initialize(class_name, params)
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
- (Object) __getobj__
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 |
- (Object) __setobj__(obj)
26 27 28 |
# File 'lib/relaxdb/all_delegator.rb', line 26 def __setobj__ obj # Intentionally empty end |
- (Object) destroy!
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 |
- (Object) load!
30 31 32 33 |
# File 'lib/relaxdb/all_delegator.rb', line 30 def load! __getobj__ @objs = RelaxDB.load! @ids end |
- (Object) size
35 36 37 38 |
# File 'lib/relaxdb/all_delegator.rb', line 35 def size size = RelaxDB.view "#{@class_name}_all", :reduce => true size || 0 end |