Sha256: 02feed9ecefae45b27094679159bcf8b2f1d8201c2ab9a0b1bff223fdcba877a

Contents?: true

Size: 1.08 KB

Versions: 6

Compression:

Stored size: 1.08 KB

Contents

require 'flipper'

module Flipper
  module Adapters
    # Public: Adapter that wraps another adapter and raises for any writes.
    class ReadOnly
      include ::Flipper::Adapter

      class WriteAttempted < Error
        def initialize(message = nil)
          super(message || 'write attempted while in read only mode')
        end
      end

      # Public
      def initialize(adapter)
        @adapter = adapter
      end

      def features
        @adapter.features
      end

      def read_only?
        true
      end

      def get(feature)
        @adapter.get(feature)
      end

      def get_multi(features)
        @adapter.get_multi(features)
      end

      def get_all
        @adapter.get_all
      end

      def add(_feature)
        raise WriteAttempted
      end

      def remove(_feature)
        raise WriteAttempted
      end

      def clear(_feature)
        raise WriteAttempted
      end

      def enable(_feature, _gate, _thing)
        raise WriteAttempted
      end

      def disable(_feature, _gate, _thing)
        raise WriteAttempted
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
flipper-1.2.2 lib/flipper/adapters/read_only.rb
flipper-1.2.1 lib/flipper/adapters/read_only.rb
flipper-1.2.0 lib/flipper/adapters/read_only.rb
flipper-1.1.2 lib/flipper/adapters/read_only.rb
flipper-1.1.1 lib/flipper/adapters/read_only.rb
flipper-1.1.0 lib/flipper/adapters/read_only.rb