Class: Code::Object::Json

Inherits:
Code::Object show all
Defined in:
lib/code/object/json.rb

Constant Summary

Constants inherited from Code::Object

NUMBER_CLASSES

Instance Attribute Summary

Attributes inherited from Code::Object

#raw

Class Method Summary collapse

Methods inherited from Code::Object

#<=>, #==, #as_json, as_json, #call, code_and_operator, #code_and_operator, #code_as_json, code_as_json, code_different, #code_different, code_equal_equal, #code_equal_equal, code_equal_equal_equal, #code_equal_equal_equal, code_exclamation_point, #code_exclamation_point, code_exclusive_range, #code_exclusive_range, code_inclusive_range, #code_inclusive_range, code_new, code_or_operator, #code_or_operator, #code_self, code_self, #code_to_json, code_to_json, falsy?, #falsy?, #hash, #initialize, inspect, maybe, #multi_fetch, multi_fetch, nothing?, #nothing?, repeat, sig, #sig, #succ, #to_code, to_json, #to_json, to_s, truthy?, #truthy?, |

Constructor Details

This class inherits a constructor from Code::Object

Class Method Details

.call(**args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/code/object/json.rb', line 6

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

.code_parse(value) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/code/object/json.rb', line 20

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

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