Module: SoarSc::Web::Views::JSON

Defined in:
lib/soar_sc_views/json.rb

Class Method Summary collapse

Class Method Details

.errorObject



16
17
18
19
# File 'lib/soar_sc_views/json.rb', line 16

def self.error
  body = ex.message
  [500, {"Content-Type" => "application/json"}, [::JSON.generate(body)]]
end

.is_json?(data) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
# File 'lib/soar_sc_views/json.rb', line 21

def self.is_json?(data)
  begin
    ::JSON.parse(data)
    return true
  rescue => ex
    return false
  end
end

.not_foundObject



12
13
14
# File 'lib/soar_sc_views/json.rb', line 12

def self.not_found
  [404, {}, []]
end

.render(http_code, body) ⇒ Object



7
8
9
10
# File 'lib/soar_sc_views/json.rb', line 7

def self.render(http_code, body)
  data = SoarSc::Web::Views::JSON::is_json?(body) ? body : ::JSON.generate(body)
  [http_code, {"Content-Type" => "application/json"}, [data]]
end