Class: Jaql::JSONString
- Inherits:
-
Object
- Object
- Jaql::JSONString
- Defined in:
- lib/jaql/json_string.rb
Instance Method Summary collapse
-
#initialize(json) ⇒ JSONString
constructor
A new instance of JSONString.
-
#to_json(*args) ⇒ Object
specifying :json format makes Rails and Grape call #to_json on any object it gets back, including JSON strings, so we just wrap the json in a JSONString that returns it when to_json is called NB: this method ignores all args and returns the wrapped string as-is.
- #to_s ⇒ Object
- #to_str ⇒ Object
Constructor Details
#initialize(json) ⇒ JSONString
Returns a new instance of JSONString.
5 6 7 8 |
# File 'lib/jaql/json_string.rb', line 5 def initialize(json) raise "#[self.class} initialized with a #{json.class}" unless json.is_a?(String) @json = json end |
Instance Method Details
#to_json(*args) ⇒ Object
specifying :json format makes Rails and Grape call #to_json on any object it gets back, including JSON strings, so we just wrap the json in a JSONString that returns it when to_json is called NB: this method ignores all args and returns the wrapped string as-is
13 14 15 |
# File 'lib/jaql/json_string.rb', line 13 def to_json(*args) @json end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/jaql/json_string.rb', line 21 def to_s @json end |
#to_str ⇒ Object
17 18 19 |
# File 'lib/jaql/json_string.rb', line 17 def to_str @json end |