Module: Iord::Json
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/iord/json.rb
Instance Method Summary collapse
- #iordh ⇒ Object
- #json_create(hsh) ⇒ Object
- #json_destroy(hsh) ⇒ Object
- #json_index(hsh) ⇒ Object
- #json_index_attrs ⇒ Object
- #json_show(hsh) ⇒ Object
- #json_show_attrs ⇒ Object
- #json_update(hsh) ⇒ Object
Instance Method Details
#iordh ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/iord/json.rb', line 21 def iordh if request.format.symbol == :json @json_output ||= ::Iord::JsonOutput.new(view_context) else super end end |
#json_create(hsh) ⇒ Object
53 54 55 |
# File 'lib/iord/json.rb', line 53 def json_create(hsh) {status: hsh[:created] ? :created : :unprocessable_entity}.merge json_show(hsh) end |
#json_destroy(hsh) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/iord/json.rb', line 61 def json_destroy(hsh) { json: {status: hsh[:destroyed] ? "ok" : "error"}, status: hsh[:destroyed] ? :ok : :unprocessable_entity } end |
#json_index(hsh) ⇒ Object
41 42 43 44 45 |
# File 'lib/iord/json.rb', line 41 def json_index(hsh) attrs = json_index_attrs attrs.unshift(:id) unless attrs.include? :id {json: iordh.display_array(@collection, attrs)} end |
#json_index_attrs ⇒ Object
29 30 31 32 33 |
# File 'lib/iord/json.rb', line 29 def json_index_attrs self.respond_to?(:json_attrs) ? json_attrs : index_attrs end |
#json_show(hsh) ⇒ Object
47 48 49 50 51 |
# File 'lib/iord/json.rb', line 47 def json_show(hsh) attrs = json_show_attrs attrs.unshift(:id) unless attrs.include? :id {json: iordh.display(@resource, attrs)} end |
#json_show_attrs ⇒ Object
35 36 37 38 39 |
# File 'lib/iord/json.rb', line 35 def json_show_attrs self.respond_to?(:json_attrs) ? json_attrs : show_attrs end |
#json_update(hsh) ⇒ Object
57 58 59 |
# File 'lib/iord/json.rb', line 57 def json_update(hsh) {status: hsh[:updated] ? :accepted : :unprocessable_entity}.merge json_show(hsh) end |