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
| def save(state, params) | |
| if state == :in_progress | |
| return save_in_progress(params) | |
| elsif state == :done | |
| return save_done(params) | |
| elsif state == :on_review | |
| return save_on_review(params, :some_extra_param) | |
| end | |
| end |
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
| def save(state, params) | |
| state_lambda = { | |
| in_progress: -> () { save_in_progress(params) }, | |
| done: -> () { save_done(params) }, | |
| on_review: -> () { save_on_review(params, :some_extra_param) } | |
| } | |
| state_lambda[state].call() | |
| end |
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
| def index | |
| if current_user | |
| @posts = current_user.posts | |
| else | |
| @posts = List.public_posts | |
| end | |
| end |
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 ApplicationController ... | |
| ... | |
| def current_user | |
| return GuestUser.new unless session[:user_id] | |
| User.find(session[:user_id]) | |
| end | |
| ... | |
| end |
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 GuestUser | |
| def posts | |
| List.public_posts # Exactly same method that took the Conditional Controller. | |
| end | |
| end |
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
| def index | |
| @posts = current_user.posts | |
| end |
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
| def index | |
| render :login unless current_user | |
| end |
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 GuestUser | |
| def authenticated? | |
| false | |
| end | |
| end | |
| class User | |
| def authenticated? | |
| true | |
| end |
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
| def index | |
| render :login unless current_user.authenticated? | |
| end |
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
| 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 |