Skip to content

Instantly share code, notes, and snippets.

@sinsoku
sinsoku / orthoses
Created January 12, 2024 11:43
Experimental implementation for orthoses-cli
#!/usr/bin/env ruby
# frozen_string_literal: true
# Phase to load libraries
require_relative "../config/application"
require 'orthoses/rails'
require 'orthoses/yard'
# You can choose logger level
Orthoses.logger.level = :warn
@sinsoku
sinsoku / config.yml
Created December 7, 2023 07:29
Example code to skip tests if source trees are the same.
version: 2.1
# this allows you to use CircleCI's dynamic configuration feature
setup: true
parameters:
tree_sha_path:
type: string
default: ".git_tree_sha"
tree_status_path:
@sinsoku
sinsoku / sidekiq_log_formatter.rb
Created November 9, 2023 11:13
Sidekiq log formatter
# frozen_string_literal: true
require 'sidekiq/logger'
module App
module Formatters
class Sidekiq < ::Sidekiq::Logger::Formatters::Pretty
def call(severity, time, _program_name, message)
hash = {
timestamp: time.utc.iso8601(3),
#!/usr/bin/env ruby
# frozen_string_literal: true
# Rails v7.0.5以降におけるcreate_associationメソッドの影響範囲を調べるスクリプト
#
# ## 参考ページ
# * Rails 7.0.5以降におけるcreate_associationメソッドの挙動変更についてまとめ
# https://blog.willnet.in/entry/2023/07/04/113321
# * parser gemでRubyプログラムのバグを探す
# https://nacl-ltd.github.io/2021/07/02/ruby-ast.html
@sinsoku
sinsoku / create_association_test_script.rb
Last active July 10, 2023 09:57
Rails create_association incompatibility
# frozen_string_literal: true
# This is a test script for create_association incompatibility.
#
# usage
# * `RAILS_VERSION=7.0.4 ruby active_record_test.rb`
# * `RAILS_VERSION=7.0.5 ruby active_record_test.rb`
#
# see also
# * https://github.com/rails/rails/issues/48330
class A
@@foo = "foo"
class << self
@@bar = "bar"
end
end
p A.class_variable_get(:@@foo) #=> "foo"
p A.class_variable_get(:@@bar) #=> "bar"
module A; end
module B; end
module C; end
class Foo
include A
include B
include C
end
@sinsoku
sinsoku / as.rb
Last active October 5, 2022 13:10
An instance that switches between two implementations
module As
class Proxy
def initialize(this, mod)
@this = this
@mod = mod
end
def method_missing(name, *args)
raise NoMethodError unless @mod.instance_methods.include?(name)
@mod.instance_method(name).bind_call(@this, *args)
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
@sinsoku
sinsoku / application_controller.rb
Created October 8, 2020 01:50
before/after/around actionsの前後に処理を挟むパッチ
class ApplicationController < ActionController::Base
class << self
[:before, :after, :around].each do |callback|
define_method "#{callback}_action" do |*names, &blk|
options = names.extract_options!
new_blk = -> {
# 本来の処理の前に行う処理を書く。
if blk.is_a?(Proc)
blk.call