Sha256: 10f462cc5a4ff96a04e6dcbcacd749c08db8c780c2c19ac42eebdc66bc7075a5

Contents?: true

Size: 1.07 KB

Versions: 7

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Prefab
  class FeatureFlagClient
    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)
      @base_client.stats.increment('prefab.featureflag.on', tags: ["feature:#{feature_name}"])

      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
      @base_client.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

7 entries across 7 versions & 1 rubygems

Version Path
prefab-cloud-ruby-0.24.6 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-0.24.5 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-0.24.4 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-0.24.3 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-0.24.2 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-0.24.1 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-0.24.0 lib/prefab/feature_flag_client.rb