Class: Jaql::JSONString

Inherits:
Object
  • Object
show all
Defined in:
lib/jaql/json_string.rb

Instance Method Summary collapse

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_sObject



21
22
23
# File 'lib/jaql/json_string.rb', line 21

def to_s
  @json
end

#to_strObject



17
18
19
# File 'lib/jaql/json_string.rb', line 17

def to_str
  @json
end