Class: QML::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, #to_qml
Constructor Details
#initialize(*columns) ⇒ QueryModel
Returns a new instance of QueryModel.
7 8 9 10 11 12 |
# File 'lib/qml/data/query_model.rb', line 7 def initialize(*columns) super @count = 0 @caches = [] update end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
4 5 6 |
# File 'lib/qml/data/query_model.rb', line 4 def count @count end |
Instance Method Details
#[](index) ⇒ Object
14 15 16 17 18 |
# File 'lib/qml/data/query_model.rb', line 14 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.
41 42 43 |
# File 'lib/qml/data/query_model.rb', line 41 def query(offset, count) fail ::NotImplementedError end |
#query_count ⇒ Integer
32 33 34 |
# File 'lib/qml/data/query_model.rb', line 32 def query_count fail ::NotImplementedError end |
#update ⇒ Object
Updates the model.
21 22 23 24 25 26 |
# File 'lib/qml/data/query_model.rb', line 21 def update @caches = [] resetting do @count = query_count end end |