Kaigi on Rails 2026(2026-10-16)諸橋恭介 @moro
公開スライドの各ページに対応するトークスクリプトです。見出しのページ番号はスライドのページ番号に対応しています。
元のスライドはこちら。 https://speakerdeck.com/moro/event-is-what-happens
Kaigi on Rails 2026(2026-10-16)諸橋恭介 @moro
公開スライドの各ページに対応するトークスクリプトです。見出しのページ番号はスライドのページ番号に対応しています。
元のスライドはこちら。 https://speakerdeck.com/moro/event-is-what-happens
| require 'csv' | |
| require 'sequel' | |
| def sql_to_csv(sql, db: Sequel.connect(ENV['DATABASE_URL'])) | |
| rel = db[sql] | |
| CSV.generate('', force_quotes: ENV['NO_QUOTE'].nil?) do |csv| | |
| csv << rel.columns | |
| rel.each {|row| csv << row.values } | |
| end |
| module Constructor | |
| def constructor(*names) | |
| define_method(:initialize) do |*args| | |
| names.zip(args).each do |name, value| | |
| instance_variable_set("@#{name}", value) | |
| end | |
| end | |
| end | |
| end |
| class Foo < ActiveRecord::Base | |
| after_save :do_something, unless: :other_situation? | |
| class << self | |
| def other_situation | |
| begin | |
| Thread.current[:other_situation] = true | |
| yield | |
| ensure | |
| Thread.current[:other_situation] = nil |
| module Doublet | |
| def doublet(name, &block) | |
| let(name) { double.tap(&block) } | |
| end | |
| def doublet!(name, &block) | |
| let!(name) { double.tap(&block) } | |
| end | |
| end |
| module CoffeeConstructor | |
| def constructor(*ivars) | |
| define_method :initialize do |*args| | |
| raise(ArgumentError) unless ivars.size == args.size | |
| ivars.zip(args).each do |ivar, val| | |
| instance_variable_set(ivar, val) | |
| end | |
| end | |
| end |
| module Censorable | |
| extend ActiveSupport::Concern | |
| class MonitorRequestFailed < RuntimeError | |
| ... | |
| end | |
| included do | |
| has_many :monitor_requests, as: :entity, dependent: :destroy |
| module Retriable | |
| class RepeatedError < RuntimeError | |
| def initialize(max, *args) | |
| @errors = [] | |
| @max = max | |
| super(*args) | |
| end | |
| def <<(e) | |
| @errors << e |
| ['foo', 'bar'].inject(Paste.scoped) {|rel, tag| | |
| rel.where(id: Tagging.joins(:tag).select(:paste_id).where('tags.name = ?', tag)) | |
| }.to_sql | |
| # => | |
| # SELECT "pastes".* | |
| # FROM "pastes" | |
| # WHERE "pastes"."id" IN (SELECT paste_id FROM "taggings" INNER JOIN "tags" ON "tags"."id" = "taggings"."tag_id" WHERE (tags.name = 'foo')) | |
| # AND "pastes"."id" IN (SELECT paste_id FROM "taggings" INNER JOIN "tags" ON "tags"."id" = "taggings"."tag_id" WHERE (tags.name = 'bar')) | |
| # |
| class A | |
| def foo(num) | |
| %w[one two three][num - 1] | |
| end | |
| end | |
| describe A do | |
| describe "#foo" do | |
| RSpec::Matchers.define :do_foo do |args| | |
| match do |instance| |