2020-05-20 14:08:00 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ServiceList
|
2020-09-29 11:10:08 -04:00
|
|
|
def initialize(batch, service_hash, association)
|
|
|
|
@batch = batch
|
2020-05-20 14:08:00 -04:00
|
|
|
@service_hash = service_hash
|
2020-09-15 11:10:08 -04:00
|
|
|
@association = association
|
2020-05-20 14:08:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_array
|
|
|
|
[Service, columns, values]
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-09-29 11:10:08 -04:00
|
|
|
attr_reader :batch, :service_hash, :association
|
2020-05-20 14:08:00 -04:00
|
|
|
|
|
|
|
def columns
|
2020-09-29 11:10:08 -04:00
|
|
|
service_hash.keys << "#{association}_id"
|
2020-05-20 14:08:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def values
|
2020-09-29 11:10:08 -04:00
|
|
|
batch.select(:id).map do |record|
|
|
|
|
service_hash.values << record.id
|
2020-05-20 14:08:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|