togul 2.4.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75fde010ac0c727c425c169bff582437c313ddc71a06e6bd285cd3271848afde
4
- data.tar.gz: 3fcf4a81648a4c4bf52538026fa17ef7ac4fda0e5bc2c34bc9caa74bad029a8a
3
+ metadata.gz: f3cdd5233b5ab5e0c0a9173d1cad50da849053ac889f1421cf65e115cc5dd615
4
+ data.tar.gz: d910912cdca70532ddbc022caf2e8b4b8aca2bc2faac23a64f62aa1a1af287b3
5
5
  SHA512:
6
- metadata.gz: b13234a1b51798a399e6cb7e9a80274c2ef26db810df4d0f609329c097cf90cd71bddd2a6b11d00dd1b565efc43f6ff75b2f99bd8c5105c4917735dd0ac860e3
7
- data.tar.gz: 1723699c586897d12cb4b29a2c8f8bbfd9563daea8ad6e1c598c035eb2efd7cead5d2fd3e823ca7ad97ea416a830100eff7287a149fdaffa26eac79e3ee8f306
6
+ metadata.gz: 3543177c1ed3be6bb8a4d8e8eec2c0cf430ff67e095673aa7aa1466ae3d518e24a072d08dadf8498a350dd3ebbb415dbeea96af5621db303589f5c88c2efd3ee
7
+ data.tar.gz: ad43d8263b6f8c0c470ac11f69b2fdef12edfd960fc3bd5da65cccc38ccef0ca75a43f7a175d264dc6952294b01faddc61873fead885c88b60aeeec38274b664
data/lib/togul/client.rb CHANGED
@@ -13,84 +13,22 @@ module Togul
13
13
  @stream_client = nil
14
14
  end
15
15
 
16
- # Evaluate a feature flag.
17
- #
18
- # @param key [String] Flag key
19
- # @param context [Hash<String, String>] User/request context
20
- # @return [Boolean] Whether the flag is enabled
21
- def enabled?(key, context = {})
22
- evaluate_result(key, context).enabled?
23
- rescue StandardError
24
- case @config.fallback_mode
25
- when :fail_open then true
26
- else false
27
- end
28
- end
29
-
30
- # Evaluate a feature flag and return the full result with typed value accessors.
16
+ # Evaluate a feature flag and return the result mirroring the API response.
31
17
  #
32
18
  # @param key [String] Flag key
33
19
  # @param context [Hash<String, String>] User/request context
34
20
  # @return [Togul::EvaluateResult]
35
- def evaluate_result(key, context = {})
21
+ def evaluate(key, context = {})
36
22
  cache_key = build_cache_key(key, context)
37
23
 
38
24
  cached = @cache.get(cache_key)
39
25
  return cached unless cached.nil?
40
26
 
41
- result = evaluate(key, context)
27
+ result = fetch_evaluation(key, context)
42
28
  @cache.set(cache_key, result)
43
29
  result
44
30
  end
45
31
 
46
- # Evaluate a boolean flag.
47
- #
48
- # @param key [String] Flag key
49
- # @param context [Hash<String, String>] User/request context
50
- # @param fallback [Boolean] Value to return on error or type mismatch
51
- # @return [Boolean]
52
- def evaluate_bool(key, context = {}, fallback: false)
53
- evaluate_result(key, context).bool_value(fallback)
54
- rescue StandardError
55
- fallback
56
- end
57
-
58
- # Evaluate a string flag.
59
- #
60
- # @param key [String] Flag key
61
- # @param context [Hash<String, String>] User/request context
62
- # @param fallback [String] Value to return on error or type mismatch
63
- # @return [String]
64
- def evaluate_string(key, context = {}, fallback: '')
65
- evaluate_result(key, context).string_value(fallback)
66
- rescue StandardError
67
- fallback
68
- end
69
-
70
- # Evaluate a number flag.
71
- #
72
- # @param key [String] Flag key
73
- # @param context [Hash<String, String>] User/request context
74
- # @param fallback [Float] Value to return on error or type mismatch
75
- # @return [Float]
76
- def evaluate_number(key, context = {}, fallback: 0.0)
77
- evaluate_result(key, context).number_value(fallback)
78
- rescue StandardError
79
- fallback
80
- end
81
-
82
- # Evaluate a JSON flag.
83
- #
84
- # @param key [String] Flag key
85
- # @param context [Hash<String, String>] User/request context
86
- # @param fallback [Object] Value to return on error or type mismatch
87
- # @return [Object]
88
- def evaluate_json(key, context = {}, fallback: nil)
89
- evaluate_result(key, context).json_value(fallback)
90
- rescue StandardError
91
- fallback
92
- end
93
-
94
32
  # Clear all cached flag values.
95
33
  def invalidate_cache
96
34
  @cache.flush
@@ -113,7 +51,7 @@ module Togul
113
51
 
114
52
  private
115
53
 
116
- def evaluate(key, context)
54
+ def fetch_evaluation(key, context)
117
55
  raise Error.new('API key is required') if @config.api_key.empty?
118
56
 
119
57
  last_error = nil
@@ -152,7 +90,7 @@ module Togul
152
90
  flag_key: body['flag_key'] || key,
153
91
  enabled: body['enabled'] == true,
154
92
  value_type: body['value_type'].to_s,
155
- raw_value: body['value'],
93
+ value: body['value'],
156
94
  reason: body['reason'].to_s
157
95
  )
158
96
  rescue Error
data/lib/togul/config.rb CHANGED
@@ -4,13 +4,12 @@ module Togul
4
4
  class Config
5
5
  DEFAULT_BASE_URL = 'https://api.togul.io'
6
6
 
7
- attr_reader :api_key, :environment, :timeout, :cache_ttl, :fallback_mode, :retry_count, :base_url
7
+ attr_reader :api_key, :environment, :timeout, :cache_ttl, :retry_count, :base_url
8
8
 
9
9
  # @param environment [String] Environment key (e.g. "production")
10
10
  # @param api_key [String] Environment API key for evaluate/stream requests
11
11
  # @param timeout [Numeric] HTTP timeout in seconds
12
12
  # @param cache_ttl [Integer] Cache TTL in seconds
13
- # @param fallback_mode [Symbol] :fail_closed or :fail_open
14
13
  # @param retry_count [Integer] Number of retry attempts
15
14
  # @param base_url [String, nil] Override default base URL (optional)
16
15
  def initialize(
@@ -18,7 +17,6 @@ module Togul
18
17
  api_key: '',
19
18
  timeout: 5,
20
19
  cache_ttl: 30,
21
- fallback_mode: :fail_closed,
22
20
  retry_count: 2,
23
21
  base_url: nil
24
22
  )
@@ -27,7 +25,6 @@ module Togul
27
25
  @environment = environment
28
26
  @timeout = timeout
29
27
  @cache_ttl = cache_ttl
30
- @fallback_mode = fallback_mode
31
28
  @retry_count = retry_count
32
29
  end
33
30
  end
@@ -2,45 +2,18 @@
2
2
 
3
3
  module Togul
4
4
  class EvaluateResult
5
- attr_reader :flag_key, :enabled, :value_type, :reason
5
+ attr_reader :flag_key, :enabled, :value_type, :value, :reason
6
6
 
7
- def initialize(flag_key:, enabled:, value_type:, raw_value:, reason:)
7
+ def initialize(flag_key:, enabled:, value_type:, value:, reason:)
8
8
  @flag_key = flag_key
9
9
  @enabled = enabled
10
10
  @value_type = value_type
11
- @raw_value = raw_value
11
+ @value = value
12
12
  @reason = reason
13
13
  end
14
14
 
15
15
  def enabled?
16
16
  @enabled == true
17
17
  end
18
-
19
- def bool_value(fallback = false)
20
- return fallback unless enabled? && @value_type == 'boolean'
21
- return fallback unless @raw_value == true || @raw_value == false
22
-
23
- @raw_value
24
- end
25
-
26
- def string_value(fallback = '')
27
- return fallback unless enabled? && @value_type == 'string'
28
- return fallback unless @raw_value.is_a?(String)
29
-
30
- @raw_value
31
- end
32
-
33
- def number_value(fallback = 0.0)
34
- return fallback unless enabled? && @value_type == 'number'
35
- return fallback unless @raw_value.is_a?(Numeric)
36
-
37
- @raw_value.to_f
38
- end
39
-
40
- def json_value(fallback = nil)
41
- return fallback unless enabled? && @value_type == 'json'
42
-
43
- @raw_value.nil? ? fallback : @raw_value
44
- end
45
18
  end
46
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: togul
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Togul
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-05-07 00:00:00.000000000 Z
11
+ date: 2026-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json