Class: Feature

Inherits:
Object
  • Object
show all
Defined in:
lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb

Overview

Feature model for App Configuration service

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feature) ⇒ Feature

Returns a new instance of Feature.

Parameters:

  • feature (Hash)

    Feature configuration hash



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb', line 27

def initialize(feature)
  @name = feature[:name]
  @feature_id = feature[:feature_id]
  @type = feature[:type]
  @format = feature[:format]
  @disabled_value = feature[:disabled_value]
  @enabled_value = feature[:enabled_value]
  @enabled = feature[:enabled]
  @rollout_type = feature.key?(:rollout_type) ? feature[:rollout_type] : Constants::MANUAL

  if feature[:rollout_configuration]
    @rollout_configuration = feature[:rollout_configuration]
  else
    @rollout_percentage = feature.key?(:rollout_percentage) ? feature[:rollout_percentage] : 100
  end

  @segment_rules = feature[:segment_rules]
  @experiment = feature[:experiment]
end

Instance Attribute Details

#disabled_valueObject (readonly)

Returns the value of attribute disabled_value.



22
23
24
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb', line 22

def disabled_value
  @disabled_value
end

#enabledObject (readonly)

Returns the value of attribute enabled.



22
23
24
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb', line 22

def enabled
  @enabled
end

#enabled_valueObject (readonly)

Returns the value of attribute enabled_value.



22
23
24
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb', line 22

def enabled_value
  @enabled_value
end

#experimentObject (readonly)

Returns the value of attribute experiment.



22
23
24
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb', line 22

def experiment
  @experiment
end

#feature_idObject (readonly)

Returns the value of attribute feature_id.



22
23
24
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb', line 22

def feature_id
  @feature_id
end

#formatObject (readonly)

Returns the value of attribute format.



22
23
24
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb', line 22

def format
  @format
end

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb', line 22

def name
  @name
end

#rollout_configurationObject (readonly)

Returns the value of attribute rollout_configuration.



22
23
24
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb', line 22

def rollout_configuration
  @rollout_configuration
end

#rollout_percentageObject (readonly)

Returns the value of attribute rollout_percentage.



22
23
24
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb', line 22

def rollout_percentage
  @rollout_percentage
end

#rollout_typeObject (readonly)

Returns the value of attribute rollout_type.



22
23
24
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb', line 22

def rollout_type
  @rollout_type
end

#segment_rulesObject (readonly)

Returns the value of attribute segment_rules.



22
23
24
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb', line 22

def segment_rules
  @segment_rules
end

#typeObject (readonly)

Returns the value of attribute type.



22
23
24
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb', line 22

def type
  @type
end

Instance Method Details

#get_current_value(entity_id, entity_attributes = {}) ⇒ Hash?

Evaluates and returns feature value for entity. Returns a hash containing evaluated value, enabled status & detailed reason.

Examples:

feature = app_config_client.get_feature('discount')
if feature
  result = feature.get_current_value(entity_id, entity_attributes)

  # Access the evaluated value, enabled status & details as shown below
  # result[:value]
  # result[:is_enabled]
  # result[:details]
end

# Note: While experiment is running, the `true` value of result[:is_enabled] indicates that
# given entity_id was part of experiment audience. The `false` value indicates the entity_id
# was not part of experiment audience.

Parameters:

  • entity_id (String)

    Id of the Entity. This will be a string identifier related to the Entity against which the feature is evaluated. For example, an entity might be an instance of an app that runs on a mobile device, a microservice that runs on the cloud, or a component of infrastructure that runs that microservice. For any entity to interact with App Configuration, it must provide a unique entity ID.

  • entity_attributes (Hash) (defaults to: {})

    A hash consisting of the attribute name and their values that defines the specified entity. This is an optional parameter if the feature flag is not configured with any targeting definition. If the targeting is configured, then entity_attributes should be provided for the rule evaluation. An attribute is a parameter that is used to define a segment. The SDK uses the attribute values to determine if the specified entity satisfies the targeting rules, and returns the appropriate feature flag value.

Returns:

  • (Hash, nil)

    Returns a hash containing evaluated value, enabled status & detailed reason. The evaluated value will be one of Enabled/Disabled/Overridden value based on the evaluation. The data type of evaluated value matches that of feature flag. Returns nil if entity_id is invalid.



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb', line 110

def get_current_value(entity_id, entity_attributes = {})
  if entity_id.nil? || entity_id.to_s.strip.empty?
    logger = Logger.instance
    logger.error("Feature flag evaluation: #{Constants::INVALID_ENTITY_ID} get_current_value")
    return nil
  end

  require_relative "../configuration_handler"
  configuration_handler_instance = ConfigurationHandler.instance
  configuration_handler_instance.feature_evaluation(self, entity_id, entity_attributes)
end

#get_feature_data_formatString?

Returns Feature data format (TEXT/JSON/YAML).

Returns:

  • (String, nil)

    Feature data format (TEXT/JSON/YAML)



63
64
65
66
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb', line 63

def get_feature_data_format
  @format = "TEXT" if @format.nil? && @type == "STRING"
  @format
end

#get_feature_data_typeString

Returns Feature data type (BOOLEAN/STRING/NUMERIC).

Returns:

  • (String)

    Feature data type (BOOLEAN/STRING/NUMERIC)



58
59
60
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb', line 58

def get_feature_data_type
  @type || ""
end

#get_feature_idString

Returns Feature ID.

Returns:

  • (String)

    Feature ID



53
54
55
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb', line 53

def get_feature_id
  @feature_id || ""
end

#get_feature_nameString

Returns Feature name.

Returns:

  • (String)

    Feature name



48
49
50
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb', line 48

def get_feature_name
  @name || ""
end

#is_enabled?Boolean

Returns Feature enabled state.

Returns:

  • (Boolean)

    Feature enabled state



69
70
71
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb', line 69

def is_enabled?
  @enabled
end