Module: Jade::Interop::Boundary
Instance Method Summary collapse
-
#array(label, v) ⇒ Object
Validates that v is an Array but doesn’t check element types — used when the per-element decoder isn’t a simple ‘is_a?` (e.g. nested structs).
- #bool(label, v) ⇒ Object
-
#decode_or_raise(decoder, value) ⇒ Object
Boundary-side decode: succeed → return the value, fail → raise.
- #float(label, v) ⇒ Object
- #hash(label, v) ⇒ Object
-
#integer(label, v) ⇒ Object
Specialized fast-path validators.
- #list_of(klass, label, v) ⇒ Object
- #string(label, v) ⇒ Object
- #type_error!(label, v) ⇒ Object
Instance Method Details
#array(label, v) ⇒ Object
Validates that v is an Array but doesn’t check element types — used when the per-element decoder isn’t a simple ‘is_a?` (e.g. nested structs). The caller maps a decoder over the result.
48 49 50 |
# File 'lib/jade/interop/boundary.rb', line 48 def array(label, v) v.is_a?(::Array) ? v : type_error!(label, v) end |
#bool(label, v) ⇒ Object
33 34 35 |
# File 'lib/jade/interop/boundary.rb', line 33 def bool(label, v) v == true || v == false ? v : type_error!(label, v) end |
#decode_or_raise(decoder, value) ⇒ Object
Boundary-side decode: succeed → return the value, fail → raise. The Result wrap/unwrap that user-level Decode.from_value uses is dead weight at the boundary because failure always raises anyway. Skipping it removes one allocation per arg per Ruby→Jade call.
14 15 16 17 18 19 |
# File 'lib/jade/interop/boundary.rb', line 14 def decode_or_raise(decoder, value) case Jade::Decode::Runner.run(decoder, value) in Jade::Result::Ok[v] then v in Jade::Result::Err[e] then raise Jade::Interop::DecodeError.new(e, value) end end |
#float(label, v) ⇒ Object
37 38 39 |
# File 'lib/jade/interop/boundary.rb', line 37 def float(label, v) ::Numeric === v ? v.to_f : type_error!(label, v) end |
#hash(label, v) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/jade/interop/boundary.rb', line 52 def hash(label, v) case v when ::Hash then v when ::Data then v.to_h.transform_keys(&:to_s) else type_error!(label, v) end end |
#integer(label, v) ⇒ Object
Specialized fast-path validators. Emitted by codegen for known-shape argument types in place of the generic ‘decode_or_raise` path —avoids constructing a Decoder descriptor and walking the interpreter for primitives.
25 26 27 |
# File 'lib/jade/interop/boundary.rb', line 25 def integer(label, v) ::Integer === v ? v : type_error!(label, v) end |
#list_of(klass, label, v) ⇒ Object
41 42 43 |
# File 'lib/jade/interop/boundary.rb', line 41 def list_of(klass, label, v) v.is_a?(::Array) && v.all? { klass === _1 } ? v : type_error!(label, v) end |
#string(label, v) ⇒ Object
29 30 31 |
# File 'lib/jade/interop/boundary.rb', line 29 def string(label, v) ::String === v ? v.dup : type_error!(label, v) end |