Class: CloudKit::MemoryQuery
- Defined in:
- lib/cloudkit/store/memory_table.rb
Overview
MemoryQuery is used internally by MemoryTable to configure a query and run it against the store.
Instance Method Summary collapse
-
#add_condition(key, operator, value) ⇒ Object
Add a condition to this query.
-
#initialize ⇒ MemoryQuery
constructor
Initialize a new MemoryQuery.
-
#run(table) ⇒ Object
Run a query against the provided table using the conditions stored in this MemoryQuery instance.
Constructor Details
#initialize ⇒ MemoryQuery
Initialize a new MemoryQuery.
76 77 78 |
# File 'lib/cloudkit/store/memory_table.rb', line 76 def initialize @conditions = [] end |
Instance Method Details
#add_condition(key, operator, value) ⇒ Object
Add a condition to this query. The operator parameter is ignored at this time, assuming only equality.
95 96 97 |
# File 'lib/cloudkit/store/memory_table.rb', line 95 def add_condition(key, operator, value) @conditions << [key, operator, value] end |
#run(table) ⇒ Object
Run a query against the provided table using the conditions stored in this MemoryQuery instance. Returns all records that match all conditions. Conditions are added using #add_condition.
83 84 85 86 87 88 89 90 91 |
# File 'lib/cloudkit/store/memory_table.rb', line 83 def run(table) table.keys.inject([]) do |result, key| if @conditions.all? { |condition| table[key][condition[0]] == condition[2] } result << table[key].merge(:pk => key) else result end end end |