class Togls::FeatureRepositoryDrivers::InMemoryDriver

Feature Repository In-Memory Driver

The Feature Repository In-Memory Driver provides the facility to store and retrieve features to and from the in-memory store.

Public Class Methods

new() click to toggle source
# File lib/togls/feature_repository_drivers/in_memory_driver.rb, line 10
def initialize
  @features = {}
  @features_lock = Mutex.new
end

Public Instance Methods

get(feature_id) click to toggle source
# File lib/togls/feature_repository_drivers/in_memory_driver.rb, line 21
def get(feature_id)
  @features_lock.synchronize do
    if @features.has_key?(feature_id)
      Marshal.load(@features[feature_id])
    else
      nil
    end
  end
end
store(feature_id, feature_data) click to toggle source
# File lib/togls/feature_repository_drivers/in_memory_driver.rb, line 15
def store(feature_id, feature_data)
  @features_lock.synchronize do
    @features[feature_id] = Marshal.dump(feature_data)
  end
end