Module: Jade::Decode::Runner
Instance Method Summary collapse
- #from_json(decoder, json_string) ⇒ Object
- #run(decoder, value) ⇒ Object
-
#run!(decoder, value) ⇒ Object
The decoded value or a raise — no Result for the caller to unwrap.
Instance Method Details
#from_json(decoder, json_string) ⇒ Object
402 403 404 405 406 407 408 409 |
# File 'lib/jade/decode.rb', line 402 def from_json(decoder, json_string) begin parsed = JSON.parse(json_string) rescue JSON::ParserError => e return Jade::Result::Err[Jade::Decode::WrongType['valid JSON', e.]] end run(decoder, parsed) end |
#run(decoder, value) ⇒ Object
411 412 413 414 415 |
# File 'lib/jade/decode.rb', line 411 def run(decoder, value) decoded = decoder.desc.decode(value) Failure === decoded ? Jade::Result::Err[decoded.error] : Jade::Result::Ok[decoded] end |
#run!(decoder, value) ⇒ Object
The decoded value or a raise — no Result for the caller to unwrap.
418 419 420 421 422 |
# File 'lib/jade/decode.rb', line 418 def run!(decoder, value) decoded = decoder.desc.decode(value) Failure === decoded ? yield(decoded.error) : decoded end |