Sha256: 6452b6560093992c202e26cc91f97735f2c9c50a9a3bf104a4c5f02dce8ac166

Contents?: true

Size: 1004 Bytes

Versions: 19

Compression:

Stored size: 1004 Bytes

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)
      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

19 entries across 19 versions & 1 rubygems

Version Path
prefab-cloud-ruby-1.5.1 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-0 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.5.0 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.4.5 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.4.4 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.4.3 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.4.2 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.4.1 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.4.0 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.3.2 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.3.1 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.3.0 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.2.1 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.2.0 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.1.2 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.1.1 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.1.0 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.0.1 lib/prefab/feature_flag_client.rb
prefab-cloud-ruby-1.0.0 lib/prefab/feature_flag_client.rb