Class: MemDB::IndexingObject

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

Instance Method Summary collapse

Constructor Details

#initializeIndexingObject

Returns a new instance of IndexingObject.



7
8
9
10
11
# File 'lib/mem_db/indexing_object.rb', line 7

def initialize
  @params = {}
  @attrs = {}
  @idx_value = {}
end

Instance Method Details

#[](attr) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/mem_db/indexing_object.rb', line 21

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

#[]=(param, value) ⇒ Object



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

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

#assign!(params) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/mem_db/indexing_object.rb', line 13

def assign!(params)
  @params = params
  @attrs.clear
  @idx_value.clear

  self
end

#delete(param) ⇒ Object



33
34
35
36
# File 'lib/mem_db/indexing_object.rb', line 33

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

#idx_value(idx) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/mem_db/indexing_object.rb', line 38

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

#prepare_attr(attr) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/mem_db/indexing_object.rb', line 46

def prepare_attr(attr)
  v = @params[attr]

  if v == MemDB::Idx::ANY || v.nil? || v.is_a?(Array)
    v
  else
    [v]
  end
end