jsonapi-utils 0.5.0.beta5 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e497750ffb06aad8803f1fb6e85d513ca8eafd4
4
- data.tar.gz: 7516ec26de1efe29f1666ba3aa49381d0bd033ec
3
+ metadata.gz: c0be601da593b84a1174a28708470fc8a3b19156
4
+ data.tar.gz: 201d0bb520bc0465486819f94fe419a15c4c1bb1
5
5
  SHA512:
6
- metadata.gz: b1fbb7ff07c127c0f627f2a222f123aae26b6e1782d25f396d35e709ee589fe49a681185c4a350bfb4d43b54972068d70ac9055bef3fa4fe6ac2b2b7478bdc91
7
- data.tar.gz: 599cf401067538fade2cdc0a75e8c533f8bcd1f313973da8d272d09e5a07bbb4a74c118073e229ae689931ca0f45b6d6cd02fe0c25b21be2a63e8419ded50530
6
+ metadata.gz: e07edab40bd4956fb3ef3eba13e29e1f020d1ec144d2904d6e95a716a568ce8283a09f8ba8e76ecec4fd43e42805dbf72607dd97e8e1574770b0574fa0bd3f2e
7
+ data.tar.gz: c23d41ae2fa4fe7896d2aea00dc0417479a8213e407984e06281bf899912d32251bf49f206c2b18977570eb7c9cff47ec68b6f9ebaa6580f0b083228dd0b5497
data/README.md CHANGED
@@ -6,7 +6,21 @@
6
6
 
7
7
  Simple yet powerful way to get your Rails API compliant with [JSON API](http://jsonapi.org).
8
8
 
9
- `JSONAPI::Utils` (JU) is built on top of [JSONAPI::Resources](https://github.com/cerebris/jsonapi-resources) taking advantage of its resource-driven style and bringing an easy way to build modern JSON APIs with no or less learning curve.
9
+ `JSONAPI::Utils` (JU) is built on top of [JSONAPI::Resources](https://github.com/cerebris/jsonapi-resources)
10
+ taking advantage of its resource-driven style and bringing a set of helpers to easily build modern JSON APIs
11
+ with no or less learning curve.
12
+
13
+ After installing the gem and defining the resources/routes, it's as simple as calling a render helper:
14
+
15
+ ```ruby
16
+ class UsersController < ActionController::Base
17
+ include JSONAPI::Utils
18
+
19
+ def index
20
+ jsonapi_render json: User.all
21
+ end
22
+ end
23
+ ```
10
24
 
11
25
  ## Table of Contents
12
26
 
@@ -48,10 +62,10 @@ For Rails 4.x add this to your application's Gemfile:
48
62
  gem 'jsonapi-utils', '~> 0.4.7'
49
63
  ```
50
64
 
51
- For Rails 5, specify the beta version in the Gemfile:
65
+ For Rails 5, specify the `0.5.x` version in the Gemfile:
52
66
 
53
67
  ```ruby
54
- gem 'jsonapi-utils', '0.5.0.beta5'
68
+ gem 'jsonapi-utils', '0.5.0'
55
69
  ```
56
70
 
57
71
  And then execute:
@@ -14,13 +14,17 @@ module JSONAPI
14
14
  alias_method :jsonapi_serialize, :jsonapi_format
15
15
 
16
16
  def jsonapi_format_errors(data)
17
- data = JSONAPI::Utils::Exceptions::ActiveRecord.new(data, @request.resource_klass, context) if data.is_a?(ActiveRecord::Base)
17
+ data = JSONAPI::Utils::Exceptions::ActiveRecord.new(data, @request.resource_klass, context) if active_record_obj?(data)
18
18
  errors = data.respond_to?(:errors) ? data.errors : data
19
19
  JSONAPI::Utils::Support::Error.sanitize(errors).uniq
20
20
  end
21
21
 
22
22
  private
23
23
 
24
+ def active_record_obj?(data)
25
+ data.is_a?(ActiveRecord::Base)|| data.singleton_class.include?(ActiveModel::Model)
26
+ end
27
+
24
28
  def build_response_document(records, options)
25
29
  results = JSONAPI::OperationResults.new
26
30
 
@@ -1,5 +1,5 @@
1
1
  module JSONAPI
2
2
  module Utils
3
- VERSION = '0.5.0.beta5'.freeze
3
+ VERSION = '0.5.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.beta5
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Guedes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-12-26 00:00:00.000000000 Z
12
+ date: 2017-01-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jsonapi-resources
@@ -193,9 +193,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
193
193
  version: '0'
194
194
  required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  requirements:
196
- - - ">"
196
+ - - ">="
197
197
  - !ruby/object:Gem::Version
198
- version: 1.3.1
198
+ version: '0'
199
199
  requirements: []
200
200
  rubyforge_project:
201
201
  rubygems_version: 2.6.7