Skip to content

Instantly share code, notes, and snippets.

@jfeaver
jfeaver / active_record_relation_type.rb
Last active Jun 3, 2020
Use Dry gems to build a struct which has an active record relation from a specified model as an attribute
View active_record_relation_type.rb
require 'dry-struct'
require 'active_record'
module Types
include Dry.Types
def self.ArRelation(model_class)
# Note that ActiveRecord_Relation, ActiveRecord_Associations_CollectionProxy, and ActiveRecord_AssociationRelation
# are private constants - they may change some day
Instance(model_class.const_get(:ActiveRecord_Relation)) |
View isbn.ex
defmodule Isbn do
require Record
Record.defrecord(:isbn, raw: "", gs1: "", group: "", publisher: "", title: "", check_digit: "")
end
@jfeaver
jfeaver / deploy.rake
Last active Sep 29, 2015
Heroku Deploy Script
View deploy.rake
class DeployTask
attr_accessor :app_suffix, :heroku_app, :git_branch, :force, :enter_maintenance
def initialize(options = {})
@app_suffix = options[:app_suffix]
@heroku_app = options.fetch(:heroku_app, default_app_name)
@git_branch = options.fetch(:git_branch, current_branch)
@force = options.fetch(:force, false)
@enter_maintenance = options.fetch(:enter_maintenance, true)
end
View deploy.rake
#Deploy and rollback on Heroku in staging and production
class RakeHerokuDeployer
def initialize app_env
@app = ENV["#{app_env.to_s.upcase}_APP"]
end
def run_migrations
push; turn_app_off; migrate; restart; turn_app_on; tag;
end