Class: Relaxo::Model::Recordset

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/relaxo/model/recordset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#databaseObject (readonly)

Returns the value of attribute database.



35
36
37
# File 'lib/relaxo/model/recordset.rb', line 35

def database
  @database
end

#klassObject (readonly)

Returns the value of attribute klass.



34
35
36
# File 'lib/relaxo/model/recordset.rb', line 34

def klass
  @klass
end

#viewObject (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

#countObject



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

#offsetObject



42
43
44
# File 'lib/relaxo/model/recordset.rb', line 42

def offset
	@view["offset"]
end

#rowsObject



46
47
48
# File 'lib/relaxo/model/recordset.rb', line 46

def rows
	@view["rows"]
end