View 00_Rails-binstubs-vs-Bundler-binstubs.md

Rails' binstubs vs. Bundler binstubs

There's an incompatibility in the Rails vs Bundler-generated bin/bundle binstub. Futher, other Bundler-generated binstubs (e.g., bin/rspec) generated by older versions of Bundler don't play well with those generated by Bundler v1.16.

The Binstubs and versions.

bin/rspec

The older rspec-old.rb was generated by an older version of Bundler.

View 00_Heroku-Release-Phase-Review-Apps-Rails_README.md

Heroku Release Phase + Review Apps + Rails

This is a simplified, but fairly thorough, set of scripts and configuration to enable Heroku Release Phase for Rails apps. Further, this particular set up plays nicely with Heroku Review Apps in that the release phase script will:

  1. Fail, loudly, if the DB does not yet exist.
  2. Load the DB schema if the current schema version (as determined by bin/rails db:version) is 0.
  3. Run DB migrations otherwise.

For a "normal" app that usually means it will run the DB migrations.

View i18n_helpers.rb
# frozen_string_literal: true
module I18nHelpers
def self.included(_mod)
locale_dir = Pathname.new(__dir__) + '../../config/locales/'
[:en].each do |locale|
locale_file = locale_dir + "#{locale}.yml"
I18n.backend.store_translations(locale, YAML.load_file(locale_file.open)[String(locale)])
end
end
View heroku_deploy.sh
#!/usr/bin/env bash
#
# Usage: bin/heroku_deploy <heroku-app-name> [git-treeish : default=HEAD]
. ./shell_colors
set -euo pipefail
app_name=$1
app_remote=$app_name
View _view_model.rb
# app/model/view/view_model.rb
# A base class for other view models (a.k.a., presenters)
module View
class ViewModel < SimpleDelegator
BUILD_DEFAULT_CONTEXT = -> { View::DefaultViewContext.new }
def initialize(model, view_context: BUILD_DEFAULT_CONTEXT.call)
@view_context = view_context
super(model)
end
View pre-commit.sh
#!/usr/bin/env bash
set -eu
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NO_COLOR='\033[0m'
CLEAR_LINE='\r\033[K'
View rerun-sidekiq.sh
rerun --background --dir app,config,db,lib --pattern '{**/*.rb}' -- $(grep 'worker: ' Procfile | sed 's/worker: //')
View has_one_of_a_has_many.rb
class Organization < ActiveRecord::Base
has_many :people, dependent: :destroy, inverse_of: :organization
has_many :locations, dependent: :destroy
has_many :activity_items, -> { order(last_activity_at: :desc) }, dependent: :destroy
has_one :last_activity, -> { order(last_activity_at: :desc) }, class_name: 'ActivityItem'
end
class ActivityItem < ActiveRecord::Base
belongs_to :organization
belongs_to :user
View bin-import.sh
#!/usr/bin/env bash
set -euo pipefail
. ./bin/colors
heroku_app=your-app
capture=0
migrate=0
restore=0
View same-videos.sh
# Back story: I uploaded a dozen or so HD (1080p) movies to my Synology while across the country.
# Now I want to make sure the uploads all came through without corruption.
for video in *.mp4; do
cmp "./${video}" "/Volumes/video/Movies/${video}"
done