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: b7f957055559e368f6cb0c7c449f46b957c68076
4
- data.tar.gz: 9cb3d11b49d425bc45bd229929d46b43361e7f18
3
+ metadata.gz: ce9a28ccf97e9bf1ee5c4905451a525fd31f989d
4
+ data.tar.gz: 9abb086155560c5c2673a0c9fc67f461edbe196d
5
5
  SHA512:
6
- metadata.gz: 0091f80cdf13da6d98ae0aa052de5eac75946e7569256242b72ad2a59ec442d89c3613e81ccc175fca80390944cdfb598b70f1757e069860772d50bbe4ffcb63
7
- data.tar.gz: cb1f8e078078690ee7c88d4e662e3477128a451d84d9b32d5485b56c817b5bdf20d208cd2d2e66973c412aae0b9daf3af5bc40ff120dfcd0b2a0d70dfc4e0236
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
@@ -1,3 +1,3 @@
1
1
  module Ocean
2
- VERSION = "1.14.3"
2
+ VERSION = "1.15.0"
3
3
  end
@@ -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
- if @<%= singular_table_name %>.valid?
38
- begin
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
- begin
59
- @<%= singular_table_name %>.assign_attributes(filtered_params <%= class_name %>)
60
- set_updater(@<%= singular_table_name %>)
61
- @<%= singular_table_name %>.save
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocean-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.3
4
+ version: 1.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Bengtson