Sha256: 002a4804a998212c476e2d99358c9df154c76e12f7c96843ca245596980f8b13

Contents?: true

Size: 905 Bytes

Versions: 5

Compression:

Stored size: 905 Bytes

Contents

# frozen_string_literal: true
require "singleton"

module ActiveMocker
  class LoadedMocks
    class Features
      include Singleton
      DEFAULTS = {
        timestamps:                false,
        delete_all_before_example: false,
      }.freeze

      def initialize
        reset
      end

      def each(&block)
        @features.each(&block)
      end

      def enable(feature)
        update(feature, true)
      end

      def disable(feature)
        update(feature, false)
      end

      def [](feature)
        @features[feature]
      end

      def reset
        @features = DEFAULTS.dup
      end

      def to_h
        @features
      end

      private

      def update(feature, value)
        if @features.key?(feature)
          @features[feature] = value
        else
          raise KeyError, "#{feature} is not an available feature."
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
active_mocker-2.4.0.pre5 lib/active_mocker/loaded_mocks/features.rb
active_mocker-2.4.0.pre4 lib/active_mocker/loaded_mocks/features.rb
active_mocker-2.4.0.pre3 lib/active_mocker/loaded_mocks/features.rb
active_mocker-2.4.0.pre2 lib/active_mocker/loaded_mocks/features.rb
active_mocker-2.4.0.pre1 lib/active_mocker/loaded_mocks/features.rb