Module: Rerout::InputSerialization Private
- Defined in:
- lib/rerout/input_serialization.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Internal helpers for serializing Smart Link sub-objects (routing rules and A/B variants) accepted by CreateLinkInput / UpdateLinkInput. Each input element may be a Models::RoutingRule / Models::AbVariant value object or a plain Hash; both are coerced to the wire shape.
Class Method Summary collapse
-
.rule_hash(rule) ⇒ Hash
private
String-keyed routing-rule payload.
-
.stringify(hash) ⇒ Object
private
Normalize a Hash to string keys without mutating the caller’s object.
-
.variant_hash(variant) ⇒ Hash
private
String-keyed A/B-variant payload (no server ‘id`).
Class Method Details
.rule_hash(rule) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns string-keyed routing-rule payload.
15 16 17 18 19 20 |
# File 'lib/rerout/input_serialization.rb', line 15 def rule_hash(rule) return rule.to_h if rule.is_a?(Models::RoutingRule) return stringify(rule) if rule.is_a?(Hash) raise ArgumentError, 'routing_rules entries must be Rerout::Models::RoutingRule or Hash' end |
.stringify(hash) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Normalize a Hash to string keys without mutating the caller’s object.
35 36 37 |
# File 'lib/rerout/input_serialization.rb', line 35 def stringify(hash) hash.each_with_object({}) { |(k, v), out| out[k.to_s] = v } end |
.variant_hash(variant) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns string-keyed A/B-variant payload (no server ‘id`).
24 25 26 27 28 29 30 31 32 |
# File 'lib/rerout/input_serialization.rb', line 24 def variant_hash(variant) return variant.to_h if variant.is_a?(Models::AbVariant) raise ArgumentError, 'ab_variants entries must be Rerout::Models::AbVariant or Hash' unless variant.is_a?(Hash) h = stringify(variant) h.delete('id') h['weight'] = 1 unless h.key?('weight') h end |