Sha256: 1a7cbae657cbe2b02e00016f4ad9d13bc275eee10b9f91e364772b950d53ad35

Contents?: true

Size: 911 Bytes

Versions: 1

Compression:

Stored size: 911 Bytes

Contents

require 'set'

module Flipper
  module Adapters
    class Memory
      # Public
      def initialize(source = nil)
        @source = source || {}
      end

      # Public
      def read(key)
        @source[key.to_s]
      end

      # Public
      def write(key, value)
        @source[key.to_s] = value.to_s
      end

      # Public
      def delete(key)
        @source.delete(key.to_s)
      end

      # Public
      def set_add(key, value)
        ensure_set_initialized(key)
        @source[key.to_s].add(value.to_s)
      end

      # Public
      def set_delete(key, value)
        ensure_set_initialized(key)
        @source[key.to_s].delete(value.to_s)
      end

      # Public
      def set_members(key)
        ensure_set_initialized(key)
        @source[key.to_s]
      end

      private

      def ensure_set_initialized(key)
        @source[key.to_s] ||= Set.new
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
flipper-0.4.0 lib/flipper/adapters/memory.rb