Skip to content

Instantly share code, notes, and snippets.

@mech
Created March 12, 2013 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mech/5140825 to your computer and use it in GitHub Desktop.
Save mech/5140825 to your computer and use it in GitHub Desktop.
# But why not just this?
# More straightfoward and faster to write...
class Job < ActiveRecord::Base
def publish
update_attribute(:status, "published")
JobActivityFeed.create("#{title} has been published", id)
JobMailer.info_consultant(id, "consultant@cp.com").deliver
end
end
class JobRepository < ActiveRecord::Base
belongs_to :owner
# Always hide ActiveRecord's native API behind a method
def update_status(status)
update_attribute(:status, status)
end
end
class Position
PUBLISHED = "published"
CLOSED = "closed"
def initialize(repository)
@repository = repository
end
def initialize(id)
@repository = JobRepository.find(id)
end
def publish
update_status_to_repository(PUBLISHED)
end
def close
update_status_to_repository(CLOSED)
end
private
def update_status_to_repository(status)
repository.update_status(status)
post_to_activity_feed
info_consultant
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment