Class: SplitIoClient::Validators
- Inherits:
-
Object
- Object
- SplitIoClient::Validators
- Defined in:
- lib/splitclient-rb/validators.rb
Constant Summary collapse
- Flagset_regex =
/^[a-z0-9][_a-z0-9]{0,49}$/
Instance Method Summary collapse
-
#initialize(config) ⇒ Validators
constructor
A new instance of Validators.
- #valid_flag_sets(method, flag_sets) ⇒ Object
- #valid_get_treatment_parameters(method, key, split_name, matching_key, bucketing_key, attributes) ⇒ Object
- #valid_get_treatments_parameters(method, key, split_names, matching_key, bucketing_key, attributes) ⇒ Object
- #valid_matcher_arguments(args) ⇒ Object
- #valid_split_parameters(split_name) ⇒ Object
- #valid_track_parameters(key, traffic_type_name, event_type, value, properties) ⇒ Object
Constructor Details
#initialize(config) ⇒ Validators
Returns a new instance of Validators.
8 9 10 |
# File 'lib/splitclient-rb/validators.rb', line 8 def initialize(config) @config = config end |
Instance Method Details
#valid_flag_sets(method, flag_sets) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/splitclient-rb/validators.rb', line 47 def valid_flag_sets(method, flag_sets) if flag_sets.nil? || !flag_sets.is_a?(Array) @config.logger.error("#{method}: FlagSets must be a non-empty list.") return [] end if flag_sets.empty? @config.logger.error("#{method}: FlagSets must be a non-empty list.") return [] end without_nil = Array.new flag_sets.each { |flag_set| without_nil.push(flag_set) if !flag_set.nil? log_nil("flag set", method) if flag_set.nil? } if without_nil.length() == 0 log_invalid_flag_set_type(method) return [] end valid_flag_sets = Set[] without_nil.compact.uniq.select do |flag_set| if flag_set.nil? || !flag_set.is_a?(String) log_invalid_flag_set_type(method) elsif flag_set.is_a?(String) && flag_set.empty? log_invalid_flag_set_type(method) elsif !flag_set.empty? && string_match?(flag_set.strip.downcase, method) valid_flag_sets.add(flag_set.strip.downcase) else log_invalid_flag_set_type(method) end end !valid_flag_sets.empty? ? valid_flag_sets.to_a.sort : [] end |
#valid_get_treatment_parameters(method, key, split_name, matching_key, bucketing_key, attributes) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/splitclient-rb/validators.rb', line 12 def valid_get_treatment_parameters(method, key, split_name, matching_key, bucketing_key, attributes) valid_key?(method, key) && valid_split_name?(method, split_name) && valid_matching_key?(method, matching_key) && valid_bucketing_key?(method, key, bucketing_key) && valid_attributes?(method, attributes) end |
#valid_get_treatments_parameters(method, key, split_names, matching_key, bucketing_key, attributes) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/splitclient-rb/validators.rb', line 20 def valid_get_treatments_parameters(method, key, split_names, matching_key, bucketing_key, attributes) valid_key?(method, key) && valid_split_names?(method, split_names) valid_matching_key?(method, matching_key) && valid_bucketing_key?(method, key, bucketing_key) && valid_attributes?(method, attributes) end |
#valid_matcher_arguments(args) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/splitclient-rb/validators.rb', line 40 def valid_matcher_arguments(args) return false if !args.key?(:attributes) && !args.key?(:value) return false if args.key?(:value) && args[:value].nil? return false if args.key?(:attributes) && args[:attributes].nil? true end |
#valid_split_parameters(split_name) ⇒ Object
36 37 38 |
# File 'lib/splitclient-rb/validators.rb', line 36 def valid_split_parameters(split_name) valid_split_name?(:split, split_name) end |
#valid_track_parameters(key, traffic_type_name, event_type, value, properties) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/splitclient-rb/validators.rb', line 28 def valid_track_parameters(key, traffic_type_name, event_type, value, properties) valid_track_key?(key) && valid_traffic_type_name?(traffic_type_name) && valid_event_type?(event_type) && valid_value?(value) && valid_properties?(properties) end |