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(dataset, path, model) ⇒ Recordset

Returns a new instance of Recordset.



26
27
28
29
30
# File 'lib/relaxo/model/recordset.rb', line 26

def initialize(dataset, path, model)
	@dataset = dataset
	@path = path
	@model = model
end

Instance Attribute Details

#datasetObject (readonly)

Returns the value of attribute dataset.



32
33
34
# File 'lib/relaxo/model/recordset.rb', line 32

def dataset
  @dataset
end

#modelObject (readonly)

Returns the value of attribute model.



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

def model
  @model
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#each(model = @model, &block) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/relaxo/model/recordset.rb', line 48

def each(model = @model, &block)
	@dataset.each(@path) do |name, object|
		object = model.new(@dataset, object)
		object.load_object
		
		yield object
	end
end

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
	!@dataset.each(@path).any?
end

#firstObject



40
41
42
# File 'lib/relaxo/model/recordset.rb', line 40

def first
	to_a.first
end

#lastObject



44
45
46
# File 'lib/relaxo/model/recordset.rb', line 44

def last
	to_a.last
end