Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac11319
commit 6072b8a
Showing
36 changed files
with
879 additions
and
1,050 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--color | ||
--format=documentation | ||
#--format=documentation | ||
--backtrace | ||
--profile | ||
--order random |
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
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
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
module MailyHerald | ||
class List < ActiveRecord::Base | ||
attr_accessible :token_action, :context_name | ||
|
||
has_many :subscriptions, :class_name => "MailyHerald::Subscription" | ||
|
||
after_initialize do | ||
if self.new_record? | ||
self.token_action = :unsubscribe | ||
end | ||
end | ||
|
||
def context | ||
@context ||= MailyHerald.context self.context_name | ||
end | ||
|
||
def subscribe! entity | ||
s = subscription_for(entity) | ||
s ? s.activate! : s = create_subscription_for(entity, true) | ||
s | ||
end | ||
|
||
def unsubscribe! entity | ||
s = subscription_for(entity) | ||
s ? s.deactivate! : s = create_subscription_for(entity, false) | ||
s | ||
end | ||
|
||
def subscribed? entity | ||
!!subscription_for(entity).try(:active?) | ||
end | ||
|
||
def subscription_for entity | ||
self.subscriptions.for_entity(entity).first | ||
end | ||
|
||
def token_action | ||
read_attribute(:token_action).to_sym | ||
end | ||
|
||
def token_custom_action &block | ||
if block_given? | ||
MailyHerald.token_custom_action :mailing, self.id, &block | ||
else | ||
MailyHerald.token_custom_action :mailing, self.id | ||
end | ||
end | ||
|
||
private | ||
|
||
def create_subscription_for entity, active = false | ||
s = self.subscriptions.build.tap do |s| | ||
s.entity = entity | ||
s.active = active | ||
end | ||
s.save! | ||
s | ||
end | ||
|
||
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
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
Oops, something went wrong.