Class: IbmAppconfigurationRubySdk::Property

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(property) ⇒ Property

Initialize a new Property instance

Parameters:

  • property (Hash)

    properties hash that contains all the properties



29
30
31
32
33
34
35
36
# File 'lib/ibm_appconfiguration_ruby_sdk/models/property.rb', line 29

def initialize(property)
  @name = property[:name]
  @property_id = property[:property_id]
  @type = property[:type]
  @format = property[:format] # will be nil for boolean & numeric datatypes
  @value = property[:value]
  @segment_rules = property[:segment_rules]
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



24
25
26
# File 'lib/ibm_appconfiguration_ruby_sdk/models/property.rb', line 24

def format
  @format
end

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/ibm_appconfiguration_ruby_sdk/models/property.rb', line 24

def name
  @name
end

#property_idObject (readonly)

Returns the value of attribute property_id.



24
25
26
# File 'lib/ibm_appconfiguration_ruby_sdk/models/property.rb', line 24

def property_id
  @property_id
end

#segment_rulesObject (readonly)

Returns the value of attribute segment_rules.



24
25
26
# File 'lib/ibm_appconfiguration_ruby_sdk/models/property.rb', line 24

def segment_rules
  @segment_rules
end

#typeObject (readonly)

Returns the value of attribute type.



24
25
26
# File 'lib/ibm_appconfiguration_ruby_sdk/models/property.rb', line 24

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



24
25
26
# File 'lib/ibm_appconfiguration_ruby_sdk/models/property.rb', line 24

def value
  @value
end

Instance Method Details

#data_formatString?

Get the Property data format applicable only for STRING datatype property.

Returns:

  • (String, nil)

    string named TEXT/JSON/YAML



43
44
45
46
47
48
# File 'lib/ibm_appconfiguration_ruby_sdk/models/property.rb', line 43

def data_format
  # Format will be `nil` for Boolean & Numeric properties
  # If the Format is nil for a String type, we default it to TEXT
  @format = "TEXT" if @format.nil? && @type == "STRING"
  @format
end

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

Get the evaluated value of the property.

Examples:

property = app_config_client.get_property('discount')
if property
  result = property.get_current_value(entity_id, entity_attributes)
  result.value               # => the resolved property value
  result.details.value_type  # => "DEFAULT_VALUE" / "SEGMENT_VALUE"
end

Parameters:

  • entity_id (String)

    Id of the Entity. This will be a string identifier related to the Entity against which the property 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 property 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 property value.

Returns:

  • (EvaluationResult, nil)

    Returns an EvaluationResult with:

    • result.value — the resolved value (type matches the property's type)
    • result.details — an EvaluationDetails explaining how the value was reached (+result.enabled+ is always nil for properties) Returns nil if entity_id is invalid.


79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ibm_appconfiguration_ruby_sdk/models/property.rb', line 79

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

  require_relative "../configuration_handler"
  configuration_handler_instance = ConfigurationHandler.current_instance
  configuration_handler_instance.property_evaluation(self, entity_id, entity_attributes)
end