togglecraft 1.0.0 → 1.0.1

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: 6e77c8218c124ce83fbdc25f2f2975f50ca69fde64b3109116e639580ac5be42
4
- data.tar.gz: 872451734b10596e4b11337275454a998605a7966ff7e9f5d575c4764ff2a89e
3
+ metadata.gz: ffa98d6abdac97120d6cdfd774cd8da1e99fd1b88e2bfb2f978a500c50388f4e
4
+ data.tar.gz: 5fcf387b554e526d25bc28c430650b5ee3849c1eff0523b11117fd570959a7eb
5
5
  SHA512:
6
- metadata.gz: 3353a6384c9c2ab564c5244f0c015a723c403287213e6fa6542c0b8cbfbb49bf804d303f3c1d51510c1a07858884b2626a0128a05744d2d0a7e394ad6f1f43b0
7
- data.tar.gz: 6a31210c7fb15839f8b5bbb2b85b37c13129f00ea26a57796d885331a5cf981e6c4eefaf7ad69fdd882a05a29acb2b9175321784892a750d087ef9deba4c4e96
6
+ metadata.gz: f07746457dfdd5ecd50882359a8ffad9e107ee4f90ff21a599dc815794b7fb3a21b0a9245b4f5f4c64bc010afc6467856f52503b5318a31661deae4ac8c0a22f
7
+ data.tar.gz: 1e00cbc1d6be11cc76186de12a926d4a23338ff5818a44ee5b86ecb24bcbda6ea2771a9fe485dada25362584a727b8d03d859cd482f4e2df5d63407ed9802abb
@@ -18,12 +18,13 @@ module ToggleCraft
18
18
  end
19
19
 
20
20
  # Evaluate a boolean flag
21
- # @param flag_key [String] The flag key
21
+ # @param flag_key [String, Symbol] The flag key
22
22
  # @param context [Hash] The evaluation context
23
23
  # @param default_value [Boolean] Default value if flag not found
24
24
  # @return [Boolean]
25
25
  def evaluate_boolean(flag_key, context = {}, default_value = false)
26
- flag = @flags[flag_key]
26
+ # Normalize key to symbol for lookup (flags are stored with symbol keys)
27
+ flag = @flags[flag_key.to_sym]
27
28
 
28
29
  # Flag doesn't exist
29
30
  return default_value unless flag
@@ -56,7 +57,8 @@ module ToggleCraft
56
57
  # @param default_variant [String, nil] Default variant if flag not found
57
58
  # @return [String, nil]
58
59
  def evaluate_multivariate(flag_key, context = {}, default_variant = nil)
59
- flag = @flags[flag_key]
60
+ # Normalize key to symbol for lookup (flags are stored with symbol keys)
61
+ flag = @flags[flag_key.to_sym]
60
62
 
61
63
  # Flag doesn't exist
62
64
  return default_variant unless flag
@@ -88,12 +90,13 @@ module ToggleCraft
88
90
  end
89
91
 
90
92
  # Evaluate a percentage rollout flag
91
- # @param flag_key [String] The flag key
93
+ # @param flag_key [String, Symbol] The flag key
92
94
  # @param context [Hash] The evaluation context
93
95
  # @param default_value [Boolean] Default value if flag not found
94
96
  # @return [Boolean]
95
97
  def evaluate_percentage(flag_key, context = {}, default_value = false)
96
- flag = @flags[flag_key]
98
+ # Normalize key to symbol for lookup (flags are stored with symbol keys)
99
+ flag = @flags[flag_key.to_sym]
97
100
 
98
101
  # Flag doesn't exist
99
102
  return default_value unless flag
@@ -158,10 +161,11 @@ module ToggleCraft
158
161
  end
159
162
 
160
163
  # Get the current percentage value of a flag
161
- # @param flag_key [String] The flag key
164
+ # @param flag_key [String, Symbol] The flag key
162
165
  # @return [Integer, nil]
163
166
  def percentage(flag_key)
164
- flag = @flags[flag_key]
167
+ # Normalize key to symbol for lookup (flags are stored with symbol keys)
168
+ flag = @flags[flag_key.to_sym]
165
169
 
166
170
  return nil unless flag && flag[:type] == 'percentage'
167
171
 
@@ -252,7 +256,8 @@ module ToggleCraft
252
256
  # @param flag_key [String] The flag key
253
257
  # @return [Boolean]
254
258
  def has_flag?(flag_key)
255
- @flags.key?(flag_key)
259
+ # Normalize key to symbol for lookup (flags are stored with symbol keys)
260
+ @flags.key?(flag_key.to_sym)
256
261
  end
257
262
 
258
263
  # Get all flag keys
@@ -262,10 +267,11 @@ module ToggleCraft
262
267
  end
263
268
 
264
269
  # Get flag metadata
265
- # @param flag_key [String] The flag key
270
+ # @param flag_key [String, Symbol] The flag key
266
271
  # @return [Hash, nil]
267
272
  def flag_metadata(flag_key)
268
- flag = @flags[flag_key]
273
+ # Normalize key to symbol for lookup (flags are stored with symbol keys)
274
+ flag = @flags[flag_key.to_sym]
269
275
  return nil unless flag
270
276
 
271
277
  metadata = {
@@ -285,12 +291,13 @@ module ToggleCraft
285
291
  end
286
292
 
287
293
  # Evaluate any flag type
288
- # @param flag_key [String] The flag key
294
+ # @param flag_key [String, Symbol] The flag key
289
295
  # @param context [Hash] The evaluation context
290
296
  # @param default_value [Object] Default value
291
297
  # @return [Object]
292
298
  def evaluate(flag_key, context = {}, default_value = false)
293
- flag = @flags[flag_key]
299
+ # Normalize key to symbol for lookup (flags are stored with symbol keys)
300
+ flag = @flags[flag_key.to_sym]
294
301
  return default_value unless flag
295
302
 
296
303
  case flag[:type]
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'cgi'
3
4
  require 'http'
4
5
  require 'json'
5
6
 
@@ -111,24 +112,30 @@ module ToggleCraft
111
112
  sse_url = "#{@url}/events?identifier=#{CGI.escape(channel_identifier)}"
112
113
  log "Connecting to #{sse_url}"
113
114
 
114
- HTTP.get(sse_url) do |response|
115
- raise "HTTP #{response.status}: #{response.status.reason}" unless response.status.success?
115
+ # Don't use block form - open connection and keep reference
116
+ response = HTTP.timeout(connect: 10, read: 300)
117
+ .headers('Accept' => 'text/event-stream')
118
+ .get(sse_url)
116
119
 
117
- @connected = true
118
- @reconnect_attempts = 0
119
- @on_connect.call
120
- start_heartbeat
120
+ raise "HTTP #{response.status}: #{response.status.reason}" unless response.status.success?
121
121
 
122
- # Read SSE stream
123
- buffer = ''
124
- response.body.each do |chunk|
125
- buffer += chunk
122
+ @connected = true
123
+ @reconnect_attempts = 0
124
+ @on_connect.call
125
+ start_heartbeat
126
+
127
+ # Read SSE stream using readpartial (body.each doesn't work properly)
128
+ buffer = ''
129
+ loop do
130
+ chunk = response.body.readpartial
131
+ break unless chunk # Connection closed
132
+
133
+ buffer += chunk
126
134
 
127
- # Process complete SSE messages (ending with \n\n)
128
- while buffer.include?("\n\n")
129
- message, buffer = buffer.split("\n\n", 2)
130
- process_sse_message(message)
131
- end
135
+ # Process complete SSE messages (ending with \n\n)
136
+ while buffer.include?("\n\n")
137
+ message, buffer = buffer.split("\n\n", 2)
138
+ process_sse_message(message)
132
139
  end
133
140
  end
134
141
  rescue StandardError => e
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ToggleCraft
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: togglecraft
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ToggleCraft