Class: QML::Data::QueryModel
- Defined in:
- lib/qml/data/query_model.rb
Overview
QueryModel provides a list model implementation with database backends like ActiveRecord.
Defined Under Namespace
Classes: Cache
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
Attributes inherited from ListModel
Instance Method Summary collapse
- #[](index) ⇒ Object
-
#initialize(*columns) ⇒ QueryModel
constructor
A new instance of QueryModel.
-
#query(offset, count) ⇒ Array
abstract
Queries a block of records.
-
#query_count ⇒ Integer
abstract
Queries the count of the records.
-
#update ⇒ Object
Updates the model.
Methods inherited from ListModel
#each, #inserting, #moving, #removing, #resetting
Methods included from QML::Dispatchable
Methods included from Wrappable
Constructor Details
#initialize(*columns) ⇒ QueryModel
Returns a new instance of QueryModel.
8 9 10 11 12 13 |
# File 'lib/qml/data/query_model.rb', line 8 def initialize(*columns) super @count = 0 @caches = [] update end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
5 6 7 |
# File 'lib/qml/data/query_model.rb', line 5 def count @count end |
Instance Method Details
#[](index) ⇒ Object
15 16 17 18 19 |
# File 'lib/qml/data/query_model.rb', line 15 def [](index) block_index = index / CACHE_SIZE cache = @caches.find { |c| c.block_index == block_index } || add_cache(block_index) cache.items[index % CACHE_SIZE] end |
#query(offset, count) ⇒ Array
This method is abstract.
Queries a block of records. The results are chached.
42 43 44 |
# File 'lib/qml/data/query_model.rb', line 42 def query(offset, count) fail ::NotImplementedError end |
#query_count ⇒ Integer
33 34 35 |
# File 'lib/qml/data/query_model.rb', line 33 def query_count fail ::NotImplementedError end |
#update ⇒ Object
Updates the model.
22 23 24 25 26 27 |
# File 'lib/qml/data/query_model.rb', line 22 def update @caches = [] resetting do @count = query_count end end |