Class: JSONAPI::CompiledJson
- Inherits:
-
Object
- Object
- JSONAPI::CompiledJson
- Defined in:
- lib/jsonapi/compiled_json.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#[](key) ⇒ Object
:nocov:.
-
#initialize(json, h = nil) ⇒ CompiledJson
constructor
A new instance of CompiledJson.
-
#to_h ⇒ Object
:nocov:.
- #to_json(*_args) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(json, h = nil) ⇒ CompiledJson
Returns a new instance of CompiledJson.
21 22 23 24 |
# File 'lib/jsonapi/compiled_json.rb', line 21 def initialize(json, h = nil) @json = json @h = h end |
Class Method Details
.compile(h) ⇒ Object
5 6 7 |
# File 'lib/jsonapi/compiled_json.rb', line 5 def self.compile(h) new(JSON.generate(h), h) end |
.of(obj) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/jsonapi/compiled_json.rb', line 9 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 |
Instance Method Details
#[](key) ⇒ Object
:nocov:
40 41 42 43 44 |
# File 'lib/jsonapi/compiled_json.rb', line 40 def [](key) # :nocov: to_h[key] # :nocov: end |
#to_h ⇒ Object
:nocov:
35 36 37 |
# File 'lib/jsonapi/compiled_json.rb', line 35 def to_h @h ||= JSON.parse(@json) end |
#to_json(*_args) ⇒ Object
26 27 28 |
# File 'lib/jsonapi/compiled_json.rb', line 26 def to_json(*_args) @json end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/jsonapi/compiled_json.rb', line 30 def to_s @json end |