class Flipper::Adapters::Memory

Public: Adapter for storing everything in memory. Useful for tests/specs.

Constants

FeaturesKey

Attributes

name[R]

Public: The name of the adapter.

Public Class Methods

new(source = nil) click to toggle source

Public

# File lib/flipper/adapters/memory.rb, line 16
def initialize(source = nil)
  @source = source || {}
  @name = :memory
end

Public Instance Methods

add(feature) click to toggle source

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

# File lib/flipper/adapters/memory.rb, line 27
def add(feature)
  @source[feature.key] ||= default_config
  true
end
clear(feature) click to toggle source

Public: Clears all the gate values for a feature.

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

Public

# File lib/flipper/adapters/memory.rb, line 82
def disable(feature, gate, thing)
  @source[feature.key] ||= default_config

  case gate.data_type
  when :boolean
    clear(feature)
  when :integer
    @source[feature.key][gate.key] = thing.value.to_s
  when :set
    @source[feature.key][gate.key].delete thing.value.to_s
  else
    raise "#{gate} is not supported by this adapter yet"
  end

  true
end
enable(feature, gate, thing) click to toggle source

Public

# File lib/flipper/adapters/memory.rb, line 63
def enable(feature, gate, thing)
  @source[feature.key] ||= default_config

  case gate.data_type
  when :boolean
    clear(feature)
    @source[feature.key][gate.key] = thing.value.to_s
  when :integer
    @source[feature.key][gate.key] = thing.value.to_s
  when :set
    @source[feature.key][gate.key] << thing.value.to_s
  else
    raise "#{gate} is not supported by this adapter yet"
  end

  true
end
features() click to toggle source

Public: The set of known features.

# File lib/flipper/adapters/memory.rb, line 22
def features
  @source.keys.to_set
end
get(feature) click to toggle source

Public

# File lib/flipper/adapters/memory.rb, line 46
def get(feature)
  @source[feature.key] || default_config
end
get_all() click to toggle source
# File lib/flipper/adapters/memory.rb, line 58
def get_all
  @source
end
get_multi(features) click to toggle source
# File lib/flipper/adapters/memory.rb, line 50
def get_multi(features)
  result = {}
  features.each do |feature|
    result[feature.key] = @source[feature.key] || default_config
  end
  result
end
inspect() click to toggle source

Public

# File lib/flipper/adapters/memory.rb, line 100
def inspect
  attributes = [
    'name=:memory',
    "source=#{@source.inspect}",
  ]
  "#<#{self.class.name}:#{object_id} #{attributes.join(', ')}>"
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/memory.rb, line 34
def remove(feature)
  @source.delete(feature.key)
  true
end