Class CloudKit::MemoryQuery

  1. lib/cloudkit/store/memory_table.rb
Parent: Object

MemoryQuery is used internally by MemoryTable to configure a query and run it against the store.

Methods

public class

  1. new

public instance

  1. add_condition
  2. run

Public class methods

new ()

Initialize a new MemoryQuery.

[show source]
    # File lib/cloudkit/store/memory_table.rb, line 76
76:     def initialize
77:       @conditions = []
78:     end

Public instance methods

add_condition (key, operator, value)

Add a condition to this query. The operator parameter is ignored at this time, assuming only equality.

[show source]
    # File lib/cloudkit/store/memory_table.rb, line 95
95:     def add_condition(key, operator, value)
96:       @conditions << [key, operator, value]
97:     end
run (table)

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.

[show source]
    # File lib/cloudkit/store/memory_table.rb, line 83
83:     def run(table)
84:       table.keys.inject([]) do |result, key|
85:         if @conditions.all? { |condition| table[key][condition[0]] == condition[2] }
86:           result << table[key].merge(:pk => key)
87:         else
88:           result
89:         end
90:       end
91:     end