From 8a3938a6ffc849100b9ea8d2e813fafac8be8d15 Mon Sep 17 00:00:00 2001 From: John Kodumal Date: Thu, 29 Jan 2015 21:43:44 -0800 Subject: [PATCH 1/3] Support for userTarget --- lib/ldclient-rb/ldclient.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/ldclient-rb/ldclient.rb b/lib/ldclient-rb/ldclient.rb index 3b004485..674af36f 100644 --- a/lib/ldclient-rb/ldclient.rb +++ b/lib/ldclient-rb/ldclient.rb @@ -247,8 +247,19 @@ def match_target?(target, user) end + def match_user?(variation, user) + if !!variation[:userTarget] + return match_target?(variation[:userTarget], user) + end + return false + end + def match_variation?(variation, user) variation[:targets].each do |target| + if !!variation[:userTarget] and target[:attribute].to_sym == :key + next + end + if match_target?(target, user) return true end @@ -267,6 +278,12 @@ def evaluate(feature, user) return nil end + feature[:variations].each do |variation| + if match_user?(variation, user) + return variation[:value] + end + end + feature[:variations].each do |variation| if match_variation?(variation, user) return variation[:value] From bcf17424827c8004f4d796d203f710594f8da7a8 Mon Sep 17 00:00:00 2001 From: John Kodumal Date: Fri, 30 Jan 2015 10:22:42 -0800 Subject: [PATCH 2/3] Make match_user private --- lib/ldclient-rb/ldclient.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ldclient-rb/ldclient.rb b/lib/ldclient-rb/ldclient.rb index 674af36f..b6177b8b 100644 --- a/lib/ldclient-rb/ldclient.rb +++ b/lib/ldclient-rb/ldclient.rb @@ -303,7 +303,7 @@ def evaluate(feature, user) end - private :add_event, :get_flag_int, :param_for_user, :match_target?, :match_variation?, :evaluate, :create_worker + private :add_event, :get_flag_int, :param_for_user, :match_target?, :match_user?, :match_variation?, :evaluate, :create_worker end From d94b1208612835442d1feeb2d75fe255565df92b Mon Sep 17 00:00:00 2001 From: John Kodumal Date: Fri, 30 Jan 2015 14:57:28 -0800 Subject: [PATCH 3/3] Add matching support for new built-in attributes. --- lib/ldclient-rb/ldclient.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/ldclient-rb/ldclient.rb b/lib/ldclient-rb/ldclient.rb index b6177b8b..9c72d2f9 100644 --- a/lib/ldclient-rb/ldclient.rb +++ b/lib/ldclient-rb/ldclient.rb @@ -5,6 +5,9 @@ require 'logger' module LaunchDarkly + + BUILTINS = [:key, :ip, :country, :email, :firstName, :lastName, :avatar, :name] + # # A client for the LaunchDarkly API. Client instances are thread-safe. Users # should create a single client instance for the lifetime of the application. @@ -221,7 +224,7 @@ def param_for_user(feature, user) def match_target?(target, user) attrib = target[:attribute].to_sym - if attrib == :key or attrib == :ip or attrib == :country + if BUILTINS.include?(attrib) if user[attrib] u_value = user[attrib] return target[:values].include? u_value