Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Active Record Scratch Pad
source 'https://rubygems.org'
gem 'sqlite3'
gem 'activerecord'
GEM
remote: https://rubygems.org/
specs:
activemodel (4.0.0)
activesupport (= 4.0.0)
builder (~> 3.1.0)
activerecord (4.0.0)
activemodel (= 4.0.0)
activerecord-deprecated_finders (~> 1.0.2)
activesupport (= 4.0.0)
arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.3)
activesupport (4.0.0)
i18n (~> 0.6, >= 0.6.4)
minitest (~> 4.2)
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
arel (4.0.0)
atomic (1.1.14)
builder (3.1.4)
i18n (0.6.5)
minitest (4.7.5)
multi_json (1.8.0)
sqlite3 (1.3.8)
thread_safe (0.1.3)
atomic
tzinfo (0.3.37)
PLATFORMS
ruby
DEPENDENCIES
activerecord
sqlite3
task default: :console
task :console do
require 'irb'
require './scratch'
ARGV.clear
IRB.start
end
require 'logger'
require 'sqlite3'
require 'active_record'
def reload!
load __FILE__
end
def migrate!
ActiveRecord::Schema.define do
create_table :users do |t|
t.string :name
end
end
end
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.logger.formatter = proc { |*_, msg| "#{msg.to_s.strip}\n" }
class User < ActiveRecord::Base
before_save { logger.info :before_save }
after_save { logger.info :after_save }
before_create { logger.info :before_create }
after_create { logger.info :after_create }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment