Module: FeatureSwitch

Defined in:
lib/feature_switch.rb

Overview

Author:

  • Dan Williams

Instance Method Summary collapse

Instance Method Details

#disable(feature) ⇒ Object

Disable a feature

Parameters:

  • The (Symbol)

    feature to disable



20
21
22
# File 'lib/feature_switch.rb', line 20

def disable(feature)
  (@_disabled_features ||= []) << feature
end

#disabled?(feature) ⇒ Boolean

Returns if the feature has been disabled

Parameters:

  • The (Symbol)

    feature to check the status of

Returns:

  • (Boolean)


34
35
36
# File 'lib/feature_switch.rb', line 34

def disabled?(feature)
  disabled_features.include?(feature)
end

#enable(feature) ⇒ Object

Enable a feature

Parameters:

  • The (Symbol)

    feature to enable



13
14
15
# File 'lib/feature_switch.rb', line 13

def enable(feature)
  (@_enabled_features ||= []) << feature
end

#enabled?(feature) ⇒ Boolean

Returns if the feature has been enabled

Parameters:

  • The (Symbol)

    feature to check the status of

Returns:

  • (Boolean)


27
28
29
# File 'lib/feature_switch.rb', line 27

def enabled?(feature)
  enabled_features.include?(feature)
end

#feature(feature) ⇒ Object

Yields a block if the feature is enabled

Parameters:

  • The (Symbol)

    feature to use as a guard-check



6
7
8
# File 'lib/feature_switch.rb', line 6

def feature(feature)    
  yield if enabled_features.include?(feature) || (enabled_features(current_user.features).include?(feature) if respond_to?(:current_user) && current_user.respond_to?(:features))
end