Class: DexieCable::Query
- Inherits:
-
Object
- Object
- DexieCable::Query
- Defined in:
- lib/dexiecable/query.rb
Overview
Builds a chain of Dexie.js operations and transmits them as a single payload once a write operation is reached.
DexieCable::Query.new(channel, "messages")
.where(:room_id).equals(5)
.add(text: "hello")
Constant Summary collapse
- WRITE_OPS =
%i[ add bulkAdd put bulkPut bulkDelete upsert update delete modify clear ].freeze
Instance Attribute Summary collapse
-
#query ⇒ Object
Returns the value of attribute query.
Instance Method Summary collapse
-
#initialize(transmitter, name) ⇒ Query
constructor
A new instance of Query.
- #method_missing(method, *params) ⇒ Object
- #respond_to_missing?(method) ⇒ Boolean
Constructor Details
#initialize(transmitter, name) ⇒ Query
Returns a new instance of Query.
19 20 21 22 |
# File 'lib/dexiecable/query.rb', line 19 def initialize(transmitter, name) @transmitter = transmitter @query = { table: name, ops: [] } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *params) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/dexiecable/query.rb', line 24 def method_missing(method, *params) @query[:ops] << { method: method, params: params } if WRITE_OPS.include?(method) @transmitter.transmit(query) else self end end |
Instance Attribute Details
#query ⇒ Object
Returns the value of attribute query.
17 18 19 |
# File 'lib/dexiecable/query.rb', line 17 def query @query end |
Instance Method Details
#respond_to_missing?(method) ⇒ Boolean
33 34 35 |
# File 'lib/dexiecable/query.rb', line 33 def respond_to_missing?(method, *) true end |