Class: Cure::History::HistoryCache
- Inherits:
-
Object
- Object
- Cure::History::HistoryCache
show all
- Includes:
- Database, Singleton
- Defined in:
- lib/cure/strategy/history/history_cache.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Database
#database_service, #init_database
Constructor Details
Returns a new instance of HistoryCache.
39
40
41
42
43
|
# File 'lib/cure/strategy/history/history_cache.rb', line 39
def initialize
@count = 0
init_cache
end
|
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
37
38
39
|
# File 'lib/cure/strategy/history/history_cache.rb', line 37
def count
@count
end
|
Instance Method Details
#all_values ⇒ Object
58
59
60
|
# File 'lib/cure/strategy/history/history_cache.rb', line 58
def all_values
database_service.all_translations
end
|
#init_cache ⇒ Object
75
76
77
78
79
|
# File 'lib/cure/strategy/history/history_cache.rb', line 75
def init_cache
return if database_service.table_exist?(:translations)
database_service.create_table(:translations, %w[source_value value named_range column])
end
|
#insert(source_value, value, named_range: nil, column: nil) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/cure/strategy/history/history_cache.rb', line 50
def insert(source_value, value, named_range: nil, column: nil)
@count += 1
database_service.insert_row(:translations, [
@count, source_value, value, named_range, column
])
end
|
#reset ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/cure/strategy/history/history_cache.rb', line 62
def reset
@count = 0
if database_service.table_exist?(:translations)
database_service.truncate_table(:translations)
else
init_cache
end
end
|
#search(source_value, _named_range: nil, _column: nil) ⇒ String
46
47
48
|
# File 'lib/cure/strategy/history/history_cache.rb', line 46
def search(source_value, _named_range: nil, _column: nil)
database_service.find_translation(source_value)
end
|
#table_count ⇒ Object
71
72
73
|
# File 'lib/cure/strategy/history/history_cache.rb', line 71
def table_count
database_service.table_count(:translations)
end
|