This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
revision_command = "git log -n 1 --pretty=format:'%H'" | |
revision = `#{revision_command}` | |
appsignal_token = <your appsignal push api key> | |
branch_name = <your branch> | |
server_name = <your server name> | |
rails_env = <your environment> | |
user = <deployment user> | |
appsignal_url = "https://push.appsignal.com/1/markers?api_key=#{appsignal_token}&name=#{server_name}&environment=#{rails_env}" | |
bash 'report deployment' do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add an alias to your bash profile with this code as walk | |
# alias walk='ruby <your file path.rb>' | |
# Usage | |
# walk first | |
# walk next | |
# walk prev | |
case ARGV[0] | |
when "next" | |
rev_list = `git rev-list --children --all` | |
refs = rev_list.scan(/[a-z0-9]{40}(?= )/) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definition of the Interactor | |
class AuthenticateUser | |
include Interactor | |
def call | |
if user = User.authenticate(context.email, context.password) | |
context.user = user | |
context.token = user.secret_token | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definition of the Interactor | |
class MyInteractor | |
include Interactor | |
def call | |
puts context.email # => [email protected] | |
puts context.name # => my_name | |
context.new_attribute = 'some_random_value' | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definition of the PORO | |
class MyInteractor | |
attr_reader :context | |
def initialize(email:, name:) | |
@context = {} | |
context[:email] = email | |
context[:name] = name | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module InteractorValidations | |
def self.included(base) | |
base.extend ClassMethods | |
end | |
module ClassMethods | |
def requires(*attributes) | |
before do | |
attributes.each do |attribute| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definition of a BaseInteractor | |
class BaseInteractor | |
include Interactor | |
include ActiveModel::Validations | |
# For any class that inherits this class, a `before` hook is registered, which raises ArgumentError if the reqired parameters are not passed in during invocation. | |
def self.inherited(subclass) | |
subclass.class_eval do | |
def self.requires(*attributes) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Without delegation | |
class MyInteractor | |
include Interactor | |
def call | |
if context.email.match(/^[a-z]+.\@reflektive\.com$/i) | |
puts "Welcome, #{context.name} from Reflektive!" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc 'Run rake tasks with sandboxing' | |
task sandbox: :environment do | |
# Start transaction | |
ActiveRecord::Base.connection.begin_transaction(joinable: false) | |
puts "๐ Sandbox Mode: ON ๐" | |
# Run your task | |
Rake.application.invoke_task(ARGV.delete_at(1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc 'destroys employee update' | |
task :employee_update_remove => :environment do | |
puts "Starting Migration" | |
records = EmployeeUpdate.last(3) | |
records.each do |record| | |
puts "Going to destroy record #{record.id}" | |
record.destroy | |
end | |
puts "Migration Ended" | |
end |
OlderNewer