Sha256: 730184e3a84d2521039f4085ace9d7c12dabc1d201d62f918f52f932979ec5ea

Contents?: true

Size: 1.01 KB

Versions: 17

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Prefab
  class FeatureFlagClient
    LOG = Prefab::InternalLogger.new(self)
    def initialize(base_client)
      @base_client = base_client
    end

    def feature_is_on?(feature_name)
      feature_is_on_for?(feature_name, {})
    end

    def feature_is_on_for?(feature_name, properties)
      variant = @base_client.config_client.get(feature_name, false, properties)

      is_on?(variant)
    end

    def get(feature_name, properties, default: false)
      value = _get(feature_name, properties)

      value.nil? ? default : value
    end

    private

    def _get(feature_name, properties)
      @base_client.config_client.get(feature_name, nil, properties)
    end

    def is_on?(variant)
      return false if variant.nil?

      return variant if variant == !!variant

      variant.bool
    rescue StandardError
      LOG.info("is_on? methods only work for boolean feature flags variants. This feature flags variant is '#{variant}'. Returning false")
      false
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
prefab-cloud-ruby-1.8.8.pre.1 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.8.7 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.8.6 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.8.5 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.8.4 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.8.3 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.8.2 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.8.1 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.8.0 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.7.2 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.7.1 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.7.0 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.6.2 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.6.1 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.6.0 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.6.0.pre2 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.6.0.pre1 lib/prefab/feature_flag_client.rb