restful_json 3.4.0 → 3.4.1

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjgzMjdmNjljNDk3NmVjMGY1MGY4ZWIxMTdhNzQ5OTM1MTA5YTJkYQ==
4
+ OTc4OTM4YTFiYWVhNjNjM2RkZTI4ZDY4YmFjZDBiOWIwM2EwOWZhOA==
5
5
  data.tar.gz: !binary |-
6
- ODgwNzg5ODUwMTQwNjBhOTIyZjNlNDNlY2U0ZWY1ZDYxNjE5NmU5Mw==
6
+ YmIzYWYzMDZlNTNiM2YzMThjNmYzYjA5ZDI5MDJhOGI5ZjkwODQ4Mw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OGYwZjQ5ZjljOWJmZTUzN2RlYTM0OGNmNGI5ZDViNDIzNDMxOTFlNjQ5YmMx
10
- NzY5MTdhMzk0YmQ0MGNmZmJkMjQwMDMwNGYzYjllNDg0OWM3Y2ZmZjkyMDI2
11
- NjVlN2ZhMTRhMTljZGE3NWI3YzNjYWYxMjBhODhlNTk3MTYwZmQ=
9
+ MTRhZDlmN2Q3Zjk4MmYxZjE4ZTg1MWRhNDU3Yjc3ZGE3NDZjZTJmNjc5OTBi
10
+ MzMwZTBjMjFlYjZlMTNiNzhiOWYyNTIzNGI4ZjY4NGRmYzVkYjcyOThiNmI0
11
+ N2YxNzhjYmRiYTJjYTkxNjIwZDI1YmE3MzQxNTZlMjI3ZGFjZWY=
12
12
  data.tar.gz: !binary |-
13
- YTVjM2YyNjNhYjAyMDdiMzM3M2JlNGExMWYwODRjYWExZGM5NWQxZDU1MmM5
14
- NzAyYTU3MjY3MWFiYzM1NjYzYTUyNTlmNWRjNjEzODljYzNkZmU4NzRkYTI1
15
- MDE1MTFkNGYxMDNiZDc1ZWU5ZTc0YjYzZDk2MzczNDVlMmU2MDE=
13
+ OWVmZmQ1ODExODFiMmQ2ZTY4ZDc3NmYyMzAwYzM0MzU3M2E2Y2M4MzViZDNl
14
+ MTU1MGM0YTM1NjBhZjQ2ZDZmYmNmNTI3YmUzZWU2YzFkMjY5NjY2MzRmMTA0
15
+ NjM5NTEzYWRjOTZhNDhmMTYxNWYyM2ExZDkxYmEwNzhlMDU4ZTI=
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Restful JSON [![Build Status](https://secure.travis-ci.org/rubyservices/restful_json.png?branch=master)](http://travis-ci.org/rubyservices/restful_json)
2
2
 
3
- Develop declarative, featureful JSON RESTful-ish service controllers to use with modern Javascript MVC frameworks like AngularJS, Ember, etc. with much less code.
3
+ Develop declarative, featureful RESTful-ish JSON service controllers to use with modern Javascript MVC frameworks like AngularJS, Ember, etc. with much less code. (I say "RESTful-ish" instead of RESTful, to differentiate them from true-REST, hypermedia-driven projects, but restful_json controllers are RESTful by the existing Rails definition of being RESTful, using the same actions and resourceful routes, but with more abilities.)
4
4
 
5
5
  What does that mean? It means you typically won't have to write index, create, update, destroy, etc. methods in your controllers to filter, sort, and do complex queries.
6
6
 
@@ -26,16 +26,16 @@ An example app using an older version of restful_json with AngularJS is [employe
26
26
 
27
27
  In your Rails app's `Gemfile`:
28
28
 
29
- gem 'restful_json', '~> 3.3.0'
29
+ gem 'restful_json', '~> 3.4.0'
30
30
 
31
31
  And if you go with the defaults to use ActiveModel::Serializers and Permitters (using Strong Parameters and Cancan):
32
32
 
33
33
  # comment this out if you don't want to use Strong Parameters or Permitters, or if you are using Rails 4, which includes it
34
- gem 'strong_parameters', '~> 0.1.6'
34
+ gem 'strong_parameters', '~> 0.2.0'
35
35
  # comment this out if you don't plan to use Permitters
36
- gem 'cancan', '~> 1.6.8'
36
+ gem 'cancan', '~> 1.6.9'
37
37
  # comment this out if you don't plan to use ActiveModel::Serializers
38
- gem 'active_model_serializers', '~> 0.6.0'
38
+ gem 'active_model_serializers', '~> 0.7.0'
39
39
 
40
40
  Then:
41
41
 
@@ -36,11 +36,24 @@ RestfulJson.configure do
36
36
  self.return_error_data = true
37
37
  # Set to nil to reraise StandardError in rescue vs. calling render_error(e) to render using restful_json
38
38
  self.rescue_class = StandardError
39
- # Ordered array of handlers to handle rescue of self.rescue_class or sub types. Can use optional i18n_key for message, but will default to e.message if not found.
40
- # Eventually may support [DataMapper::ObjectNotFoundError], [MongoMapper::DocumentNotFound], etc.
41
- # If no exception_classes or exception_ancestor_classes provided, it will always match self.rescue_class.
42
- self.rescue_handlers = [
43
- {exception_classes: [ActiveRecord::RecordNotFound], status: :not_found, i18n_key: 'api.not_found'.freeze},
44
- {status: :internal_server_error, i18n_key: 'api.internal_server_error'.freeze}
45
- ]
39
+ self.rescue_handlers = []
40
+ # support 404 error for ActiveRecord::RecordNotFound if using ActiveRecord
41
+ # errors not loaded yet, so we need to try to require
42
+ begin
43
+ require 'active_record/errors'
44
+ RestfulJson.configure do
45
+ # Ordered array of handlers to handle rescue of self.rescue_class or sub types. Can use optional i18n_key for message, but will default to e.message if not found.
46
+ # Eventually may support [DataMapper::ObjectNotFoundError], [MongoMapper::DocumentNotFound], etc.
47
+ # If no exception_classes or exception_ancestor_classes provided, it will always match self.rescue_class.
48
+ # Important note: if you specify classes in your configuration, do not specify as strings unless the RestfulJson railtie
49
+ # will have a chance to convert it to constants/class objects. See railtie for more info.
50
+ self.rescue_handlers = [
51
+ {exception_classes: [ActiveRecord::RecordNotFound], status: :not_found, i18n_key: 'api.not_found'.freeze},
52
+ ]
53
+ end
54
+ rescue LoadError, NameError
55
+ end
56
+
57
+ # add default 500 errors last
58
+ self.rescue_handlers << {status: :internal_server_error, i18n_key: 'api.internal_server_error'.freeze}
46
59
  end
@@ -1,9 +1,3 @@
1
- #require 'restful_json/config'
2
- #require 'twinturbo/controller'
3
- #require 'active_model_serializers'
4
- #require 'strong_parameters'
5
- #require 'cancan'
6
-
7
1
  # The restful_json controller module. This module (RestfulJson::Controller) is included on ActionController
8
2
  # and then each individual controller should call acts_as_restful_json.
9
3
  #
@@ -197,12 +191,6 @@ module RestfulJson
197
191
  value && NILS.include?(value) ? nil : value
198
192
  end
199
193
 
200
- def safe_i18n_t(i18n_key)
201
- I18n.t(i18n_key)
202
- rescue => e
203
- logger.debug "failed to get i18n message for #{i18n_key.inspect}: #{e.message}\n#{e.backtrace.join('\n')}" if self.debug
204
- end
205
-
206
194
  # Returns self.return_error_data by default. To only return error_data in dev and test, use this:
207
195
  # `def enable_long_error?; Rails.env.development? || Rails.env.test?; end`
208
196
  def include_error_data?
@@ -254,17 +242,17 @@ module RestfulJson
254
242
  # It handles any format in theory that is supported by respond_to and has a `to_(some format)` method.
255
243
  def render_error(e, handling_data)
256
244
  i18n_key = handling_data[:i18n_key]
257
- msg = i18n_key ? safe_i18n_t(i18n_key) : e.message
245
+ msg = result = t(i18n_key, default: e.message)
258
246
  status = handling_data[:status] || :internal_server_error
259
247
  if include_error_data?
260
248
  respond_to do |format|
261
249
  format.html { render notice: msg }
262
- format.any { render request.format.to_sym => {:status => status, error: msg, error_data: {type: e.class.name, message: e.message, trace: Rails.backtrace_cleaner.clean(e.backtrace)}}, status: status }
250
+ format.any { render request.format.to_sym => {status: status, error: msg, error_data: {type: e.class.name, message: e.message, trace: Rails.backtrace_cleaner.clean(e.backtrace)}}, status: status }
263
251
  end
264
252
  else
265
253
  respond_to do |format|
266
254
  format.html { render notice: msg }
267
- format.any { render request.format.to_sym => {:status => status, error: msg}, status: status }
255
+ format.any { render request.format.to_sym => {status: status, error: msg}, status: status }
268
256
  end
269
257
  end
270
258
  # return exception so we know it was handled
@@ -276,7 +264,7 @@ module RestfulJson
276
264
  # 404/not found is just for update (not destroy, because idempotent destroy = no 404)
277
265
  if success_code == :not_found
278
266
  respond_to do |format|
279
- format.html { render :file => "#{Rails.root}/public/404.html", :status => :not_found }
267
+ format.html { render file: "#{Rails.root}/public/404.html", status: :not_found }
280
268
  format.any { head :not_found }
281
269
  end
282
270
  elsif !@value.nil? && ((read_only_action && RestfulJson.return_resource) || RestfulJson.avoid_respond_with)
@@ -3,9 +3,17 @@ require 'restful_json'
3
3
  module RestfulJson
4
4
  class Railtie < ::Rails::Railtie
5
5
  initializer "restful_json.action_controller" do
6
+ # provide deprecated acts_as_restful_json method on controller
6
7
  ActiveSupport.on_load(:action_controller) do
7
8
  include ::RestfulJson::BaseController
8
9
  end
9
10
  end
11
+
12
+ #TODO: split permitters out into their own gem, and then can always add to autoload path if gem loaded
13
+ initializer "restful_json.autoload_paths", after: :load_config_initializers do
14
+ if RestfulJson.use_permitters
15
+ ActiveSupport::Dependencies.autoload_paths << "#{Rails.root}/app/permitters" unless ActiveSupport::Dependencies.autoload_paths.include?("#{Rails.root}/app/permitters")
16
+ end
17
+ end
10
18
  end
11
19
  end
@@ -1,3 +1,3 @@
1
1
  module RestfulJson
2
- VERSION = '3.4.0'
2
+ VERSION = '3.4.1'
3
3
  end
data/lib/restful_json.rb CHANGED
@@ -5,5 +5,4 @@ require 'twinturbo/controller'
5
5
  require 'restful_json/base_controller'
6
6
  require 'restful_json/controller'
7
7
  require 'restful_json/default_controller'
8
-
9
- ActiveSupport::Dependencies.autoload_paths << "#{Rails.root}/app/permitters" unless ActiveSupport::Dependencies.autoload_paths.include?("#{Rails.root}/app/permitters")
8
+ require 'restful_json/railtie' if defined? ::Rails::Railtie
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restful_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary S. Weaver
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-17 00:00:00.000000000 Z
12
+ date: 2013-04-22 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: 3.1.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ! '>='
26
+ - !ruby/object:Gem::Version
27
+ version: 3.1.0
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: bundler
16
30
  requirement: !ruby/object:Gem::Requirement