jsonapi-utils 0.4.3 → 0.4.4

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: c5c764a38bce9c5b3858bb2cde1a345ca31f6a23
4
- data.tar.gz: 8c12bdfdf4c949eda015c8a46534a1e1c3cf333b
3
+ metadata.gz: 8e4f9e4f00521de390580aa6cc15c92f785ae0a5
4
+ data.tar.gz: 42c4dc5facd04f531fe5e19790463785e45962d2
5
5
  SHA512:
6
- metadata.gz: 202613eae09e04c60f0ccb83c250c5c934667899af4a359c4e98fa146f05db16d9dd1185505081f023ab6edda8e07a8d30617c3ba2c84ba2bc6aa4a490c24485
7
- data.tar.gz: fc7edd5cd32d6281ad6d639b5d0756c0a80b81ca6b3bcc622c8495015b627e967cbd476088da8e2acb2f215eea8b1bc3534cd36bc90b34e7bf623b0ff4d9739c
6
+ metadata.gz: ea64cf3d3f5900d25b194047f045ccc0450315108223250cbfab943e89f8ccd25ecff1aca8d056bb1454aa2e9e933abc08177688f110f02f4b91095f99ffdcae
7
+ data.tar.gz: 249e6f9b09eb464091f0c4aa38fb19920f42a3b62ad3d0d547d7274d2cdb2712230a5493711ec83e5efcea0efd5efe52bdc3b040339c5cf51d73c60bfb75381e
data/README.md CHANGED
@@ -44,6 +44,9 @@ jsonapi_render json: User.find(params[:id])
44
44
  # Collection rendering
45
45
  jsonapi_render json: User.all
46
46
 
47
+ # Specify a particular HTTP status code
48
+ jsonapi_render json: new_user, status: :created
49
+
47
50
  # Forcing a different resource
48
51
  jsonapi_render json: User.all, options: { resource: V2::UserResource }
49
52
 
@@ -194,7 +197,7 @@ class PostsController < BaseController
194
197
  end
195
198
  ```
196
199
 
197
- ### Erros
200
+ ### Errors
198
201
 
199
202
  #### Not found
200
203
 
@@ -5,18 +5,15 @@ require 'jsonapi/utils/exceptions'
5
5
  module JSONAPI
6
6
  module Utils
7
7
  def self.included(base)
8
- base.helper_method :jsonapi_serialize
8
+ if base.respond_to?(:helper_method)
9
+ base.before_action :setup_request, :check_request
10
+ base.helper_method :jsonapi_render, :jsonapi_serialize
11
+ end
9
12
  end
10
13
 
11
14
  def jsonapi_render(json:, status: nil, options: {})
12
- setup_request
13
-
14
- if @request.errors.present?
15
- render_errors(@request.errors)
16
- else
17
- body = jsonapi_serialize(json, options)
18
- render json: body, status: status || @_response_document.status
19
- end
15
+ body = jsonapi_serialize(json, options)
16
+ render json: body, status: status || @_response_document.status
20
17
  rescue => e
21
18
  handle_exceptions(e)
22
19
  ensure
@@ -26,8 +23,9 @@ module JSONAPI
26
23
  end
27
24
 
28
25
  def jsonapi_render_errors(exception)
29
- error = jsonapi_format_errors(exception)
30
- render json: { errors: error.errors }, status: error.code
26
+ result = jsonapi_format_errors(exception)
27
+ errors = result.errors
28
+ render json: { errors: errors }, status: errors.first.status
31
29
  end
32
30
 
33
31
  def jsonapi_format_errors(exception)
@@ -52,8 +50,6 @@ module JSONAPI
52
50
  end
53
51
 
54
52
  def jsonapi_serialize(records, options = {})
55
- setup_request
56
-
57
53
  if records.is_a?(Hash)
58
54
  hash = records.with_indifferent_access
59
55
  records = hash_to_active_record(hash[:data], options[:model])
@@ -256,5 +252,9 @@ module JSONAPI
256
252
  server_error_callbacks: (self.class.server_error_callbacks || [])
257
253
  )
258
254
  end
255
+
256
+ def check_request
257
+ @request.errors.blank? || render_errors(@request.errors)
258
+ end
259
259
  end
260
260
  end
@@ -1,5 +1,5 @@
1
1
  module JSONAPI
2
2
  module Utils
3
- VERSION = '0.4.3'
3
+ VERSION = '0.4.4'
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.4.3
4
+ version: 0.4.4
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-04-28 00:00:00.000000000 Z
12
+ date: 2016-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jsonapi-resources
@@ -53,20 +53,6 @@ dependencies:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '10.0'
56
- - !ruby/object:Gem::Dependency
57
- name: rspec-rails
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '3.1'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '3.1'
70
56
  - !ruby/object:Gem::Dependency
71
57
  name: sqlite3
72
58
  requirement: !ruby/object:Gem::Requirement
@@ -82,61 +68,61 @@ dependencies:
82
68
  - !ruby/object:Gem::Version
83
69
  version: '0'
84
70
  - !ruby/object:Gem::Dependency
85
- name: factory_girl
71
+ name: rails
86
72
  requirement: !ruby/object:Gem::Requirement
87
73
  requirements:
88
74
  - - "~>"
89
75
  - !ruby/object:Gem::Version
90
- version: '4.5'
76
+ version: '4.2'
91
77
  type: :development
92
78
  prerelease: false
93
79
  version_requirements: !ruby/object:Gem::Requirement
94
80
  requirements:
95
81
  - - "~>"
96
82
  - !ruby/object:Gem::Version
97
- version: '4.5'
83
+ version: '4.2'
98
84
  - !ruby/object:Gem::Dependency
99
- name: jsonapi-resources
85
+ name: rspec-rails
100
86
  requirement: !ruby/object:Gem::Requirement
101
87
  requirements:
102
88
  - - "~>"
103
89
  - !ruby/object:Gem::Version
104
- version: 0.7.0
90
+ version: '3.1'
105
91
  type: :development
106
92
  prerelease: false
107
93
  version_requirements: !ruby/object:Gem::Requirement
108
94
  requirements:
109
95
  - - "~>"
110
96
  - !ruby/object:Gem::Version
111
- version: 0.7.0
97
+ version: '3.1'
112
98
  - !ruby/object:Gem::Dependency
113
- name: rails
99
+ name: factory_girl
114
100
  requirement: !ruby/object:Gem::Requirement
115
101
  requirements:
116
102
  - - "~>"
117
103
  - !ruby/object:Gem::Version
118
- version: '4.2'
104
+ version: '4.5'
119
105
  type: :development
120
106
  prerelease: false
121
107
  version_requirements: !ruby/object:Gem::Requirement
122
108
  requirements:
123
109
  - - "~>"
124
110
  - !ruby/object:Gem::Version
125
- version: '4.2'
111
+ version: '4.5'
126
112
  - !ruby/object:Gem::Dependency
127
- name: pry
113
+ name: smart_rspec
128
114
  requirement: !ruby/object:Gem::Requirement
129
115
  requirements:
130
- - - ">="
116
+ - - "~>"
131
117
  - !ruby/object:Gem::Version
132
- version: '0'
118
+ version: 0.1.4
133
119
  type: :development
134
120
  prerelease: false
135
121
  version_requirements: !ruby/object:Gem::Requirement
136
122
  requirements:
137
- - - ">="
123
+ - - "~>"
138
124
  - !ruby/object:Gem::Version
139
- version: '0'
125
+ version: 0.1.4
140
126
  description: A Rails way to get your API's data serialized through JSON API's specs
141
127
  (http://jsosapi.org)
142
128
  email:
@@ -146,17 +132,11 @@ executables: []
146
132
  extensions: []
147
133
  extra_rdoc_files: []
148
134
  files:
149
- - ".gitignore"
150
- - ".rspec"
151
- - ".travis.yml"
152
135
  - CODE_OF_CONDUCT.md
153
- - Gemfile
154
136
  - LICENSE.txt
155
137
  - README.md
156
- - Rakefile
157
138
  - bin/console
158
139
  - bin/setup
159
- - jsonapi-utils.gemspec
160
140
  - lib/jsonapi/utils.rb
161
141
  - lib/jsonapi/utils/exceptions.rb
162
142
  - lib/jsonapi/utils/version.rb
data/.gitignore DELETED
@@ -1,22 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/log/
9
- /spec/test_db
10
- /spec/reports/
11
- /tmp/
12
- /log/
13
- *.log
14
- *.bundle
15
- *.so
16
- *.sw*
17
- *.o
18
- *.a
19
- *.gem
20
- .DS_Store
21
- test_db
22
-
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format documentation
2
- --color
@@ -1,9 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- env:
4
- - 'RAILS_VERSION=4.1.0'
5
- - 'RAILS_VERSION=4.2.0'
6
- rvm:
7
- - 2.2
8
- before_install: gem install bundler -v 1.10.4
9
- script: bundle exec rspec spec/controllers/{user,post}s_controller_spec.rb
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in jsonapi-utils.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:spec) do |test|
5
- test.pattern = 'spec/controllers/{user,post}s_controller.rb'
6
- end
7
-
8
- task default: :spec
@@ -1,32 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'jsonapi/utils/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'jsonapi-utils'
8
- spec.version = JSONAPI::Utils::VERSION
9
- spec.authors = ['Tiago Guedes', 'Douglas André']
10
- spec.email = ['tiagopog@gmail.com', 'douglas@beautydate.com.br']
11
-
12
- spec.summary = %q{JSON::Utils is a simple way to get a full-featured JSON API serialization for your controller's responses.}
13
- spec.description = %q{A Rails way to get your API's data serialized through JSON API's specs (http://jsosapi.org)}
14
- spec.homepage = 'https://github.com/b2beauty/jsonapi-utils'
15
- spec.license = 'MIT'
16
-
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = 'exe'
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ['lib']
21
-
22
- spec.add_runtime_dependency 'jsonapi-resources', '~> 0.7.0'
23
-
24
- spec.add_development_dependency 'bundler', '~> 1.10'
25
- spec.add_development_dependency 'rake', '~> 10.0'
26
- spec.add_development_dependency 'rspec-rails', '~> 3.1'
27
- spec.add_development_dependency 'sqlite3'
28
- spec.add_development_dependency 'factory_girl', '~> 4.5'
29
- spec.add_development_dependency 'jsonapi-resources', '~> 0.7.0'
30
- spec.add_development_dependency 'rails', '~> 4.2'
31
- spec.add_development_dependency 'pry'
32
- end