Create a gist now

Instantly share code, notes, and snippets.

Extraction Blog Post
class Contact < ActiveRecord::Base
belongs_to :user
def name
"#{first_name} #{last_name}"
end
end
require 'lib/logic/contact'
class FakeContact
include Logic::Contact
attr_accessor :first_name, :last_name
end
describe Logic::Contact do
subject do
contact = FakeContact.new
contact.first_name = "Anthony"
contact.last_name = "Eden"
contact
end
it "has a name" do
subject.name.should eq("#{subject.first_name} #{subject.last_name}")
end
end
class Domain < ActiveRecord::Base
# ...lots of code...
def auto_renew?
registry_domain.auto_renew?
rescue => e
logger.error e
false
end
# ... more code ...
end
class Contact < ActiveRecord::Base
include Logic::Contact
belongs_to :user
end
module Logic
module Contact
def name
"#{first_name} #{last_name}"
end
end
end
class Domain < ActiveRecord::Base
include Logic::Domain::Renewable
end
module Logic
module Domain
module Renewable
def auto_renew?
registry_domain.auto_renew?
rescue => e
logger.error e
false
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment