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
IosStrategy = Struct.new(:app_token) do | |
def notify(context) | |
context.receivers.each { |receiver| push(user_token: receiver.token, title: context.subject_msg, content: context.content_msg) } | |
end | |
private | |
def push(user_token:, title:, content:) |
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
EmailStrategy = Struct.new(:from) do | |
def notify(context) | |
context.receivers.each { |receiver| push(to: receiver.email, subject: context.subject_msg, content: context.content_msg) } | |
end | |
private | |
def push(to:, subject:, content:) |
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
Notification = Struct.new(:notifier_strategy, :receivers, :subject_msg, :content_msg) do | |
def notify | |
# The Notifier Strategy will be Email or iOS. | |
notifier_strategy.notify(self) | |
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
def index | |
render :login unless current_user.authenticated? | |
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 GuestUser | |
def authenticated? | |
false | |
end | |
end | |
class User | |
def authenticated? | |
true | |
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
def index | |
render :login unless current_user | |
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
def index | |
@posts = current_user.posts | |
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 GuestUser | |
def posts | |
List.public_posts # Exactly same method that took the Conditional Controller. | |
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 ApplicationController ... | |
... | |
def current_user | |
return GuestUser.new unless session[:user_id] | |
User.find(session[:user_id]) | |
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
def index | |
if current_user | |
@posts = current_user.posts | |
else | |
@posts = List.public_posts | |
end | |
end |