From c9128276b8ea7ae4f074116d78577da0441d3538 Mon Sep 17 00:00:00 2001 From: Larry Gebhardt Date: Wed, 10 Jun 2015 10:37:14 -0400 Subject: [PATCH 1/3] Remove unrequired require statements --- README.md | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/README.md b/README.md index 773934a7f..ff63c843c 100644 --- a/README.md +++ b/README.md @@ -50,8 +50,6 @@ Resources must be derived from `JSONAPI::Resource`, or a class that is itself de For example: ```ruby -require 'jsonapi/resource' - class ContactResource < JSONAPI::Resource end ``` @@ -64,8 +62,6 @@ the `attribute` method, and multiple attributes can be declared with the `attrib For example: ```ruby -require 'jsonapi/resource' - class ContactResource < JSONAPI::Resource attribute :name_first attributes :name_last, :email, :twitter @@ -81,8 +77,6 @@ This allows a resource's methods to access the underlying model. For example, a computed attribute for `full_name` could be defined as such: ```ruby -require 'jsonapi/resource' - class ContactResource < JSONAPI::Resource attributes :name_first, :name_last, :email, :twitter attribute :full_name @@ -127,8 +121,6 @@ the `update` or `create` methods, override the `self.updatable_fields` and `self This example prevents `full_name` from being set: ```ruby -require 'jsonapi/resource' - class ContactResource < JSONAPI::Resource attributes :name_first, :name_last, :full_name @@ -280,8 +272,6 @@ declared using the `filter` method, and multiple filters can be declared with th For example: ```ruby -require 'jsonapi/resource' - class ContactResource < JSONAPI::Resource attributes :name_first, :name_last, :email, :twitter @@ -762,7 +752,6 @@ The `ResourceSerializer` can be used to serialize a resource into JSON API compl method that takes a resource instance or array of resource instances to serialize. For example: ```ruby -require 'jsonapi/resource_serializer' post = Post.find(1) JSONAPI::ResourceSerializer.new(PostResource).serialize_to_hash(PostResource.new(post)) ``` From af72e46eb5bab9e40228ec4ba0fdaae38cb46c0d Mon Sep 17 00:00:00 2001 From: Larry Gebhardt Date: Wed, 10 Jun 2015 10:37:37 -0400 Subject: [PATCH 2/3] Update error codes --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ff63c843c..0ae1130f6 100644 --- a/README.md +++ b/README.md @@ -720,13 +720,14 @@ module JSONAPI KEY_NOT_INCLUDED_IN_URL = 110 INVALID_INCLUDE = 112 RELATION_EXISTS = 113 - INVALID_SORT_PARAM = 114 + INVALID_SORT_CRITERIA = 114 INVALID_LINKS_OBJECT = 115 TYPE_MISMATCH = 116 INVALID_PAGE_OBJECT = 117 INVALID_PAGE_VALUE = 118 INVALID_FIELD_FORMAT = 119 INVALID_FILTERS_SYNTAX = 120 + SAVE_FAILED = 121 FORBIDDEN = 403 RECORD_NOT_FOUND = 404 UNSUPPORTED_MEDIA_TYPE = 415 From fb586f271136849b9328e09fc5424958478182e9 Mon Sep 17 00:00:00 2001 From: Larry Gebhardt Date: Wed, 10 Jun 2015 10:37:49 -0400 Subject: [PATCH 3/3] Default Filters --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 0ae1130f6..9ee9f4911 100644 --- a/README.md +++ b/README.md @@ -280,6 +280,25 @@ class ContactResource < JSONAPI::Resource end ``` +##### Default Filters + +A default filter may be defined for a resource using the `default` option on the `filter` method. This default is used +unless the request overrides this value. + +For example: + +```ruby + class CommentResource < JSONAPI::Resource + attributes :body, :status + has_one :post + has_one :author + + filter :status, default: 'published,pending' +end +``` + +The default value is used as if it came from the request. + ##### Finders Basic finding by filters is supported by resources. This is implemented in the `find` and `find_by_key` finder methods.