Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class PremiumFeature
attr_accessor :controller
def initialize(controller)
@controller = controller
end
def enabled?
controller.current_user.premium?
end
end
class WidgetController
# Further down the controller class
def add_feature(name)
feature = "#{name}_feature".camelize.constantize.new(self)
if feature.respond_to?(:enabled?)
features[name] = feature
end
rescue
fail 'Feature does not exist'
end
def feature_enabled?(name)
features.fetch(name, NeverEnabledFeature.new).enabled?
end
helper_method :feature_enabled?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.