Sha256: aee5f9d2efd2e30409c809056438b57e0ab088b2cd3eb4a62b4a55942f81bce6

Contents?: true

Size: 638 Bytes

Versions: 5

Compression:

Stored size: 638 Bytes

Contents

# frozen_string_literal: true

class Code
  class Object
    class Json < Object
      def self.call(**args)
        code_operator = args.fetch(:operator, nil).to_code
        code_arguments = args.fetch(:arguments, []).to_code
        code_value = code_arguments.code_first

        case code_operator.to_s
        when "parse"
          sig(args) { String }
          code_parse(code_value)
        else
          super
        end
      end

      def self.code_parse(value)
        code_value = value.to_code

        ::JSON.parse(code_value.raw).to_code
      rescue JSON::ParserError
        Nothing.new
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
code-ruby-1.2.5 lib/code/object/json.rb
code-ruby-1.2.4 lib/code/object/json.rb
code-ruby-1.2.3 lib/code/object/json.rb
code-ruby-1.2.2 lib/code/object/json.rb
code-ruby-1.2.1 lib/code/object/json.rb