Created
March 12, 2013 06:46
-
-
Save mech/5140825 to your computer and use it in GitHub Desktop.
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
# 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 |
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 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 |
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 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