Class: InertiaRails::RawJson
- Inherits:
-
Object
- Object
- InertiaRails::RawJson
- Defined in:
- lib/inertia_rails/raw_json.rb
Overview
Wraps a pre-serialized JSON string so it embeds directly into a larger JSON structure without re-serialization.
-
JSON.generate calls #to_json, embedding the raw string.
-
ActiveSupport::JSON.encode calls #as_json first, which returns parsed Ruby data that the encoder re-serializes.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(json_string) ⇒ RawJson
constructor
A new instance of RawJson.
- #to_json ⇒ Object
Constructor Details
#initialize(json_string) ⇒ RawJson
Returns a new instance of RawJson.
11 12 13 |
# File 'lib/inertia_rails/raw_json.rb', line 11 def initialize(json_string) @json_string = json_string end |
Instance Method Details
#as_json ⇒ Object
19 20 21 |
# File 'lib/inertia_rails/raw_json.rb', line 19 def as_json(*) JSON.parse(@json_string) end |
#to_json ⇒ Object
15 16 17 |
# File 'lib/inertia_rails/raw_json.rb', line 15 def to_json(*) @json_string end |