Class: DataCacheService

Inherits:
Object
  • Object
show all
Includes:
DataExportHelper
Defined in:
app/models/concerns/data_cache_service.rb

Instance Method Summary collapse

Methods included from DataExportHelper

#convert_parameters, #field_result, #footer_result, #header_result

Constructor Details

#initialize(table_list) ⇒ DataCacheService

Returns a new instance of DataCacheService.



4
5
6
7
8
9
# File 'app/models/concerns/data_cache_service.rb', line 4

def initialize(table_list)
  @table_list = table_list
  @data_list = @table_list.data_list
  @config_table = table_list.data_list.config_table
  convert_parameters(@table_list.parameters)
end

Instance Method Details

#cache_tableObject



11
12
13
14
15
16
17
# File 'app/models/concerns/data_cache_service.rb', line 11

def cache_table
  @table_list.headers = header_result
  cache_table_items
  @table_list.footers = footer_result
  @table_list.done = true
  @table_list.save
end

#cache_table_itemsObject



19
20
21
22
23
24
# File 'app/models/concerns/data_cache_service.rb', line 19

def cache_table_items
  @config_table.collection.call(@params).each_with_index do |object, index|
    row = field_result(object, index)
    @table_list.table_items.create(fields: row)
  end
end