Last active
December 24, 2015 14:49
-
-
Save invisiblefunnel/6815374 to your computer and use it in GitHub Desktop.
Simple Active Record Scratch Pad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'sqlite3' | |
gem 'activerecord' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task default: :console | |
task :console do | |
require 'irb' | |
require './scratch' | |
ARGV.clear | |
IRB.start | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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