Skip to content

Instantly share code, notes, and snippets.

⌨️
Pocke is typing...

Masataka Pocke Kuwabara pocke

⌨️
Pocke is typing...
View GitHub Profile
View bitjourney-querly.yaml
rules:
- id: sample.delete_all
pattern:
- delete_all
- update_all
message: |
これらはvalidationやcallbackをスキップするので危険かもしれません。
justification:
- どうしても高速に update/destroy したい場合
View active_record.rbs
module ActiveRecord
def self.eager_load!: () -> untyped
def self.gem_version: () -> untyped
def self.version: () -> untyped
end
class ActiveRecord::ActiveRecordError < StandardError
end
View ext.rbs
# Devise
extension ApplicationController (Devise)
def current_user: () -> User
end
class DeviseController < ApplicationController
end
class Devise::SessionsController < DeviseController
View kibela-public-api-tester.rb
require 'net/http'
require 'json'
TEAM = ENV['TEAM'] or raise 'TEAM env is required'
TOKEN = ENV['KIBELA_ACCESS_TOKEN'] or raise 'KIBELA_ACCESS_TOKEN env is required'
def req(query)
http = Net::HTTP.new("#{TEAM}.kibe.la", 443)
http.use_ssl = true
header = {
View Rails.env.md

Rails.envを減らしたい

TL;DR

  • if Rails.env.production?をやめて、if ENV['ENABLE_HOGEHOGE_FEATURE']のように書いていこう

Kibelaの現状

Rails.envがたくさん生えています。

@pocke
pocke / rurema-converter2.rb
Created Mar 1, 2020
For removing unnecessary indents
View rurema-converter2.rb
require 'ast'
require 'strscan'
class RuremaParser
def initialize(text, path: nil)
@text = text
@path = path
@index = 0
end
@pocke
pocke / steep.rake
Created Feb 23, 2020
Steepで解析できる型定義ファイルを生成する 2020-02-23版
View steep.rake
namespace :steep do
task gen: %i[base copy ar2rbs path_helper]
task :base do
require 'ruby/signature'
sig_base_path = Rails.root.join('sig/base.rbs')
files = Dir.glob(['app/**/*.rb', 'lib/**/*.rb']).sort
sh 'bundle', 'exec', 'rbs', 'prototype', 'rb', *files, :out => sig_base_path.to_s
View literal-type.diff
diff --git a/tmp/before.rbs b/tmp/after.rbs
index b67bb830f..49b9c3bdf 100644
--- a/tmp/before.rbs
+++ b/tmp/after.rbs
@@ -271,7 +271,7 @@ class RuboCop::AST::CaseNode < Node
# Returns the keyword of the `case` statement as a string.
#
# @return [String] the keyword of the `case` statement
- def keyword: () -> untyped
+ def keyword: () -> "case"
View ski.rb
expr_gen = -> (n) { "(?<expr#{n}>[^()]|\\(\\g<expr#{n}>+\\))" }
simple = '(?<simple>(?:[()]|[^ski])*)'
S = /^#{simple}s#{expr_gen.(1)}#{expr_gen.(2)}#{expr_gen.(3)}(?<rest>.*)/
K = /^#{simple}k#{expr_gen.(1)}#{expr_gen.(2)}(?<rest>.*)$/
I = /^#{simple}i(?<rest>.+)/
P = /^#{simple}\((?<content>#{expr_gen.(1)}*)\)(?<rest>.*)/
$s = '\k<simple>(\k<expr1>\k<expr3>)(\k<expr2>\k<expr3>)\k<rest>'
$k = '\k<simple>\k<expr1>\k<rest>'
View ruby3-signature-stdlib-test.patch
diff --git a/lib/ruby/signature/test/hook.rb b/lib/ruby/signature/test/hook.rb
index ef0cc31..4b05887 100644
--- a/lib/ruby/signature/test/hook.rb
+++ b/lib/ruby/signature/test/hook.rb
@@ -19,6 +19,7 @@ module Ruby
INSTANCE_EVAL = BasicObject.instance_method(:instance_eval)
INSTANCE_EXEC = BasicObject.instance_method(:instance_exec)
METHOD = Kernel.instance_method(:method)
+ INSTANCE_METHOD = Module.method(:instance_method).unbind
CLASS = Kernel.instance_method(:class)
You can’t perform that action at this time.