public
Created

Extraction Blog Post

  • Download Gist
contact.rb
Ruby
1 2 3 4 5 6 7
class Contact < ActiveRecord::Base
belongs_to :user
 
def name
"#{first_name} #{last_name}"
end
end
contact_spec.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
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
domain.rb
Ruby
1 2 3 4 5 6 7 8 9 10
class Domain < ActiveRecord::Base
# ...lots of code...
def auto_renew?
registry_domain.auto_renew?
rescue => e
logger.error e
false
end
# ... more code ...
end
logic_contact.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12
class Contact < ActiveRecord::Base
include Logic::Contact
belongs_to :user
end
 
module Logic
module Contact
def name
"#{first_name} #{last_name}"
end
end
end
logic_domain_renewable.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.