jsonapi-utils 0.2.1 → 0.2.2
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 +4 -4
- data/README.md +4 -4
- data/lib/jsonapi/utils.rb +5 -1
- data/lib/jsonapi/utils/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a230fe7cfdad1a0c6df415f03789bdbadcfcde3
|
4
|
+
data.tar.gz: 0822570d229169faa5803647b2c26bca0d51ef3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcb7c2e0a664d9a4df465d137ac331157e9780680b44208f8e132dc6cb67924a61ce773dcefa9a151f7c507d2a797851b4f5424e4eb0174dc7023a2090fc4f66
|
7
|
+
data.tar.gz: 7a8590dfdc101cd752a742078d7fb0c32451a158dbf52c4e722b33147d336315d73c314f28e50599bbec5a83ae0a25c18b5beda4242ed0bcc580753d412c4d00
|
data/README.md
CHANGED
@@ -44,7 +44,7 @@ count the total number of records for a given resource.
|
|
44
44
|
|
45
45
|
```ruby
|
46
46
|
users = User.all
|
47
|
-
jsonapi_render json: users, options: { count: users.
|
47
|
+
jsonapi_render json: users, options: { count: users.count }
|
48
48
|
```
|
49
49
|
|
50
50
|
## Usage
|
@@ -125,8 +125,7 @@ class UsersController < BaseController
|
|
125
125
|
|
126
126
|
# GET /users
|
127
127
|
def index
|
128
|
-
|
129
|
-
jsonapi_render json: users, options: { count: users.size }
|
128
|
+
jsonapi_render json: User.all
|
130
129
|
end
|
131
130
|
|
132
131
|
# GET /users/:id
|
@@ -152,7 +151,8 @@ class PostsController < BaseController
|
|
152
151
|
|
153
152
|
# GET /users/:user_id/posts
|
154
153
|
def index
|
155
|
-
|
154
|
+
posts = @user.posts.enabled
|
155
|
+
jsonapi_render json: posts, options: { count: posts.count }
|
156
156
|
end
|
157
157
|
|
158
158
|
# GET /users/:user_id/posts/:id
|
data/lib/jsonapi/utils.rb
CHANGED
@@ -35,7 +35,7 @@ module JSONAPI
|
|
35
35
|
fix_request_options(params, records)
|
36
36
|
|
37
37
|
if records.respond_to?(:to_ary)
|
38
|
-
records = fix_when_hash(records, options) if
|
38
|
+
records = fix_when_hash(records, options) if needs_to_be_fixed?(records)
|
39
39
|
@resources = build_collection(records, options)
|
40
40
|
results.add_result(JSONAPI::ResourcesOperationResult.new(:ok, @resources, result_options(options)))
|
41
41
|
else
|
@@ -77,6 +77,10 @@ module JSONAPI
|
|
77
77
|
@request.send("setup_#{action}_action", params)
|
78
78
|
end
|
79
79
|
|
80
|
+
def needs_to_be_fixed?(records)
|
81
|
+
records.is_a?(Array) && records.all? { |e| e.is_a?(Hash) }
|
82
|
+
end
|
83
|
+
|
80
84
|
def result_options(options)
|
81
85
|
hash = {}
|
82
86
|
|
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.2.
|
4
|
+
version: 0.2.2
|
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: 2015-
|
12
|
+
date: 2015-10-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|