Skip to content

Instantly share code, notes, and snippets.

@ch1ago
Last active October 1, 2015 01:06
Show Gist options
  • Save ch1ago/29de373663a9e3cdc85a to your computer and use it in GitHub Desktop.
Save ch1ago/29de373663a9e3cdc85a to your computer and use it in GitHub Desktop.
class ApplicationController
def current_user_decorator
@cud ||= current_user ? CurrentUserDecorator.new(current_user) : NullCurrentUserDecorator.new
end
# or this
def current_user
if signed_in?
super
else
@cud ||= NullCurrentUser.new
end
end
end
class CurrentUserDecorator
def initialize(current_user)
@current_user = current_user
end
end
class NullCurrentUserDecorator
def initialize
# nothing here
end
def movies
[]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment