Module: ReactiveRecord::LookupTables

Included in:
Base
Defined in:
lib/reactive_record/active_record/reactive_record/lookup_tables.rb

Instance Method Summary collapse

Instance Method Details

#class_scopes(model) ⇒ Object



12
13
14
# File 'lib/reactive_record/active_record/reactive_record/lookup_tables.rb', line 12

def class_scopes(model)
  @class_scopes[model.base_class]
end

#clear_waiting_for_save(model) ⇒ Object



24
25
26
# File 'lib/reactive_record/active_record/reactive_record/lookup_tables.rb', line 24

def clear_waiting_for_save(model)
  @waiting_for_save[model] = []
end

#initialize_lookup_tablesObject



3
4
5
6
7
8
9
10
# File 'lib/reactive_record/active_record/reactive_record/lookup_tables.rb', line 3

def initialize_lookup_tables
  @records = Hash.new { |hash, key| hash[key] = [] }
  @records_by_id = `{}`
  @records_by_vector = `{}`
  @records_by_object_id = `{}`
  @class_scopes = Hash.new { |hash, key| hash[key] = {} }
  @waiting_for_save = Hash.new { |hash, key| hash[key] = [] }
end

#lookup_by_id(*args) ⇒ Object

model and id



36
37
38
# File 'lib/reactive_record/active_record/reactive_record/lookup_tables.rb', line 36

def lookup_by_id(*args) # model and id
  `#{@records_by_id}[#{args}]` || nil
end

#lookup_by_object_id(object_id) ⇒ Object



28
29
30
# File 'lib/reactive_record/active_record/reactive_record/lookup_tables.rb', line 28

def lookup_by_object_id(object_id)
  `#{@records_by_object_id}[#{object_id}]`.ar_instance
end

#lookup_by_vector(vector) ⇒ Object



44
45
46
# File 'lib/reactive_record/active_record/reactive_record/lookup_tables.rb', line 44

def lookup_by_vector(vector)
  `#{@records_by_vector}[#{vector}]` || nil
end

#set_id_lookup(record) ⇒ Object



40
41
42
# File 'lib/reactive_record/active_record/reactive_record/lookup_tables.rb', line 40

def set_id_lookup(record)
  `#{@records_by_id}[#{[record.model, record.id]}] = #{record}`
end

#set_object_id_lookup(record) ⇒ Object



32
33
34
# File 'lib/reactive_record/active_record/reactive_record/lookup_tables.rb', line 32

def set_object_id_lookup(record)
  `#{@records_by_object_id}[#{record.object_id}] = #{record}`
end

#set_vector_lookup(record, vector) ⇒ Object



48
49
50
51
52
# File 'lib/reactive_record/active_record/reactive_record/lookup_tables.rb', line 48

def set_vector_lookup(record, vector)
  record.vector = vector
  `delete #{@records_by_vector}[#{record.vector}]`
  `#{@records_by_vector}[#{vector}] = record`
end

#wait_for_save(model, &block) ⇒ Object



20
21
22
# File 'lib/reactive_record/active_record/reactive_record/lookup_tables.rb', line 20

def wait_for_save(model, &block)
  @waiting_for_save[model] << block
end

#waiting_for_save(model) ⇒ Object



16
17
18
# File 'lib/reactive_record/active_record/reactive_record/lookup_tables.rb', line 16

def waiting_for_save(model)
  @waiting_for_save[model]
end