Module: Archon::PowerOverwhelming::ClassMethods

Defined in:
lib/archon/power_overwhelming.rb

Overview

Archon::PowerOverwhelming::ClassMethods

Some methods applied to model classes and ActiveRecord::Relation objects

Instance Method Summary collapse

Instance Method Details

#create_from(selectish) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/archon/power_overwhelming.rb', line 26

def create_from(selectish)
  transaction do
    timestamp = ActiveRecord::Base.connection.quoted_date(Time.now)
    timestamp = Arel::Nodes::SqlLiteral.new("'#{timestamp}'")

    insert_result = connection.execute Archon.insert_into_select(
      arel_table, selectish.arel
    ).to_sql

    Rails.logger.debug "Inserted #{insert_result.cmd_tuples} records " \
                       "to table '#{arel_table.name}'."
    insert_result
  end
end