-
Notifications
You must be signed in to change notification settings - Fork 28
[FSSDK-11140] Ruby: Update project config to track CMAB properties #362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
5ef3c76
42a5e50
42bb090
a228105
6cb34a4
400584f
b9317bb
bf7718f
8cd522a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ class DatafileProjectConfig < ProjectConfig | |
attr_reader :datafile, :account_id, :attributes, :audiences, :typed_audiences, :events, | ||
:experiments, :feature_flags, :groups, :project_id, :bot_filtering, :revision, | ||
:sdk_key, :environment_key, :rollouts, :version, :send_flag_decisions, | ||
:attribute_key_map, :audience_id_map, :event_key_map, :experiment_feature_map, | ||
:attribute_key_map, :attribute_id_to_key_map, :audience_id_map, :event_key_map, :experiment_feature_map, | ||
:experiment_id_map, :experiment_key_map, :feature_flag_key_map, :feature_variable_key_map, | ||
:group_id_map, :rollout_id_map, :rollout_experiment_id_map, :variation_id_map, | ||
:variation_id_to_variable_usage_map, :variation_key_map, :variation_id_map_by_experiment_id, | ||
|
@@ -82,6 +82,10 @@ def initialize(datafile, logger, error_handler) | |
|
||
# Utility maps for quick lookup | ||
@attribute_key_map = generate_key_map(@attributes, 'key') | ||
@attribute_id_to_key_map = {} | ||
@attributes.each do |attribute| | ||
@attribute_id_to_key_map[attribute['id']] = attribute['key'] | ||
end | ||
@event_key_map = generate_key_map(@events, 'key') | ||
@group_id_map = generate_key_map(@groups, 'id') | ||
@group_id_map.each do |key, group| | ||
|
@@ -440,6 +444,40 @@ def get_attribute_id(attribute_key) | |
nil | ||
end | ||
|
||
def get_attribute_by_key(attribute_key) | ||
# Get attribute for the provided attribute key. | ||
# | ||
# Args: | ||
# Attribute key for which attribute is to be fetched. | ||
# | ||
# Returns: | ||
# Attribute corresponding to the provided attribute key. | ||
attribute = @attribute_key_map[attribute_key] | ||
return attribute if @attribute_key_map.key?(attribute_key) | ||
|
||
invalid_attribute_error = InvalidAttributeError.new(attribute_key) | ||
@logger.log Logger::ERROR, invalid_attribute_error.message | ||
@error_handler.handle_error invalid_attribute_error | ||
nil | ||
end | ||
|
||
def get_attribute_key_by_id(attribute_id) | ||
# Get attribute key for the provided attribute ID. | ||
# | ||
# Args: | ||
# Attribute ID for which attribute is to be fetched. | ||
# | ||
# Returns: | ||
# Attribute key corresponding to the provided attribute ID. | ||
attribute = @attribute_id_to_key_map[attribute_id] | ||
return attribute if @attribute_id_to_key_map.key?(attribute_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similar here |
||
|
||
invalid_attribute_error = InvalidAttributeError.new(attribute_id) | ||
@logger.log Logger::ERROR, invalid_attribute_error.message | ||
@error_handler.handle_error invalid_attribute_error | ||
nil | ||
end | ||
|
||
def variation_id_exists?(experiment_id, variation_id) | ||
# Determines if a given experiment ID / variation ID pair exists in the datafile | ||
# | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,6 +201,9 @@ module Constants | |
}, | ||
'forcedVariations' => { | ||
'type' => 'object' | ||
}, | ||
'cmab' => { | ||
'type' => 'object' | ||
} | ||
}, | ||
'required' => %w[ | ||
|
@@ -303,6 +306,20 @@ module Constants | |
}, | ||
'required' => %w[key] | ||
} | ||
}, | ||
'cmab' => { | ||
'type' => 'object', | ||
'items' => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as cmab field is a single object, I guess
|
||
'type' => 'object', | ||
'properties' => { | ||
'attributeIds' => { | ||
'type' => 'array' | ||
}, | ||
'trafficAllocation' => { | ||
'type' => 'integer' | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
'required' => %w[ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new test is good, but you might add further tests for the new attribute lookup methods to verify error cases and edge cases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have much ruby knowledge, but I was curious whether we can refactor like this:
Copilot says that will work