Class: MemDB::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/mem_db/query.rb

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Query

Returns a new instance of Query.



5
6
7
8
9
10
# File 'lib/mem_db/query.rb', line 5

def initialize(params)
  @params = params
  @attrs = {}
  @idx_value = {}
  @field_value = {}
end

Instance Method Details

#[](attr) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/mem_db/query.rb', line 16

def [](attr)
  if @attrs.key?(attr)
    @attrs[attr]
  else
    @attrs[attr] ||= prepare_attr(attr)
  end
end

#[]=(param, value) ⇒ Object



24
25
26
# File 'lib/mem_db/query.rb', line 24

def []=(param, value)
  @params[param] = value
end

#delete(param) ⇒ Object



28
29
30
31
# File 'lib/mem_db/query.rb', line 28

def delete(param)
  @params.delete(param)
  @attrs.delete(param)
end

#field_value(field) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/mem_db/query.rb', line 41

def field_value(field)
  if @field_value.key?(field)
    @field_value[field]
  else
    @field_value[field] ||= field.prepare_query(self)
  end
end

#idx_value(idx) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/mem_db/query.rb', line 33

def idx_value(idx)
  if @idx_value.key?(idx)
    @idx_value[idx]
  else
    @idx_value[idx] ||= idx.prepare_query(self)
  end
end

#prepare_attr(attr) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/mem_db/query.rb', line 49

def prepare_attr(attr)
  v = @params[attr]
  if v.is_a?(Array)
    v
  else
    [v]
  end
end

#using(index) ⇒ Object



12
13
14
# File 'lib/mem_db/query.rb', line 12

def using(index)
  index.query(self)
end