Sha256: accbd91b0e4cfa92cb5efe40f87ae76932b7be444e0d2dd6a6586c9e38c2abbc
Contents?: true
Size: 905 Bytes
Versions: 1
Compression:
Stored size: 905 Bytes
Contents
class Array 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 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 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 end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
arql-0.1.11 | lib/arql/ext/array.rb |