lib/ldclient-rb/ldclient.rb
#
# Returns a FeatureFlagsState object that encapsulates the state of all feature flags for a given user,
# including the flag values and also metadata that can be used on the front end. This method does not
# send analytics events back to LaunchDarkly.
#
# @param user [Hash] The end user requesting the feature flags
# @param options={} [Hash] Optional parameters to control how the state is generated
# @option options [Boolean] :client_side_only (false) True if only flags marked for use with the
#   client-side SDK should be included in the state. By default, all flags are included.
# @option options [Boolean] :with_reasons (false) True if evaluation reasons should be included
#   in the state (see `variation_detail`). By default, they are not included.
# @option options [Boolean] :details_only_for_tracked_flags (false) True if any flag metadata that is
# normally only used for event generation - such as flag versions and evaluation reasons - should be
# omitted for any flag that does not have event tracking or debugging turned on. This reduces the size
# of the JSON data if you are passing the flag state to the front end.
# @return [FeatureFlagsState] a FeatureFlagsState object which can be serialized to JSON
#
Returns a FeatureFlagsState object that encapsulates the state of all feature flags for a given user,
including the flag values and also metadata that can be used on the front end. This method does not
send analytics events back to LaunchDarkly.
Returns a FeatureFlagsState object that encapsulates the state of all feature flags for a given user including the flag values and also metadata that can be used on the front end . This method does not send analytics events back to LaunchDarkly .
def all_flags_state(user, options={})
      return FeatureFlagsState.new(false) if @config.offline?
      unless user && !user[:key].nil?
        @config.logger.error { "[LDClient] User and user key must be specified in all_flags_state" }
        return FeatureFlagsState.new(false)
      end
      sanitize_user(user)
      begin
        features = @store.all(FEATURES)
      rescue => exn
        Util.log_exception(@config.logger, "Unable to read flags for all_flags_state", exn)
        return FeatureFlagsState.new(false)
      end
      state = FeatureFlagsState.new(true)
      client_only = options[:client_side_only] || false
      with_reasons = options[:with_reasons] || false
      details_only_if_tracked = options[:details_only_for_tracked_flags] || false
      features.each do |k, f|
        if client_only && !f[:clientSide]
          next
        end
        begin
          result = evaluate(f, user, @store, @config.logger)
          state.add_flag(f, result.detail.value, result.detail.variation_index, with_reasons ? result.detail.reason : nil,
            details_only_if_tracked)
        rescue => exn
          Util.log_exception(@config.logger, "Error evaluating flag \"#{k}\" in all_flags_state", exn)
          state.add_flag(f, nil, nil, with_reasons ? { kind: 'ERROR', errorKind: 'EXCEPTION' } : nil, details_only_if_tracked)
        end
      end
      state
    end
def all_flags_state ( user , options = { } ) return FeatureFlagsState . new ( false ) if @config . offline? unless user && ! user [ :key ] . nil? @config . logger . error { "[LDClient] User and user key must be specified in all_flags_state" } return FeatureFlagsState . new ( false ) end sanitize_user ( user ) begin features = @store . all ( FEATURES ) rescue => exn Util . log_exception ( @config . logger , "Unable to read flags for all_flags_state" , exn ) return FeatureFlagsState . new ( false ) end state = FeatureFlagsState . new ( true ) client_only = options [ :client_side_only ] || false with_reasons = options [ :with_reasons ] || false details_only_if_tracked = options [ :details_only_for_tracked_flags ] || false features . each do | k , f | if client_only && ! f [ :clientSide ] next end begin result = evaluate ( f , user , @store , @config . logger ) state . add_flag ( f , result . detail . value , result . detail . variation_index , with_reasons ? result . detail . reason : nil , details_only_if_tracked ) rescue => exn Util . log_exception ( @config . logger , "Error evaluating flag \"#{k}\" in all_flags_state" , exn ) state . add_flag ( f , nil , nil , with_reasons ? { kind : 'ERROR' , errorKind : 'EXCEPTION' } : nil , details_only_if_tracked ) end end state end
Returns a FeatureFlagsState object that encapsulates the state of all feature flags for a given user,
including the flag values and also metadata that can be used on the front end.
Returns a FeatureFlagsState object that encapsulates the state of all feature flags for a given user including the flag values and also metadata that can be used on the front end .
a FeatureFlagsState object which can be serialized to JSON
a FeatureFlagsState object which can be serialized to JSON
FeatureFlagsState
user
The end user requesting the feature flags
The end user requesting the feature flags
options
:details_only_for_tracked_flags (false) True if any flag metadata that is normally only used for event generation - such as flag versions and evaluation reasons - should be omitted for any flag that does not have event tracking or debugging turned on. This reduces the size of the JSON data if you are passing the flag state to the front end.
: details_only_for_tracked_flags ( false ) True if any flag metadata that is normally only used for event generation - such as flag versions and evaluation reasons - should be omitted for any flag that does not have event tracking or debugging turned on . This reduces the size of the JSON data if you are passing the flag state to the front end .
options={}
<not_specific>
Optional parameters to control how the state is generated
Optional parameters to control how the state is generated