Class: Typelizer::SerializerConfigLayer
- Inherits:
-
Object
- Object
- Typelizer::SerializerConfigLayer
- Defined in:
- lib/typelizer/serializer_config_layer.rb
Overview
SerializerConfigLayer
Lightweight, validated container for per-serializer overrides defined via the DSL.
-
Backed by a plain Hash for cheap deep-merge later (see WriterContext).
-
Only keys from Config.members are allowed; unknown keys raise NoMethodError.
-
Supports flat setters/getters in the DSL (e.g., c.null_strategy = :nullable_and_optional).
-
Mutable only via the DSL; #to_h returns a frozen hash to prevent external mutation.
Rationale: we don’t allocate another Config here; this layer is merged on top of library/global/writer settings when computing the effective config.
Constant Summary collapse
- VALID_KEYS =
Config.members.to_set
Instance Method Summary collapse
-
#initialize(target_hash) ⇒ SerializerConfigLayer
constructor
A new instance of SerializerConfigLayer.
- #to_h ⇒ Object
Constructor Details
#initialize(target_hash) ⇒ SerializerConfigLayer
Returns a new instance of SerializerConfigLayer.
18 19 20 |
# File 'lib/typelizer/serializer_config_layer.rb', line 18 def initialize(target_hash) @target_hash = target_hash end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object (private)
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/typelizer/serializer_config_layer.rb', line 28 def method_missing(name, *args) name = name.to_s key = name.chomp("=").to_sym raise NoMethodError, "Unknown configuration key: '#{key}'" unless VALID_KEYS.include?(key) return @target_hash[key] = args.first if name.end_with?("=") && args.length == 1 return @target_hash[key] if args.empty? super end |
Instance Method Details
#to_h ⇒ Object
22 23 24 |
# File 'lib/typelizer/serializer_config_layer.rb', line 22 def to_h @target_hash.dup.freeze end |