Sha256: 446dbf1bd916f02e171983b6c71bdfd41198f58ce28458272f439bf869a73b61
Contents?: true
Size: 480 Bytes
Versions: 5
Compression:
Stored size: 480 Bytes
Contents
# frozen_string_literal: true require "json" module InferModel class Parsers::JSON extend Callable extend Dry::Initializer param :value option :allow_blank, default: -> { true } def call raise Parsers::Error, "value was blank which is not allowed" if value.nil? && !allow_blank return if value.nil? || value.empty? JSON.parse(value) rescue JSON::ParserError raise Parsers::Error, "'#{value}' is not a JSON" end end end
Version data entries
5 entries across 5 versions & 1 rubygems