ocean-rails 1.14.3 → 1.15.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce9a28ccf97e9bf1ee5c4905451a525fd31f989d
|
4
|
+
data.tar.gz: 9abb086155560c5c2673a0c9fc67f461edbe196d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6aa5c1b90969a5153777aaeefbc5ede1ddbfd21e6451fdbf82472eb5abc685e6e7e7f4b4396c13f20b507f568f9bbc01f0ee9aad7ff5a6ac5c8b9618f7367875
|
7
|
+
data.tar.gz: d5be6dbac22701ece003f860a5f55c97125231903ef70b96e25ccc2e71e45c7f0775e41bb603cfcae74dd098726c3ed66518f123bd3a20a504d8dcf2f5d34693
|
@@ -9,6 +9,18 @@ module Ocean
|
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
|
11
11
|
included do
|
12
|
+
rescue_from ActiveRecord::RecordNotUnique,
|
13
|
+
ActiveRecord::StatementInvalid do |x|
|
14
|
+
render_api_error 422, "#{controller_name.singularize.camelize} already exists"
|
15
|
+
end
|
16
|
+
|
17
|
+
rescue_from ActiveRecord::StaleObjectError do |x|
|
18
|
+
render_api_error 409, "Stale #{x.record.class.name}"
|
19
|
+
end
|
20
|
+
|
21
|
+
rescue_from ActiveRecord::RecordInvalid do |x|
|
22
|
+
render_validation_errors x.record
|
23
|
+
end
|
12
24
|
end
|
13
25
|
|
14
26
|
module ClassMethods
|
data/lib/ocean/version.rb
CHANGED
@@ -34,18 +34,8 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
34
34
|
def create
|
35
35
|
@<%= singular_table_name %> = <%= class_name %>.new(filtered_params <%= class_name %>)
|
36
36
|
set_updater(@<%= singular_table_name %>)
|
37
|
-
|
38
|
-
|
39
|
-
@<%= singular_table_name %>.save!
|
40
|
-
rescue ActiveRecord::RecordNotUnique, ActiveRecord::StatementInvalid,
|
41
|
-
SQLite3::ConstraintException
|
42
|
-
render_api_error 422, "<%= class_name %> already exists"
|
43
|
-
return
|
44
|
-
end
|
45
|
-
api_render @<%= singular_table_name %>, new: true
|
46
|
-
else
|
47
|
-
render_validation_errors @<%= singular_table_name %>
|
48
|
-
end
|
37
|
+
@<%= singular_table_name %>.save!
|
38
|
+
api_render @<%= singular_table_name %>, new: true
|
49
39
|
end
|
50
40
|
|
51
41
|
|
@@ -55,19 +45,10 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
55
45
|
render_api_error 422, "Missing resource attributes"
|
56
46
|
return
|
57
47
|
end
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
rescue ActiveRecord::StaleObjectError
|
63
|
-
render_api_error 409, "Stale <%= class_name %>"
|
64
|
-
return
|
65
|
-
end
|
66
|
-
if @<%= singular_table_name %>.valid?
|
67
|
-
api_render @<%= singular_table_name %>
|
68
|
-
else
|
69
|
-
render_validation_errors(@<%= singular_table_name %>)
|
70
|
-
end
|
48
|
+
@<%= singular_table_name %>.assign_attributes(filtered_params <%= class_name %>)
|
49
|
+
set_updater(@<%= singular_table_name %>)
|
50
|
+
@<%= singular_table_name %>.save!
|
51
|
+
api_render @<%= singular_table_name %>
|
71
52
|
end
|
72
53
|
|
73
54
|
|