Class: ActiveAdmin::Annotations::Exporter

Inherits:
Object
  • Object
show all
Defined in:
lib/activeadmin/annotations/exporter.rb

Constant Summary collapse

BATCH_SIZE =
100

Instance Method Summary collapse

Constructor Details

#initialize(reviews:) ⇒ Exporter

Returns a new instance of Exporter.



9
10
11
# File 'lib/activeadmin/annotations/exporter.rb', line 9

def initialize(reviews:)
  @reviews = reviews
end

Instance Method Details

#each_jsonl_rowObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/activeadmin/annotations/exporter.rb', line 21

def each_jsonl_row
  return enum_for(:each_jsonl_row) unless block_given?

  if reviews.is_a?(ActiveRecord::Relation)
    export_relation_in_batches { |row| yield row }
  else
    Array(reviews).each do |review|
      rows_for(review).each { |row| yield row }
    end
  end
end

#to_jsonlObject



13
14
15
16
17
18
19
# File 'lib/activeadmin/annotations/exporter.rb', line 13

def to_jsonl
  lines = []
  each_jsonl_row { |row| lines << JSON.generate(row) }
  return "" if lines.empty?

  "#{lines.join("\n")}\n"
end