mailing_list.rb |
|
---|---|
This object is meant to be used in conjunction with a
|
module Newman
class MailingList |
|
|
To initialize a
|
def initialize(name, store)
self.name = name
self.store = store
end |
|
|
If the provided email address is for a new subscriber, a new record gets created for that subscriber, adding them to the list. Otherwise, this method does not modify the mailing list. Returns true if list was modified, returns false otherwise. |
def subscribe(email)
return false if subscriber?(email)
store[name].create(email)
true
end |
|
|
If the provided email address is for an existing subscriber, the record for that subscriber is destroyed, removing them from the list. Otherwise, this method does not modify the mailing list. Returns true if list was modified, returns false otherwise. |
def unsubscribe(email)
return false unless subscriber?(email)
record = store[name].find { |e| e.contents == email }
store[name].destroy(record.id)
true
end |
|
|
Returns true if a record is found which matches the given email address, returns false otherwise. |
def subscriber?(email)
store[name].any? { |r| r.contents == email }
end |
|
|
Returns an array of email addresses. |
def subscribers
store[name].map { |r| r.contents }
end |
|
|
NOTE: Methods below this point in the file are implementation details, and should not be depended upon. |
private |
|
|
These accessors have been made private to reflect the fact that
|
attr_accessor :name, :store
end
end |