Module: Hobby::JSON
- Defined in:
- lib/hobby/json.rb
Defined Under Namespace
Classes: Response
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(app) ⇒ Object
6 7 8 9 |
# File 'lib/hobby/json.rb', line 6 def self.included app app.use Rack::ContentType, 'application/json' app.response = Response end |
Instance Method Details
#json ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/hobby/json.rb', line 17 def json @json ||= begin fail unless env.fetch('CONTENT_TYPE').start_with? 'application/json' ::JSON.parse request.body.read rescue response.status = 400 halt end end |