class FeatureFlagger::Configuration

Attributes

cache_store[RW]
notifier_callback[RW]
storage[RW]
yaml_filepath[RW]

Public Class Methods

new() click to toggle source
# File lib/feature_flagger/configuration.rb, line 5
def initialize
  @storage       ||= Storage::Redis.default_client
  @yaml_filepath ||= default_yaml_filepath
  @notifier_callback = nil
  @cache_store = nil
end

Public Instance Methods

cache_store=(cache_store) click to toggle source
# File lib/feature_flagger/configuration.rb, line 12
def cache_store=(cache_store)
  raise ArgumentError, "Cache is only support when used with ActiveSupport" unless defined?(ActiveSupport)

  cache_store = :null_store if cache_store.nil?
  @cache_store = ActiveSupport::Cache.lookup_store(*cache_store)
end
info() click to toggle source
# File lib/feature_flagger/configuration.rb, line 19
def info
  @info ||= YAML.load_file(yaml_filepath) if yaml_filepath
end
mapped_feature_keys(resource_name = nil) click to toggle source
# File lib/feature_flagger/configuration.rb, line 23
def mapped_feature_keys(resource_name = nil)
  info_filtered = resource_name ? info[resource_name] : info
  [].tap do |keys|
    make_keys_recursively(info_filtered).each { |key| keys.push(join_key(resource_name, key)) }
  end
end

Private Instance Methods

default_yaml_filepath() click to toggle source
# File lib/feature_flagger/configuration.rb, line 32
def default_yaml_filepath
  "#{Rails.root}/config/rollout.yml" if defined?(Rails)
end
join_key(resource_name, key) click to toggle source
# File lib/feature_flagger/configuration.rb, line 50
def join_key(resource_name, key)
  key.unshift resource_name if resource_name
  key.join(":")
end
make_keys_recursively(hash, keys = [], composed_key = []) click to toggle source
# File lib/feature_flagger/configuration.rb, line 36
def make_keys_recursively(hash, keys = [], composed_key = [])
  unless hash.values[0].is_a?(Hash)
    keys.push(composed_key)
    return
  end

  hash.each do |key, value|
    composed_key_cloned = composed_key.clone
    composed_key_cloned.push(key.to_sym)
    make_keys_recursively(value, keys, composed_key_cloned)
  end
  keys
end