Class: SimpleMaster::Storage::TestTable
- Inherits:
-
Table
- Object
- Table
- SimpleMaster::Storage::TestTable
show all
- Defined in:
- lib/simple_master/storage/test_table.rb
Overview
Ondemand table based on updated id_hash.
Constant Summary
Constants inherited
from Table
SimpleMaster::Storage::Table::METADATA_PREFIX
Instance Attribute Summary
Attributes inherited from Table
#applied_diff, #dataset, #digest, #id_hash, #klass, #loader, #method_cache, #sub_tables
Instance Method Summary
collapse
Methods inherited from Table
#apply_diff, #apply_diff_to_id_hash, #diff, #duplicate_for, #freeze_all, #load_records, #run_on_sub_tables, #tap_instance_methods, #update_class_method_cache, #update_grouped_hash, #update_id_hash, #update_sub_tables
Constructor Details
#initialize(_klass, _dataset, _loader) ⇒ TestTable
Returns a new instance of TestTable.
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/simple_master/storage/test_table.rb', line 9
def initialize(_klass, _dataset, _loader)
super
@all = []
@id_hash = {}
@grouped_hash = {}
@class_method_cache = {}
@method_cache = Hash.new { |k, v| k[v] = {}.compare_by_identity }.compare_by_identity
@all_need_update = true
@grouped_hash_need_update = true
@class_method_cache_need_update = true
end
|
Instance Method Details
#all ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/simple_master/storage/test_table.rb', line 44
def all
if @all_need_update
@all_need_update = false
@all = id_hash.values
end
@all
end
|
#all=(records) ⇒ Object
39
40
41
42
|
# File 'lib/simple_master/storage/test_table.rb', line 39
def all=(records)
@all_need_update = false
super.tap { update_id_hash }
end
|
#class_method_cache ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/simple_master/storage/test_table.rb', line 60
def class_method_cache
if @class_method_cache_need_update
@class_method_cache_need_update = false
update_class_method_cache
end
@class_method_cache
end
|
#grouped_hash ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/simple_master/storage/test_table.rb', line 52
def grouped_hash
if @grouped_hash_need_update
@grouped_hash_need_update = false
update_grouped_hash
end
@grouped_hash
end
|
#record_updated ⇒ Object
34
35
36
37
|
# File 'lib/simple_master/storage/test_table.rb', line 34
def record_updated
@grouped_hash_need_update = true
@class_method_cache_need_update = true
end
|
#sub_table(sub_klass) ⇒ Object
23
24
25
|
# File 'lib/simple_master/storage/test_table.rb', line 23
def sub_table(sub_klass)
(@sub_tables ||= klass.descendants.reject(&:abstract_class).index_with { |k| self.class.new(k, dataset, loader) })[sub_klass]
end
|
#update(id, record) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/simple_master/storage/test_table.rb', line 27
def update(id, record)
id_hash[id] = record
@all_need_update = true
@grouped_hash_need_update = true
@class_method_cache_need_update = true
end
|