This file contains 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
# Instead of ditching ivars, just make them easier to discover: | |
class ApplicationController < ActionController::Base | |
private | |
# Expose an object as an ivar to your views. Explodes if you try to assign nil. | |
# | |
# Use: | |
# |
This file contains 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
# The controller; yeah it's not great but I want to show the tests | |
class ProductsController < ApplicationController | |
def index | |
if params[:min_rating] | |
@products = Product.where("average_rating >= ?", params[:min_rating]) | |
else | |
@products = Product.to_a | |
end | |
end | |
end |
This file contains 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
# app/commands/receive_bonus_command.rb | |
# Commands look like ActiveModel+virtus "ish" objects | |
class ReceiveBonusCommand < Command | |
attribute :income_source_id, String | |
attribute :bonus_amount, Integer | |
attribute :effective_date, Date | |
validates :account_id, presence: true | |
def validate |
This file contains 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
source "https://rubygems.org" | |
gem "whatever" | |
# Load minitest and red-green | |
group :minitest do | |
gem "minitest" | |
gem "minitest-rg" | |
end |
This file contains 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
class InitializerArgumentsPaymentProcessor | |
def initialize(number, expiration_date, amount) | |
@number, @expiration_date, @amount = number, expiration_date, amount | |
end | |
def call | |
if SomeGateway.(number, expiration_date, amount) | |
true | |
else | |
false |
This file contains 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
# This is an example using Eventide's message handling DSL for declaring different | |
# handler methods based on message type | |
class SomeHandler | |
include Messaging::Handle | |
handle SomeMessage do |some_msg| | |
# ... | |
end | |
handle OtherMessage do |other_msg| |