Sha256: e697e59bf5e04e32d3820c1721dd29b741243d1868f2dfbf87fcfa25cee8e954
Contents?: true
Size: 1.23 KB
Versions: 2
Compression:
Stored size: 1.23 KB
Contents
module Archon # = PowerOverwhelming # # Packs several powerful convenient methods for ActiveRecord models. You can add them like this: # # == ActiveRecord >= 5.x # ``` # # app/models/application_record.rb # class ApplicationRecord < ActiveRecord::Base # self.abstract_class = true # include Archon::PowerOverwhelming # end # ``` # # == ActiveRecord >= 4.2.x, < 5.x # ``` # # initializers/archon.rb # ActiveRecord::Base.send :include, Archon::PowerOverwhelming # ``` module PowerOverwhelming extend ActiveSupport::Concern # = Archon::PowerOverwhelming::ClassMethods # Some methods applied to model classes and ActiveRecord::Relation objects module ClassMethods 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 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
archon-0.0.5 | lib/archon/power_overwhelming.rb |
archon-0.0.4 | lib/archon/power_overwhelming.rb |