Class: Relaxo::Model::Recordset
- Inherits:
-
Object
- Object
- Relaxo::Model::Recordset
- Includes:
- Enumerable
- Defined in:
- lib/relaxo/model/recordset.rb
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Instance Method Summary collapse
- #count ⇒ Object
- #each(klass = nil, &block) ⇒ Object
-
#initialize(database, view, klass = nil) ⇒ Recordset
constructor
A new instance of Recordset.
- #offset ⇒ Object
- #rows ⇒ Object
Constructor Details
#initialize(database, view, klass = nil) ⇒ Recordset
Returns a new instance of Recordset.
27 28 29 30 31 32 |
# File 'lib/relaxo/model/recordset.rb', line 27 def initialize(database, view, klass = nil) @database = database @view = view @klass = klass end |
Instance Attribute Details
#database ⇒ Object (readonly)
Returns the value of attribute database.
35 36 37 |
# File 'lib/relaxo/model/recordset.rb', line 35 def database @database end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
34 35 36 |
# File 'lib/relaxo/model/recordset.rb', line 34 def klass @klass end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
36 37 38 |
# File 'lib/relaxo/model/recordset.rb', line 36 def view @view end |
Instance Method Details
#count ⇒ Object
38 39 40 |
# File 'lib/relaxo/model/recordset.rb', line 38 def count rows.count end |
#each(klass = nil, &block) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/relaxo/model/recordset.rb', line 50 def each(klass = nil, &block) klass ||= @klass if klass if klass.respond_to? :call rows.each do |row| yield klass.call(@database, row) end else rows.each do |row| # If user specified :include_docs => true, row['doc'] contains the primary value: yield klass.new(@database, row['doc'] || row['value']) end end else rows.each &block end end |
#offset ⇒ Object
42 43 44 |
# File 'lib/relaxo/model/recordset.rb', line 42 def offset @view["offset"] end |
#rows ⇒ Object
46 47 48 |
# File 'lib/relaxo/model/recordset.rb', line 46 def rows @view["rows"] end |