Class: LaunchDarkly::UserFilter
- Inherits:
-
Object
- Object
- LaunchDarkly::UserFilter
- Defined in:
- lib/ldclient-rb/user_filter.rb
Instance Method Summary collapse
-
#initialize(config) ⇒ UserFilter
constructor
A new instance of UserFilter.
- #transform_user_props(user_props) ⇒ Object
Constructor Details
#initialize(config) ⇒ UserFilter
Returns a new instance of UserFilter.
7 8 9 10 |
# File 'lib/ldclient-rb/user_filter.rb', line 7 def initialize(config) @all_attributes_private = config.all_attributes_private @private_attribute_names = Set.new(config.private_attribute_names.map(&:to_sym)) end |
Instance Method Details
#transform_user_props(user_props) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ldclient-rb/user_filter.rb', line 12 def transform_user_props(user_props) return nil if user_props.nil? user_private_attrs = Set.new((user_props[:privateAttributeNames] || []).map(&:to_sym)) filtered_user_props, removed = filter_values(user_props, user_private_attrs, ALLOWED_TOP_LEVEL_KEYS, IGNORED_TOP_LEVEL_KEYS) custom = user_props[:custom] if !custom.nil? filtered_user_props[:custom], removed_custom = filter_values(custom, user_private_attrs) removed.merge(removed_custom) end unless removed.empty? # note, :privateAttributeNames is what the developer sets; :privateAttrs is what we send to the server filtered_user_props[:privateAttrs] = removed.to_a.sort.map { |s| s.to_s } end return filtered_user_props end |