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
# this would be in a helper somewhere | |
def stub_find(entity) | |
result = mock_model(entity) | |
entity.stub(:find).with(result.id).and_return(result) | |
result | |
end | |
let(:params) do | |
{:these => 'params'} | |
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
class CarElement | |
def accept(visitor) | |
raise NotImpelementedError.new | |
end | |
end | |
module Visitable | |
def accept(visitor) | |
visitor.visit(self) | |
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
# autoload concerns | |
module YourApp | |
class Application < Rails::Application | |
config.autoload_paths += %W( | |
#{config.root}/app/controllers/concerns | |
#{config.root}/app/models/concerns | |
) | |
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
# Sandi Metz - Less - The Path to Better Design | |
# http://vimeo.com/26330100 | |
# http://less-goruco.heroku.com/ | |
# | |
# Abstractions are more stable than concretions. | |
class Trip | |
attr_reader :bicycles, :customers, :vehicle | |
def prepare(preparers) |
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
# | |
# Controller - Application service layer until a separation has clear value | |
# | |
# | |
class CartController < ApplicationController | |
before_filter :find_variant | |
rescue_from Model::InvalidOperation, with: :domain_error | |
def add_item |
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
gem 'dragonfly', '~>0.9.4' | |
group :production do | |
gem 'fog' # for Amazon S3 | |
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
# http://tech.groups.yahoo.com/group/domaindrivendesign/message/6654 | |
class Target { | |
public void strike(missile) { | |
missile.setCoordinates(self.coordinates); | |
missile.launch(); | |
markDestroyed(); | |
} | |
} |
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
class User < ActiveRecord::Base | |
# Collaboration Rules | |
def can_like?(like) | |
user.plugins.include?(:page_like) | |
end | |
# Business Service | |
def like(page) | |
Like.create!(:page => page, :user => self) | |
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
def revoke(user) | |
proxy_association.owner.tap do |project| | |
# You can't remove the last user with access (someone has to have access to the project!) | |
if project.users.many? | |
if user.pending? && user.projects.one? | |
user.destroy | |
else | |
project.users.delete(user) | |
user.touch | |
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
# SQL Antipatterns: http://pragprog.com/book/bksqla/sql-antipatterns | |
# A relationship between a model and a DAO like ActiveRecord should be HAS-A | |
# (aggregation) instead of (inheritance). Most frameworks that rely on | |
# ActiveRecord assume the IS-A solution. If you model uses DAOs instead of | |
# inheriting from the DAO class, then you can design the model to contain all | |
# data and code for the domain it's supposed to model--even if it takes | |
# multiple database tables to represent it. | |
# BugReport is a domain object encapsulating: | |
# * Bugs |
OlderNewer