debian-mirror-gitlab/app/models/data_list.rb

32 lines
627 B
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
class DataList
2021-12-11 22:18:48 +05:30
def initialize(batch, data_fields_hash, data_fields_klass)
2021-01-03 14:25:43 +05:30
@batch = batch
2020-06-23 00:09:42 +05:30
@data_fields_hash = data_fields_hash
2021-12-11 22:18:48 +05:30
@data_fields_klass = data_fields_klass
2020-06-23 00:09:42 +05:30
end
def to_array
2021-12-11 22:18:48 +05:30
[data_fields_klass, columns, values]
2020-06-23 00:09:42 +05:30
end
private
2021-12-11 22:18:48 +05:30
attr_reader :batch, :data_fields_hash, :data_fields_klass
2020-06-23 00:09:42 +05:30
def columns
2021-12-11 22:18:48 +05:30
data_fields_hash.keys << data_fields_foreign_key
end
def data_fields_foreign_key
data_fields_klass.reflections['integration'].foreign_key
2020-06-23 00:09:42 +05:30
end
def values
2021-01-03 14:25:43 +05:30
batch.map do |record|
data_fields_hash.values << record['id']
2020-11-24 15:15:51 +05:30
end
2020-06-23 00:09:42 +05:30
end
end