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.
19 20 21 22 |
# File 'lib/jsonapi/compiled_json.rb', line 19 def initialize(json, h = nil) @json = json @h = h end |
Class Method Details
.compile(h) ⇒ Object
3 4 5 |
# File 'lib/jsonapi/compiled_json.rb', line 3 def self.compile(h) new(JSON.generate(h), h) end |
.of(obj) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# 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 |
Instance Method Details
#[](key) ⇒ Object
:nocov:
38 39 40 41 42 |
# File 'lib/jsonapi/compiled_json.rb', line 38 def [](key) # :nocov: to_h[key] # :nocov: end |
#to_h ⇒ Object
:nocov:
33 34 35 |
# File 'lib/jsonapi/compiled_json.rb', line 33 def to_h @h ||= JSON.parse(@json) end |
#to_json(*_args) ⇒ Object
24 25 26 |
# File 'lib/jsonapi/compiled_json.rb', line 24 def to_json(*_args) @json end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/jsonapi/compiled_json.rb', line 28 def to_s @json end |