Skip to content

Instantly share code, notes, and snippets.

View yhirano55's full-sized avatar
🐕
Enjoy

yhirano55 yhirano55

🐕
Enjoy
View GitHub Profile
@yhirano55
yhirano55 / seed_fu.rake
Last active January 16, 2020 19:30
Run in CI: RAILS_ENV=test bundle exec rails db:seed_fu:lint
# lib/tasks/seed_fu/lint.rake
namespace :db do
namespace :seed_fu do
desc 'Verify that all fixtures are valid'
task lint: :environment do
if Rails.env.test?
conn = ActiveRecord::Base.connection
%w[development test production].each do |env|
conn.transaction do
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails"

以下のログは下記コードの実行後に生成されたマークダウンファイルとなります。

env = Rack::MockRequest.env_for('http://localhost:3000/books')
TraceLocation.trace(ignore: /rbenv|activesupport/) { status, headers, body = Rails.application.call(env) }

Generated by trace_location at 2019-06-06 10:43:54 +0900

Generated by trace_location at 2019-06-06 08:18:16 +0900

activerecord-5.2.2.1/lib/active_record/connection_handling.rb:89
ActiveRecord::ConnectionHandling#connection
def connection
  retrieve_connection

Generated by trace_location at 2019-06-05 10:56:45 +0900

activemodel-5.2.3/lib/active_model/secure_password.rb:55
ActiveModel::SecurePassword::ClassMethods#has_secure_password
def has_secure_password(options = {})
  # Load bcrypt gem only when has_secure_password is used.

Generated by trace_location at 2019-06-05 10:39:18 +0900

activerecord-5.2.3/lib/active_record/connection_handling.rb:49
ActiveRecord::ConnectionHandling#establish_connection
def establish_connection(config = nil)
 raise "Anonymous class is not allowed." unless name

Generated by trace_location at 2019-06-04 23:08:49 +0900

activerecord-5.2.3/lib/active_record/validations.rb:65
ActiveRecord::Validations#valid?
def valid?(context = nil)
  context ||= default_validation_context
 output = super(context)

元コード

目的: どのようにバリデーションが定義されているかを知る

class Story < ApplicationRecord
  TraceLocation.trace(format: :markdown) do
    validates :title, allow_blank: true, length: { in: 1..65_535 }
  end
end
@yhirano55
yhirano55 / trello.rb
Created July 30, 2018 22:23
trello の json からカード名を抜き出すスクリプト
content = JSON.parse(File.read("./trello.json"))
content["actions"].select { |a| a["type"] == "createCard" && a.dig("data", "list", "name") == "Keep" }.map { |a| a.dig("data", "card", "name") }.each(&method(:puts))
@yhirano55
yhirano55 / 00.md
Last active September 26, 2023 15:01
katacoda

なぜKubernetesが必要なのか?

https://thinkit.co.jp/article/13289

k8sとは

  • Kubernetesはコンテナ化されたアプリケーションの展開、スケーリング、および管理を自動化するためのコンテナオーケストレーションエンジンです。
  • Dockerに注目が集まり、プロダクションで利用するシーンが増えたため、あと、Microservices化などの流れに伴って、流行している。
  • 以前はDocker Swarmもあったが、デファクトスタンダードはk8sになっている。