Sha256: f4d2d5ded00eb0d0d4be4b6927ea3912872d9941064a584e4befe225908fceb8
Contents?: true
Size: 879 Bytes
Versions: 7
Compression:
Stored size: 879 Bytes
Contents
require "bundler/setup" require "json" require 'blood_contracts/core' require "pry" module Types class JSON < BC::Refined def match super do begin context[:parsed] = ::JSON.parse(unpack_refined(@value)) self rescue StandardError => error failure(error) end end end def unpack super { |match| match.context[:parsed] } end end class Symbol < BC::Refined def match super do begin context[:as_symbol] = unpack_refined(@value).to_sym self rescue StandardError => error failure(error) end end end def unpack super { |match| match.context[:as_symbol] } end end end Config = BC::Tuple.new(Types::Symbol, Types::JSON, names: %i(name config)) c = Config.new("test", '{"some": "value"}') binding.pry
Version data entries
7 entries across 7 versions & 1 rubygems