Sha256: 6ede17dd2dc1317bc683590f40027898ba813ba0d178e3dd139747cb432ac4b1

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

# typed: strict
# frozen_string_literal: true

require "singleton"

module OpenFeature
  # Singleton class that supports global configuration for OpenFeature.
  # Should not be interacted with directly; rather, favor interacting
  # with methods defined on the `OpenFeature` module.
  class Configuration
    extend T::Sig

    include Singleton

    sig { returns(Provider) }
    attr_reader :provider

    sig { returns(T::Array[Hook]) }
    attr_reader :hooks

    sig { void }
    def initialize
      @provider = T.let(NoOpProvider.new, Provider)
      @hooks = T.let([], T::Array[Hook])
    end

    sig { returns(ProviderMetadata) }
    def provider_metadata
      provider.metadata
    end

    sig { params(provider: Provider).void }
    def set_provider(provider) # rubocop:disable Naming/AccessorMethodName
      @provider = provider
    end

    sig { params(hooks: T.any(Hook, T::Array[Hook])).void }
    def add_hooks(hooks)
      @hooks.concat(Array(hooks))
    end

    sig { void }
    def clear_hooks!
      @hooks = []
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
openfeature-sdk-sorbet-0.1.2 lib/open_feature/configuration.rb
openfeature-sdk-sorbet-0.1.1 lib/open_feature/configuration.rb
openfeature-sdk-sorbet-0.1.0 lib/open_feature/configuration.rb