Class: JSONAPI::ResourceController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- JSONAPI::ResourceController
- Defined in:
- lib/jsonapi/resource_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #create_association ⇒ Object
-
#create_operations_processor ⇒ Object
Override this to use another operations processor.
- #destroy ⇒ Object
- #destroy_association ⇒ Object
- #get_related_resource ⇒ Object
- #get_related_resources ⇒ Object
- #index ⇒ Object
- #show ⇒ Object
- #show_association ⇒ Object
- #update ⇒ Object
- #update_association ⇒ Object
Instance Method Details
#create ⇒ Object
72 73 74 |
# File 'lib/jsonapi/resource_controller.rb', line 72 def create process_request_operations end |
#create_association ⇒ Object
76 77 78 |
# File 'lib/jsonapi/resource_controller.rb', line 76 def create_association process_request_operations end |
#create_operations_processor ⇒ Object
Override this to use another operations processor
132 133 134 |
# File 'lib/jsonapi/resource_controller.rb', line 132 def create_operations_processor JSONAPI::ActiveRecordOperationsProcessor.new end |
#destroy ⇒ Object
88 89 90 |
# File 'lib/jsonapi/resource_controller.rb', line 88 def destroy process_request_operations end |
#destroy_association ⇒ Object
92 93 94 |
# File 'lib/jsonapi/resource_controller.rb', line 92 def destroy_association process_request_operations end |
#get_related_resource ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/jsonapi/resource_controller.rb', line 96 def association_type = params[:association] source_resource = @request.source_klass.find_by_key(@request.source_id, context: context) serializer = JSONAPI::ResourceSerializer.new(@request.source_klass, include: @request.include, fields: @request.fields, base_url: base_url, key_formatter: key_formatter, route_formatter: route_formatter) render json: serializer.serialize_to_hash(source_resource.send(association_type)) end |
#get_related_resources ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/jsonapi/resource_controller.rb', line 110 def association_type = params[:association] source_resource = @request.source_klass.find_by_key(@request.source_id, context: context) = source_resource.send(association_type, { filters: @request.source_klass.verify_filters(@request.filters, context), sort_criteria: @request.sort_criteria, paginator: @request.paginator }) serializer = JSONAPI::ResourceSerializer.new(@request.source_klass, include: @request.include, fields: @request.fields, base_url: base_url, key_formatter: key_formatter, route_formatter: route_formatter) render json: serializer.serialize_to_hash() end |
#index ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/jsonapi/resource_controller.rb', line 17 def index serializer = JSONAPI::ResourceSerializer.new(resource_klass, include: @request.include, fields: @request.fields, base_url: base_url, key_formatter: key_formatter, route_formatter: route_formatter) resource_records = resource_klass.find(resource_klass.verify_filters(@request.filters, context), context: context, sort_criteria: @request.sort_criteria, paginator: @request.paginator) render json: serializer.serialize_to_hash(resource_records) rescue => e handle_exceptions(e) end |
#show ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/jsonapi/resource_controller.rb', line 35 def show serializer = JSONAPI::ResourceSerializer.new(resource_klass, include: @request.include, fields: @request.fields, base_url: base_url, key_formatter: key_formatter, route_formatter: route_formatter) key = resource_klass.verify_key(params[resource_klass._primary_key], context) resource_record = resource_klass.find_by_key(key, context: context) render json: serializer.serialize_to_hash(resource_record) rescue => e handle_exceptions(e) end |
#show_association ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/jsonapi/resource_controller.rb', line 52 def show_association association_type = params[:association] parent_key = resource_klass.verify_key(params[resource_klass._as_parent_key], context) parent_resource = resource_klass.find_by_key(parent_key, context: context) association = resource_klass._association(association_type) serializer = JSONAPI::ResourceSerializer.new(resource_klass, fields: @request.fields, base_url: base_url, key_formatter: key_formatter, route_formatter: route_formatter) render json: serializer.serialize_to_links_hash(parent_resource, association) rescue => e handle_exceptions(e) end |
#update ⇒ Object
84 85 86 |
# File 'lib/jsonapi/resource_controller.rb', line 84 def update process_request_operations end |
#update_association ⇒ Object
80 81 82 |
# File 'lib/jsonapi/resource_controller.rb', line 80 def update_association process_request_operations end |