Class: Relaxo::Model::Recordset
- Inherits:
-
Object
- Object
- Relaxo::Model::Recordset
- Includes:
- Enumerable
- Defined in:
- lib/relaxo/model/recordset.rb
Instance Attribute Summary collapse
-
#dataset ⇒ Object
readonly
Returns the value of attribute dataset.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #each(model = @model, &block) ⇒ Object
- #empty? ⇒ Boolean
- #first ⇒ Object
-
#initialize(dataset, path, model) ⇒ Recordset
constructor
A new instance of Recordset.
- #last ⇒ Object
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
#dataset ⇒ Object (readonly)
Returns the value of attribute dataset.
32 33 34 |
# File 'lib/relaxo/model/recordset.rb', line 32 def dataset @dataset end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
34 35 36 |
# File 'lib/relaxo/model/recordset.rb', line 34 def model @model end |
#path ⇒ Object (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
36 37 38 |
# File 'lib/relaxo/model/recordset.rb', line 36 def empty? !@dataset.each(@path).any? end |
#first ⇒ Object
40 41 42 |
# File 'lib/relaxo/model/recordset.rb', line 40 def first to_a.first end |
#last ⇒ Object
44 45 46 |
# File 'lib/relaxo/model/recordset.rb', line 44 def last to_a.last end |