Class: Cure::History::HistoryCache

Inherits:
Object
  • Object
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

#initializeHistoryCache

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

#countObject

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_valuesObject



58
59
60
# File 'lib/cure/strategy/history/history_cache.rb', line 58

def all_values
  database_service.all_translations
end

#init_cacheObject



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

#resetObject



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

Returns:



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_countObject



71
72
73
# File 'lib/cure/strategy/history/history_cache.rb', line 71

def table_count
  database_service.table_count(:translations)
end