Created
December 18, 2012 15:55
-
-
Save joecannatti/4329206 to your computer and use it in GitHub Desktop.
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 Task | |
attr_accessor :name | |
attr_accessor :assigned_to_user_id | |
attr_accessor :due_on | |
def save | |
Storer.store(self) | |
end | |
end | |
class EmailInfo | |
def initialize(obj) | |
@obj = obj | |
@type = obj.class | |
end | |
def user_id | |
@obj.send(id_fields[@type]) | |
end | |
def title | |
mapped_data[@type][:title] | |
end | |
def body | |
mapped_data[@type][:body] | |
end | |
def id_fields | |
{ | |
Task => :assigned_to_user_id, | |
SomeThingElseMaybeUser => :id, | |
MaybeEvent => :user_id | |
} | |
end | |
def email_data | |
{ | |
Task => { :title => "New Task", :body => "You have been assigned a new task" }, | |
SomeThingElseMaybeUser => { :title => "Thanks for registering", :body => "Have fun" }, | |
MaybeEvent => { :title => "New Event", :body => "Enjoy!" } | |
} | |
end | |
end | |
class Storer | |
def self.store(obj) | |
obj.save! | |
email_info = TaskEmailInfo.new(obj) | |
email.send(email_info.user_id, email_info.title, email_info.body) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Suppose you wanted to save a task, but didn't want it to send an email? How would you suppress the email?