Class: Weft::Resolver
- Inherits:
-
Object
- Object
- Weft::Resolver
- Defined in:
- lib/weft/resolver.rb
Overview
Projects a wire params hash (string or symbol keys) onto a component class's declared schema, coercing values with declared types. Components self-resolve at build time (see DSL::Params); the Router also calls this directly for error-path bookkeeping. Future home of the reification step (wire primitives → rich objects).
Constant Summary collapse
- TYPES =
The declarable wire types, each self-describing: how to coerce a present wire value (permissive Ruby — never raises on malformed input), and the classes a declared default may already be an instance of (declaration-side validation lives in DSL::Params). Self-description is the seam a future registration API extends.
{ string: { coerce: :to_s.to_proc, classes: [String] }, integer: { coerce: :to_i.to_proc, classes: [Integer] }, float: { coerce: :to_f.to_proc, classes: [Float] }, boolean: { coerce: ->(v) { [true, "true", "1"].include?(v) }, classes: [TrueClass, FalseClass] }, decimal: { coerce: :to_d.to_proc, classes: [BigDecimal] } }.freeze
Class Method Summary collapse
- .resolve(component_class, params) ⇒ Object
-
.resolve_present(component_class, params) ⇒ Object
Coerce only the keys actually present on the wire — no default fill.
Class Method Details
.resolve(component_class, params) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/weft/resolver.rb', line 27 def resolve(component_class, params) component_class.params.each_with_object({}) do |(name, ), result| raw = fetch_raw(params, name) result[name] = raw.nil? ? [:default] : coerce(raw, [:type]) end end |
.resolve_present(component_class, params) ⇒ Object
Coerce only the keys actually present on the wire — no default fill. The construction-time source stack uses this to tell wire-satisfied keys apart from keys that fall through to lower sources.
37 38 39 40 41 42 |
# File 'lib/weft/resolver.rb', line 37 def resolve_present(component_class, params) component_class.params.each_with_object({}) do |(name, ), result| raw = fetch_raw(params, name) result[name] = coerce(raw, [:type]) unless raw.nil? end end |