実行されたmiddlewareをロギングしたい
config/initializers 配下に下記のファイルを設置する。 # Trace each middleware module entry/exit. Freely adapted from # https://github.com/DataDog/dd-trace-rb/issues/368 "Trace each middleware in the Rails stack" mo...
config/initializers 配下に下記のファイルを設置する。 # Trace each middleware module entry/exit. Freely adapted from # https://github.com/DataDog/dd-trace-rb/issues/368 "Trace each middleware in the Rails stack" mo...
#!/bin/bash FILE="$1" CMD="$2" LAST=`ls -l "$FILE"` while true; do sleep 1 NEW=`ls -l "$FILE"` if [ "$NEW" != "$LAST" ]; then "$CMD" "$FILE" LAST="$NEW" fi done linux - Shell c...
remote_url を利用する。 attacher = Shrine::Attacher.new(cache: :cache, store: :store) attacher.remote_url = "https://path/to/image.jpg" shrine/attacher.md at master · shrinerb/shrine Remote URL...
目的 sublimeでrspec、rubocopの結果を色付けされた状態(ANSI color sequence) で閲覧したい。 一つのコンソールで行うと、量が膨大だと切れたり、ワード検索時に何度も実行した結果が複数ひかかったり不便なため。 ANSIのテーマをインストール Super + p で、 Package Control を開き、 ANSIescape で検索する。 a...
エラーが発生しないテスト not_to raise_error RSpec.describe "#to_s" do it "does not raise" do expect { Object.new.to_s }.not_to raise_error end end raise_error matcher - Built in matchers - RSpec E...
解決 described_class.perform_later rescue nil RSpec.describe MyJob, type: :job do include ActiveJob::TestHelper context 'when `MyError` is raised' do before do allow_any_instance_of(d...
travel などを使用する Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 travel 1.day do User.create.created_at # => Sun, 10 Nov 2013 15:34:49 EST -05:00 end Time.current # => Sat, 09 Nov ...
let(:hoge_instance) { instance_double(Hoge) } before do allow(Hoge).to receive(:new).and_return(hoge_instance) allow(hoge_instance).to receive(:say).and_return("night!") end
object_class: OpenStruct をオプションに設定する object = JSON.parse(json, object_class: OpenStruct) Converting JSON to an Object in Ruby - Someth Victory - Medium
type logWriter struct { } func (writer logWriter) Write(bytes []byte) (int, error) { return fmt.Print(time.Now().UTC().Format("2006-01-02T15:04:05.999Z") + " [DEBUG] " + string(bytes)) } func...
解決 self.class.send(:define_method, "hoge") で呼び出す class C def initialize(n) self.class.send(:define_method, n) { puts "some method #{n}" } end end 事象 initialize 内で、 define_method をコール...
解決 複数をソート(asc、descが混在)の場合は、 sort を使用する。 User.all.sort { |a,b| [b.created_at, a.id] <=> [a.created_at, b.id] }.last.id == User.order(created_at: :desc).order(id: :asc).last.id note # gender...
ファイル作成 touch の代わりに > を使用する。 $ cd lib && > my_gem.rb Create a Simple Ruby Gem - The Startup - Medium 標準出力に文字を渡す echo の代わりに <<< を使用する。 $ cat <<< 'hi there' ...
解決 fields オプションを使用する。 render json: notifications, fields: [:id, :title] How to filter attributes? · Issue #992 · rails-api/active_model_serializers · GitHub 問題 ActiveModel::MissingAttribute...
解決 collection を使用する。 比較 resources :notifications, only: %i[index] do get "/on_top", to: "notifications#on_top" # notification_under GET /notifications/:notification_id/under(.:format) notific...