Class: Tina4::DocStore::MongoView
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Tina4::DocStore::MongoView
- Defined in:
- lib/tina4/docstore.rb
Overview
A Mongo::Collection::View that also answers to_list, and accepts every sort spelling the fallback Cursor accepts.
Instance Method Summary collapse
-
#method_missing(name, *args, &block) ⇒ Object
A View is IMMUTABLE - sort/limit/skip/projection each return a NEW View.
-
#sort(key_or_list, direction = 1) ⇒ Object
ADR-0036: ONE sort contract on both providers.
-
#to_list ⇒ Object
to_a is the driver's spelling and stays authoritative; to_list is the uniform Tina4 spelling the SQLite Cursor also answers.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
A View is IMMUTABLE - sort/limit/skip/projection each return a NEW View. Without re-wrapping, the first chained call would hand back a bare View and to_list would vanish mid-chain: exactly the "works until you sort it" surprise this ADR exists to stop.
782 783 784 785 |
# File 'lib/tina4/docstore.rb', line 782 def method_missing(name, *args, &block) result = super result.is_a?(::Mongo::Collection::View) ? MongoView.new(result) : result end |
Instance Method Details
#sort(key_or_list, direction = 1) ⇒ Object
ADR-0036: ONE sort contract on both providers.
Mongo::Collection::View#sort takes a single spec document, so sort("total", -1) raised ArgumentError and sort([["total", -1]]) reached the server as an array and came back TypeMismatch. Normalising here means all three spellings work on the driver exactly as they do on the fallback - which is the point of the swap.
774 775 776 |
# File 'lib/tina4/docstore.rb', line 774 def sort(key_or_list, direction = 1) MongoView.new(__getobj__.sort(DocStore.sort_spec(key_or_list, direction).to_h)) end |
#to_list ⇒ Object
to_a is the driver's spelling and stays authoritative; to_list is the uniform Tina4 spelling the SQLite Cursor also answers.
765 |
# File 'lib/tina4/docstore.rb', line 765 def to_list = __getobj__.to_a |