napa_rails 0.1.2 → 0.1.3
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/CHANGELOG.md +4 -0
- data/lib/napa.rb +1 -0
- data/lib/napa/grape_extensions/grape_extenders.rb +32 -0
- data/lib/napa/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 960c38e805018236509ecb3b466e50c9e094d8a4
|
4
|
+
data.tar.gz: 57f36adcac7d40c73e009ee81c5a69b0df61b519
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ddb83d14fa62c93ae37f13ae58faa6e088d3291a337fd9ac8454ff03b156fb1540eb2eeb3ae27779a75fba195fa17842d1dc6da65e87d306fc27a4b78cacbe5
|
7
|
+
data.tar.gz: 651adacb65d252a03d8e32e7292f4e524753e5631705d41bd15a96fb8c22a670b408595a97476555e668386df7fa3c9a2e9988750553643da2446e3af71f2d57
|
data/CHANGELOG.md
CHANGED
data/lib/napa.rb
CHANGED
@@ -8,6 +8,7 @@ require "napa/output_formatters/representer"
|
|
8
8
|
require "napa/output_formatters/pagination"
|
9
9
|
require "napa/grape_extensions/grape_helpers"
|
10
10
|
require "napa/grape_extensions/error_formatter"
|
11
|
+
require "napa/grape_extensions/grape_extenders"
|
11
12
|
require "napa/json_error"
|
12
13
|
|
13
14
|
module Napa
|
@@ -0,0 +1,32 @@
|
|
1
|
+
if defined?(Rails)
|
2
|
+
module Napa
|
3
|
+
module GrapeExtenders
|
4
|
+
def self.extended(modified_class)
|
5
|
+
# when extended, set the exceptions to handle
|
6
|
+
|
7
|
+
# if AR is being used, rescue from common AR errors
|
8
|
+
if defined?(::ActiveRecord)
|
9
|
+
modified_class.rescue_from ::ActiveRecord::RecordNotFound do
|
10
|
+
err = Napa::JsonError.new(:record_not_found, 'record not found')
|
11
|
+
Rails.logger.debug({ status: 404, headers: {}, response: err.try(:first) }.map { |k, v| "#{k}=#{v}" }.join(' '))
|
12
|
+
rack_response(err.to_json, 404)
|
13
|
+
end
|
14
|
+
modified_class.rescue_from ::ActiveRecord::RecordInvalid do |e|
|
15
|
+
err = Napa::JsonError.new(:unprocessable_entity, e.message, e.record.errors.messages)
|
16
|
+
Rails.logger.debug({ status: 422, headers: {}, response: err.try(:first) }.map { |k, v| "#{k}=#{v}" }.join(' '))
|
17
|
+
rack_response(err.to_json, 422)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# if AASM is being used, rescue from invalid transitions
|
22
|
+
if defined?(::AASM)
|
23
|
+
modified_class.rescue_from ::AASM::InvalidTransition do |e|
|
24
|
+
err = Napa::JsonError.new(:unprocessable_entity, e.message)
|
25
|
+
Rails.logger.debug({ status: 422, headers: {}, response: err.try(:first) }.map { |k, v| "#{k}=#{v}" }.join(' '))
|
26
|
+
rack_response(err.to_json, 422)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/napa/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: napa_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darby Frey, Flori Garcia
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- bin/setup
|
121
121
|
- lib/napa.rb
|
122
122
|
- lib/napa/grape_extensions/error_formatter.rb
|
123
|
+
- lib/napa/grape_extensions/grape_extenders.rb
|
123
124
|
- lib/napa/grape_extensions/grape_helpers.rb
|
124
125
|
- lib/napa/json_error.rb
|
125
126
|
- lib/napa/output_formatters/include_nil.rb
|