module SimpleSwitch::ManagerSharedMethods

Public Instance Methods

off?(feature, env=Rails.env) click to toggle source
# File lib/simple_switch/manager_shared_methods.rb, line 18
def off?(feature, env=Rails.env)
  !on?(feature, env)
end
on?(feature, env=Rails.env) click to toggle source
# File lib/simple_switch/manager_shared_methods.rb, line 4
def on?(feature, env=Rails.env)
  reload_config! if env == 'development'

  begin
    if valid_feature_name_for_env?(feature, env)
      config = states(feature)[env]

      config.is_a?(Array) ? config[0] : config
    end
  rescue
    true
  end
end
turn_off(feature, env) click to toggle source
# File lib/simple_switch/manager_shared_methods.rb, line 26
def turn_off(feature, env)
  update(feature, env, false)
end
turn_on(feature, env) click to toggle source
# File lib/simple_switch/manager_shared_methods.rb, line 22
def turn_on(feature, env)
  update(feature, env, true)
end

Private Instance Methods

reload_config!() click to toggle source
# File lib/simple_switch/manager_shared_methods.rb, line 31
def reload_config!
  @feature_config = load_config
end
states(feature) click to toggle source
# File lib/simple_switch/manager_shared_methods.rb, line 35
def states(feature)
  feature_config[feature][:states]
end
valid_feature_name?(feature) click to toggle source
# File lib/simple_switch/manager_shared_methods.rb, line 39
def valid_feature_name?(feature)
  reload_config! unless feature_config.has_key?(feature)

  feature_config.has_key?(feature)
end
valid_feature_name_for_env?(feature, env) click to toggle source
# File lib/simple_switch/manager_shared_methods.rb, line 45
def valid_feature_name_for_env?(feature, env)
  valid_feature_name?(feature)

  states(feature).has_key?(env)
end