Class: ConfigCat::EvaluationLogBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/configcat/evaluationlogbuilder.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEvaluationLogBuilder

Returns a new instance of EvaluationLogBuilder.



3
4
5
6
# File 'lib/configcat/evaluationlogbuilder.rb', line 3

def initialize
  @indent_level = 0
  @text = ''
end

Class Method Details

.trunc_comparison_value_if_needed(comparator, comparison_value) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/configcat/evaluationlogbuilder.rb', line 8

def self.trunc_comparison_value_if_needed(comparator, comparison_value)
  if [
    Comparator::IS_ONE_OF_HASHED,
    Comparator::IS_NOT_ONE_OF_HASHED,
    Comparator::EQUALS_HASHED,
    Comparator::NOT_EQUALS_HASHED,
    Comparator::STARTS_WITH_ANY_OF_HASHED,
    Comparator::NOT_STARTS_WITH_ANY_OF_HASHED,
    Comparator::ENDS_WITH_ANY_OF_HASHED,
    Comparator::NOT_ENDS_WITH_ANY_OF_HASHED,
    Comparator::ARRAY_CONTAINS_ANY_OF_HASHED,
    Comparator::ARRAY_NOT_CONTAINS_ANY_OF_HASHED
  ].include?(comparator)
    if comparison_value.is_a?(Array)
      length = comparison_value.length
      if length > 1
        return "[<#{length} hashed values>]"
      end
      return "[<#{length} hashed value>]"
    end

    return "'<hashed value>'"
  end

  if comparison_value.is_a?(Array)
    length_limit = 10
    length = comparison_value.length
    if length > length_limit
      remaining = length - length_limit
      more_text = remaining == 1 ? "<1 more value>" : "<#{remaining} more values>"

      formatted_strings = comparison_value.first(length_limit).map { |str| "'#{str}'" }.join(", ")
      return "[#{formatted_strings}, ... #{more_text}]"
    end

    # replace '"' with "'" in the string representation of the array
    formatted_strings = comparison_value.map { |str| "'#{str}'" }.join(", ")
    return "[#{formatted_strings}]"
  end

  if [Comparator::BEFORE_DATETIME, Comparator::AFTER_DATETIME].include?(comparator)
    time = Utils.get_date_time(comparison_value)
    return "'#{comparison_value}' (#{time.strftime('%Y-%m-%dT%H:%M:%S.%L')}Z UTC)"
  end

  "'#{comparison_value.to_s}'"
end

Instance Method Details

#append(text) ⇒ Object



66
67
68
69
# File 'lib/configcat/evaluationlogbuilder.rb', line 66

def append(text)
  @text += text
  self
end

#decrease_indentObject



61
62
63
64
# File 'lib/configcat/evaluationlogbuilder.rb', line 61

def decrease_indent
  @indent_level = [@indent_level - 1, 0].max
  self
end

#increase_indentObject



56
57
58
59
# File 'lib/configcat/evaluationlogbuilder.rb', line 56

def increase_indent
  @indent_level += 1
  self
end

#new_line(text = nil) ⇒ Object



71
72
73
74
75
# File 'lib/configcat/evaluationlogbuilder.rb', line 71

def new_line(text = nil)
  @text += "\n" + '  ' * @indent_level
  @text += text if text
  self
end

#to_sObject



77
78
79
# File 'lib/configcat/evaluationlogbuilder.rb', line 77

def to_s
  @text
end