Class: Array

Inherits:
Object show all
Defined in:
lib/arql/ext/array.rb

Instance Method Summary collapse

Instance Method Details

#to_insert_sql(batch_size = 500) ⇒ Object



2
3
4
5
6
7
# File 'lib/arql/ext/array.rb', line 2

def to_insert_sql(batch_size=500)
  raise 'All element should be an ActiveRecord instance object' unless all? { |e| e.is_a?(ActiveRecord::Base) }
  group_by(&:class).map do |(klass, records)|
    klass.to_insert_sql(records, batch_size)
  end.join("\n")
end

#to_upsert_sql(batch_size = 500) ⇒ Object



9
10
11
12
13
14
# File 'lib/arql/ext/array.rb', line 9

def to_upsert_sql(batch_size=500)
  raise 'All element should be an ActiveRecord instance object' unless all? { |e| e.is_a?(ActiveRecord::Base) }
  group_by(&:class).map do |(klass, records)|
    klass.to_upsert_sql(records, batch_size)
  end.join("\n")
end

#vObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/arql/ext/array.rb', line 16

def v
  raise 'Empty array' unless present?
  raise 'All elements must be instances of the same ActiveRecord model class' unless map(&:class).uniq.size == 1 && first.is_a?(ActiveRecord::Base)
  t = []
  t << first.attribute_names
  t << nil
  each do |e|
    t << e.attributes.values_at(*first.attribute_names)
  end
  t
end