Class: Moon::Response::JSON

Inherits:
Base
  • Object
show all
Defined in:
lib/moon/response/json.rb

Overview

Moon::Response::JSON is the base class for all json responses.

Direct Known Subclasses

Blank, Collection, Message, Model, ValidationErrors

Defined Under Namespace

Classes: Blank, Collection, Message, Model, ValidationErrors

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, hash = { }) ⇒ JSON

Returns a new instance of JSON.



15
16
17
# File 'lib/moon/response/json.rb', line 15

def initialize(status, hash = { })
  @status, @hash = status, hash
end

Instance Attribute Details

#hashObject

Returns the value of attribute hash.



13
14
15
# File 'lib/moon/response/json.rb', line 13

def hash
  @hash
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

Instance Method Details

#bodyObject



23
24
25
# File 'lib/moon/response/json.rb', line 23

def body
  ::JSON.generate hash
end

#headersObject



19
20
21
# File 'lib/moon/response/json.rb', line 19

def headers
  { "Content-Type" => "application/json" }
end