jsonapi-utils 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7dd1257dc06616941f1a935884e1b3e18ced4898
4
- data.tar.gz: e464f7c33b4c462e6a9ddc94d669f0b1558a6b6e
3
+ metadata.gz: 7a230fe7cfdad1a0c6df415f03789bdbadcfcde3
4
+ data.tar.gz: 0822570d229169faa5803647b2c26bca0d51ef3a
5
5
  SHA512:
6
- metadata.gz: 231eff83798cb798e4c3e3e28821acea750b82b9b0c51a479678bc9523d7ff815bb8e1151272ace7a7da9abb445751e49450fc0b7f0386efa00f97f98090b56c
7
- data.tar.gz: 7a5a0d73d18304b431e61788769cf603411c01da961de76865d1499b1f6e4974934ba5eb7fe0e0e397b2dc17e0175b4f55cb72a3cefe31f36f13a0e1b621a021
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.size }
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
- users = User.all
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
- jsonapi_render json: @user.posts, options: { count: @user.posts.size }
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 records.all? { |e| e.is_a?(Hash) }
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
 
@@ -1,5 +1,5 @@
1
1
  module JSONAPI
2
2
  module Utils
3
- VERSION = '0.2.1'
3
+ VERSION = '0.2.2'
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.2.1
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-09-27 00:00:00.000000000 Z
12
+ date: 2015-10-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler