Class: Property

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

Overview

Defines the model of a Property defined in App Configuration service.

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



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

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.



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

def format
  @format
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#property_idObject (readonly)

Returns the value of attribute property_id.



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

def property_id
  @property_id
end

#segment_rulesObject (readonly)

Returns the value of attribute segment_rules.



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

def segment_rules
  @segment_rules
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

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

Get the evaluated value of the property.

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.

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.

The evaluated value will be either the default property value or its overridden value based on the evaluation. The data type of returned value matches that of property. Returns nil if entity_id is invalid.

Examples:

property = app_config_client.get_property('discount')
if property
  result = property.get_current_value(entity_id, entity_attributes)

  # Access the evaluated value & details as shown below
  # result[:value]
  # result[:details]
end

Parameters:

  • entity_id (String)

    Id of the Entity.

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

    A hash consisting of the attribute name and their values that defines the specified entity.

Returns:

  • (Hash, nil)

    Returns a hash containing evaluated value & detailed reason.



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/property.rb', line 96

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.instance
  configuration_handler_instance.property_evaluation(self, entity_id, entity_attributes)
end

#get_property_data_formatString?

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

Returns:

  • (String, nil)

    string named TEXT/JSON/YAML



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

def get_property_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_property_data_typeString

Get the Property data type

Returns:

  • (String)

    string named BOOLEAN/STRING/NUMERIC



54
55
56
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/property.rb', line 54

def get_property_data_type
  @type || ""
end

#get_property_idString

Get the Property id

Returns:

  • (String)

    The Property Id



47
48
49
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/property.rb', line 47

def get_property_id
  @property_id || ""
end

#get_property_nameString

Get the Property name

Returns:

  • (String)

    The Property name



40
41
42
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/property.rb', line 40

def get_property_name
  @name || ""
end