Class: Dynameek::Model::Query::QueryChain
- Inherits:
-
Object
- Object
- Dynameek::Model::Query::QueryChain
- Defined in:
- lib/dynameek/model/query.rb
Overview
Similar to dynamoids approach but lighter (hopefully)
Constant Summary collapse
- RANGE_QUERY_MAP =
{ eq: :range_value, gte: :range_gte, gt: :range_greater_than, lte: :range_lte, lt: :range_less_than, # begins_with: :range_begins_with }
Instance Method Summary collapse
- #all ⇒ Object
- #delete ⇒ Object
- #each ⇒ Object
- #each_with_index ⇒ Object
-
#initialize(model) ⇒ QueryChain
constructor
A new instance of QueryChain.
- #query(hash_key) ⇒ Object
- #size ⇒ Object
- #where(value, op = :eq) ⇒ Object
Constructor Details
#initialize(model) ⇒ QueryChain
Returns a new instance of QueryChain.
7 8 9 10 11 |
# File 'lib/dynameek/model/query.rb', line 7 def initialize(model) @model = model @hash_key = nil @range = {eq: nil, gte: nil, gt: nil, lte: nil, lt: nil} end |
Instance Method Details
#all ⇒ Object
28 29 30 |
# File 'lib/dynameek/model/query.rb', line 28 def all run end |
#delete ⇒ Object
24 25 26 |
# File 'lib/dynameek/model/query.rb', line 24 def delete each(&:delete) end |
#each ⇒ Object
36 37 38 39 40 |
# File 'lib/dynameek/model/query.rb', line 36 def each all.each do |item| yield(item) end end |
#each_with_index ⇒ Object
42 43 44 45 46 |
# File 'lib/dynameek/model/query.rb', line 42 def each_with_index all.each_with_index do |item, index| yield(item, index) end end |
#query(hash_key) ⇒ Object
13 14 15 16 |
# File 'lib/dynameek/model/query.rb', line 13 def query(hash_key) @hash_key = hash_key self end |
#size ⇒ Object
32 33 34 |
# File 'lib/dynameek/model/query.rb', line 32 def size all.size end |
#where(value, op = :eq) ⇒ Object
18 19 20 21 22 |
# File 'lib/dynameek/model/query.rb', line 18 def where(value, op=:eq) raise Exception.new("Op #{op.to_s} not recognised") if(!@range.keys.include?(op)) @range[op] = value self end |