module FeatureFlags

Constants

VERSION

Attributes

configuration[RW]

Public Class Methods

check_features(features, check = false) click to toggle source

checking dependant features

# File lib/feature_flags/manage_features.rb, line 11
def self.check_features(features, check = false)
  features.map{|feature| get_feature(feature)}.compact.include? check
end
configure() { |configuration| ... } click to toggle source
# File lib/feature_flags/configuration.rb, line 16
def self.configure
  self.configuration ||= Configuration.new
  yield(configuration) if block_given?
end
create_and_enable(feature_name) click to toggle source
# File lib/feature_flags/manage_features.rb, line 15
def self.create_and_enable(feature_name)
  feature = Feature.new(:name => feature_name, :status => true)
  feature.save ? true : false
end
disable_all() click to toggle source

disables all features in application

# File lib/feature_flags/manage_features.rb, line 46
def self.disable_all
  Feature.update_all(:status => false)
  Feature.last.update_attributes(:status => false)
end
enable(feature_name) click to toggle source
# File lib/feature_flags/manage_features.rb, line 20
def self.enable(feature_name)
  feature = Feature.where(:name => feature_name).last
  throw_error(feature_name) unless feature.present?

  if feature.update_attributes(:status => true)
    return true
  else
    flash[:error] = "#{feature_name} could not be updated"
    return false
  end

end
enable_all() click to toggle source

enables all features in application

# File lib/feature_flags/manage_features.rb, line 52
def self.enable_all
  Feature.update_all(:status => true)
  Feature.last.update_attributes(:status => true)
end
enabled?(feature) click to toggle source
# File lib/feature_flags/manage_features.rb, line 2
def self.enabled?(feature)
  feature.is_a?(Array) ? !check_features(feature) : get_feature(feature)
end
enabled_any?(features = []) click to toggle source
# File lib/feature_flags/manage_features.rb, line 6
def self.enabled_any?(features = [])
  check_features(features, true)
end
get_feature(feature_name) click to toggle source

fetch feature’s status

# File lib/feature_flags/manage_features.rb, line 58
def self.get_feature(feature_name)
  all_features = FeatureFlags::FeatureBase.features
  all_features.has_key?(feature_name) ? all_features[feature_name] : throw_error(feature_name)
end
set_disabled(feature_name) click to toggle source
# File lib/feature_flags/manage_features.rb, line 33
def self.set_disabled(feature_name)
  feature = Feature.where(:name => feature_name).last
  throw_error(feature_name) unless feature.present?

  if feature.update_attributes(:status => false)
    return true
  else
    flash[:error] = "#{feature_name} could not be updated"
    return false
  end
end
throw_error(feature_name) click to toggle source
# File lib/feature_flags/manage_features.rb, line 63
def self.throw_error(feature_name)
  raise "#{feature_name} feature not found."
end
update_feature_hash() click to toggle source
# File lib/feature_flags/manage_features.rb, line 67
def self.update_feature_hash
  Feature.new.update_hash
end
update_pstore_value(updated = true) click to toggle source

storing toggle value inside pstore if in case someone updates from rails console

# File lib/feature_flags/storage.rb, line 4
def self.update_pstore_value(updated = true)
      store = PStore.new('feature_flags')
      store.transaction do
                      store[:updated] = updated
      end
end