toggly 1.1.0 → 1.2.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: d728557cdb56574a22377e85047ec649a801532f9cea3574ae66ccba703e320e
4
- data.tar.gz: 5054b15ad5ad1b48fde5c6fb174698c701bd8fa38b6054cc8afd6ff015e196ce
3
+ metadata.gz: 810c3cb9858347a1cb79212512e006bf2362ee97cd09c7a528eb334c0bf949cc
4
+ data.tar.gz: 7f6ef5ce376a28c1101ce65c1d82080c02e6b254487ed0908479c1a622adffeb
5
5
  SHA512:
6
- metadata.gz: 8871e715209c606026d37367ec46522c3bbcc7925633f9f511bad51179f141924cb4b7e123978212e1a1697050072d0bfacff0463e53cf02510012cb28531db1
7
- data.tar.gz: c3536488d775b49aeefa375f72f3c6b88a993fb4b6464a19e8c5ae73bde75222c310bc820e563f94039509bd6dbbc698ddb04c33cd89de6beba2e7c1ac29dd56
6
+ metadata.gz: e0c8fbd59c7cfa8baafd73f580da168fe0fe4114e802f0e55bec3c406994e8a4a169b773dbf6e97862f831157d7b011df18f6210cda33740a56a6f515c05fcfc
7
+ data.tar.gz: 92d791902d6bf591f9731647caa1963b2c589bf12255afe376b1f1fa9591437d9af10388503b54bbbf06e911afb41fb2b557be60c9564dd09eec423037fcbdab
data/CHANGELOG.md CHANGED
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.2.0] - 2026-09-24
9
+
10
+ ### Added
11
+
12
+ - Soft-typed `get_variant_value(feature, as: Klass)` (and optional block form).
13
+ Missing assignment or bind failure returns `nil` — never raises solely for
14
+ shape mismatch. Untyped `get_variant_value` (no `as:`) is unchanged
15
+ [OPS-1365].
16
+
8
17
  ## [1.1.0] - 2026-09-23
9
18
 
10
19
  ### Added
data/lib/toggly/client.rb CHANGED
@@ -166,8 +166,13 @@ module Toggly
166
166
  # @param feature_key [String, Symbol] The feature key
167
167
  # @param context [Context, nil] Optional targeting context (userId + groups)
168
168
  # @return [Object, nil]
169
- def get_variant_value(feature_key, context: nil)
170
- get_variant(feature_key, context: context)&.configuration_value
169
+ def get_variant_value(feature_key, context: nil, as: nil, &block)
170
+ value = get_variant(feature_key, context: context)&.configuration_value
171
+ return value if as.nil? && !block
172
+
173
+ return nil if value.nil?
174
+
175
+ decode_variant_configuration(value, as, &block)
171
176
  end
172
177
 
173
178
  # Default targeting userId used by {#get_variant} / {#get_variant_value}
@@ -350,6 +355,34 @@ module Toggly
350
355
 
351
356
  private
352
357
 
358
+ def decode_variant_configuration(value, as, &block)
359
+ return block.call(value) if block
360
+ return nil if as.nil?
361
+
362
+ # Scalars / :boolean before Class#new — String.new({}) would soft-fail to "".
363
+ if as == String
364
+ return value.is_a?(String) ? value : nil
365
+ end
366
+ if as == Integer
367
+ return value.is_a?(Integer) && !value.is_a?(TrueClass) && !value.is_a?(FalseClass) ? value : nil
368
+ end
369
+ if as == Float
370
+ return value.is_a?(Numeric) && !value.is_a?(TrueClass) && !value.is_a?(FalseClass) ? value.to_f : nil
371
+ end
372
+ if [TrueClass, FalseClass, :boolean].include?(as)
373
+ return [true, false].include?(value) ? value : nil
374
+ end
375
+
376
+ # is_a? requires a Module; symbols like :boolean are handled above.
377
+ return value if as.is_a?(Module) && value.is_a?(as)
378
+ return as.new(**value.transform_keys(&:to_sym)) if as.respond_to?(:new) && value.is_a?(Hash)
379
+ return as.json_create(value) if as.respond_to?(:json_create) && value.is_a?(Hash)
380
+
381
+ nil
382
+ rescue StandardError
383
+ nil
384
+ end
385
+
353
386
  # `definitions` / `definitions-signed` → local rule eval. The sole
354
387
  # source of truth for `enabled?`; also carries `variants` / `allocation`
355
388
  # for the catalog-local `get_variant` assignment.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Toggly
4
- VERSION = "1.1.0"
4
+ VERSION = "1.2.0"
5
5
  end
data/lib/toggly.rb CHANGED
@@ -123,10 +123,10 @@ module Toggly
123
123
  # @param feature_key [String, Symbol]
124
124
  # @param context [Context, nil]
125
125
  # @return [Object, nil]
126
- def get_variant_value(feature_key, context: nil)
126
+ def get_variant_value(feature_key, context: nil, as: nil, &)
127
127
  raise Error, "Toggly not configured. Call Toggly.configure first." unless @client
128
128
 
129
- @client.get_variant_value(feature_key, context: context)
129
+ @client.get_variant_value(feature_key, context: context, as: as, &)
130
130
  end
131
131
 
132
132
  # Reset the global client (mainly for testing)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toggly
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ops.ai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-09-24 00:00:00.000000000 Z
11
+ date: 2026-09-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: High-performance Ruby SDK for Toggly feature flag management. Works with
14
14
  or without Toggly.io.