class Flipper::Adapters::Moneta

Constants

FEATURES_KEY

Attributes

moneta[R]
name[R]

Public: The name of the adapter.

Public Class Methods

new(moneta) click to toggle source

Public

# File lib/flipper/adapters/moneta.rb, line 14
def initialize(moneta)
  @moneta = moneta
  @name = :moneta
end

Public Instance Methods

add(feature) click to toggle source

Public: Adds a feature to the set of known features.

# File lib/flipper/adapters/moneta.rb, line 25
def add(feature)
  moneta[FEATURES_KEY] = features << feature.key.to_s
  true
end
clear(feature) click to toggle source

Public: Clears all the gate values for a feature.

# File lib/flipper/adapters/moneta.rb, line 39
def clear(feature)
  moneta[key(feature.key)] = default_config
  true
end
disable(feature, gate, thing) click to toggle source

Public: Disables a gate for a given thing.

feature - The Flipper::Feature for the gate. gate - The Flipper::Gate to disable. thing - The Flipper::Type being disabled for the gate.

Returns true.

# File lib/flipper/adapters/moneta.rb, line 84
def disable(feature, gate, thing)
  case gate.data_type
  when :boolean
    clear(feature)
  when :integer
    result = get(feature)
    result[gate.key] = thing.value.to_s
    moneta[key(feature.key)] = result
  when :set
    result = get(feature)
    result[gate.key] = result[gate.key].delete(thing.value.to_s)
    moneta[key(feature.key)] = result
  end
  true
end
enable(feature, gate, thing) click to toggle source

Public: Enables a gate for a given thing.

feature - The Flipper::Feature for the gate. gate - The Flipper::Gate to disable. thing - The Flipper::Type being enabled for the gate.

Returns true.

# File lib/flipper/adapters/moneta.rb, line 58
def enable(feature, gate, thing)
  case gate.data_type
  when :boolean
    clear(feature)
    result = get(feature)
    result[gate.key] = thing.value.to_s
    moneta[key(feature.key)] = result
  when :integer
    result = get(feature)
    result[gate.key] = thing.value.to_s
    moneta[key(feature.key)] = result
  when :set
    result = get(feature)
    result[gate.key] << thing.value.to_s
    moneta[key(feature.key)] = result
  end
  true
end
features() click to toggle source

Public: The set of known features

# File lib/flipper/adapters/moneta.rb, line 20
def features
  moneta[FEATURES_KEY] || Set.new
end
get(feature) click to toggle source

Public: Gets the values for all gates for a given feature.

Returns a Hash of Flipper::Gate#key => value.

# File lib/flipper/adapters/moneta.rb, line 47
def get(feature)
  default_config.merge(moneta[key(feature.key)].to_h)
end
remove(feature) click to toggle source

Public: Removes a feature from the set of known features and clears all the values for the feature.

# File lib/flipper/adapters/moneta.rb, line 32
def remove(feature)
  moneta[FEATURES_KEY] = features.delete(feature.key.to_s)
  moneta.delete(key(feature.key))
  true
end

Private Instance Methods

key(feature_key) click to toggle source
# File lib/flipper/adapters/moneta.rb, line 102
def key(feature_key)
  "#{FEATURES_KEY}/#{feature_key}"
end