-
-
Save osyo-manga/d1434e8c694dbb510dc03b4a2b1abb1e to your computer and use it in GitHub Desktop.
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" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
# ここに依存する gem を記述する | |
gem "activerecord", "6.0.3" | |
# gem "rails", github: "rails/rails" | |
gem "sqlite3" | |
gem "ruby_jard" |
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
# frozen_string_literal: true | |
require "stringio" | |
# require "ruby_jard" | |
temp_io = $stdout | |
$stdout = StringIO.new | |
require "active_record" | |
# require "minitest/autorun" | |
require "logger" | |
# メモリ上に DB を構築する | |
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") | |
# ActiveRecord::Base.logger = Logger.new(STDOUT) | |
# DB の schema を定義する | |
ActiveRecord::Schema.define do | |
create_table :users, force: true do |t| | |
t.boolean :active | |
end | |
end | |
$stdout = temp_io | |
class User < ActiveRecord::Base | |
$debug = true | |
scope :actives, -> { where(active: true) } | |
$debug = false | |
scope(:owners, -> { where(owner: true) }) do | |
def order_by_created_at(order_ = "asc") | |
order(created_at: order_) | |
end | |
end | |
end | |
p User.method :actives | |
# puts User.owners.order_by_created_at.to_sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment