class JSONAPI::CompiledJson

Public Class Methods

compile(h) click to toggle source
# File lib/jsonapi/compiled_json.rb, line 3
def self.compile(h)
  new(JSON.generate(h), h)
end
new(json, h = nil) click to toggle source
# File lib/jsonapi/compiled_json.rb, line 19
def initialize(json, h = nil)
  @json = json
  @h = h
end
of(obj) click to toggle source
# File lib/jsonapi/compiled_json.rb, line 7
def self.of(obj)
  # :nocov:
  case obj
    when NilClass then nil
    when CompiledJson then obj
    when String then CompiledJson.new(obj)
    when Hash then CompiledJson.compile(obj)
    else raise "Can't figure out how to turn #{obj.inspect} into CompiledJson"
  end
  # :nocov:
end

Public Instance Methods

[](key) click to toggle source

:nocov:

# File lib/jsonapi/compiled_json.rb, line 38
def [](key)
  # :nocov:
  to_h[key]
  # :nocov:
end
to_h() click to toggle source

:nocov:

# File lib/jsonapi/compiled_json.rb, line 33
def to_h
  @h ||= JSON.parse(@json)
end
to_json(*_args) click to toggle source
# File lib/jsonapi/compiled_json.rb, line 24
def to_json(*_args)
  @json
end
to_s() click to toggle source
# File lib/jsonapi/compiled_json.rb, line 28
def to_s
  @json
end