Module: FeatureSwitch

Defined in:
lib/feature_switch.rb

Overview

Author:

  • Dan Williams

Constant Summary collapse

@@enabled_features =
[]
@@disabled_features =
[]

Instance Method Summary collapse

Instance Method Details

#disable(feature) ⇒ Object

Disable a feature

Parameters:

  • The (Symbol)

    feature to disable



23
24
25
# File 'lib/feature_switch.rb', line 23

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)


37
38
39
# File 'lib/feature_switch.rb', line 37

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

#enable(feature) ⇒ Object

Enable a feature

Parameters:

  • The (Symbol)

    feature to enable



16
17
18
# File 'lib/feature_switch.rb', line 16

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)


30
31
32
# File 'lib/feature_switch.rb', line 30

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



9
10
11
# File 'lib/feature_switch.rb', line 9

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