Module: JSONAPI::Hanami::Rendering
- Defined in:
- lib/jsonapi/hanami/rendering.rb,
lib/jsonapi/hanami/rendering/dsl.rb
Defined Under Namespace
Modules: DSL
Class Method Summary collapse
Instance Method Summary collapse
- #_jsonapi_error_params ⇒ Object
- #_jsonapi_error_status ⇒ Object
- #_jsonapi_errors ⇒ Object
- #_jsonapi_exposures ⇒ Object
-
#_jsonapi_params ⇒ Object
NOTE(beauby): It might be worth factoring those methods out into a class.
- #_jsonapi_render ⇒ Object
- #_jsonapi_render_error ⇒ Object
- #_jsonapi_render_success ⇒ Object
Class Method Details
Instance Method Details
#_jsonapi_error_params ⇒ Object
57 58 59 |
# File 'lib/jsonapi/hanami/rendering.rb', line 57 def _jsonapi_error_params @_jsonapi end |
#_jsonapi_error_status ⇒ Object
52 53 54 55 |
# File 'lib/jsonapi/hanami/rendering.rb', line 52 def _jsonapi_error_status # TODO(beauby): Set HTTP status code accordingly. 400 end |
#_jsonapi_errors ⇒ Object
61 62 63 64 |
# File 'lib/jsonapi/hanami/rendering.rb', line 61 def _jsonapi_errors # TODO(beauby): Implement inferrence for Hanami::Validations. @_jsonapi[:errors] end |
#_jsonapi_exposures ⇒ Object
39 40 41 |
# File 'lib/jsonapi/hanami/rendering.rb', line 39 def _jsonapi_exposures { routes: routes }.merge!(exposures) end |
#_jsonapi_params ⇒ Object
NOTE(beauby): It might be worth factoring those methods out into a
class.
34 35 36 37 |
# File 'lib/jsonapi/hanami/rendering.rb', line 34 def _jsonapi_params # TODO(beauby): Inject global params (toplevel jsonapi, etc.). @_jsonapi.dup.merge!(expose: _jsonapi_exposures) end |
#_jsonapi_render ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/jsonapi/hanami/rendering.rb', line 17 def _jsonapi_render if @_jsonapi.key?(:errors) _jsonapi_render_error else _jsonapi_render_success end end |
#_jsonapi_render_error ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/jsonapi/hanami/rendering.rb', line 43 def _jsonapi_render_error document = JSONAPI::Serializable::ErrorRenderer.render(@_jsonapi[:errors], _jsonapi_error_params) self.status = _jsonapi_error_status unless @_status self.format = :jsonapi if @format.nil? self.body = document end |
#_jsonapi_render_success ⇒ Object
25 26 27 28 29 30 |
# File 'lib/jsonapi/hanami/rendering.rb', line 25 def _jsonapi_render_success self.format = :jsonapi if @format.nil? return unless @_jsonapi.key?(:data) self.body = JSONAPI::Serializable::Renderer.render(@_jsonapi[:data], _jsonapi_params) end |