Class: Raw::JSONFormat
- Defined in:
- lib/raw/dispatcher/format/json.rb
Instance Attribute Summary
Attributes inherited from Format
#content_type, #extension, #name, #template_extension
Instance Method Summary collapse
- #after_action(controller, context) ⇒ Object
-
#initialize ⇒ JSONFormat
constructor
A new instance of JSONFormat.
Methods inherited from Format
#before_action, #filter_template, #to_s
Constructor Details
#initialize ⇒ JSONFormat
Returns a new instance of JSONFormat.
9 10 11 12 13 14 |
# File 'lib/raw/dispatcher/format/json.rb', line 9 def initialize @name = "json" @content_type = "application/json" @extension = "json" @template_extension = "jsonx" end |
Instance Method Details
#after_action(controller, context) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/raw/dispatcher/format/json.rb', line 16 def after_action(controller, context) if controller.out.blank? if model = controller.class.ann(:self, :model) resource = model.to_s.demodulize.underscore if collection = controller.instance_variable_get("@#{resource.plural}") controller.send(:print, collection.to_json) elsif resource = controller.instance_variable_get("@#{resource}") controller.send(:print, resource.to_json) end end end end |