agilibox 1.3.0 → 1.3.1

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
  SHA256:
3
- metadata.gz: d1d6a3a6ef0cdd710900a9321e8667760383f7055bf0722a8ca9e86606d542ff
4
- data.tar.gz: d65f84364748698b60b09238cf62d28b890a9785624f1aa3916a4606a6540188
3
+ metadata.gz: 75fc12b8fa0262b284e0cfec397b93f50ff588c7d97a43f22ac18c9871aeb621
4
+ data.tar.gz: c61269d792a2db9eac760af2099713c80efa88a217ea2caea69d5375a7cb7663
5
5
  SHA512:
6
- metadata.gz: 256f31aec139fe4817ad3247c4c7e37ea580f9fbba0594afaca3b1360230419cdb8349e4b8ff2987111159bcdd27f6932d899301047fef5ac2a609444b331add
7
- data.tar.gz: cb19a457bfce997f22bfc48b2049a799bad0513bedf685f4cbdf96943b4a73734df061e5fcf8e96386b5237396b996cdca2a771faa9c57efd2881eab7150e4bb
6
+ metadata.gz: aa5885a20d949ea989c0a48b885d686fc460773008ecf0bd87271d734ef0db59829b923aa8d60ba349f85ff4ee6d96891e324768545c1a000dca89f9c8865f8f
7
+ data.tar.gz: 4279dc4e03c1db2e15352972f0d7542db527cd749b89b55cae6794e489070fba398341458f7c7fb28adaadff1c34edb14fef0e390b14c3f8ca9360869081010c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Next version
4
4
 
5
+ ## 1.3.1
6
+
7
+ - `ApiControllerConcern` refactor + helpers
8
+
5
9
  ## 1.3.0
6
10
 
7
11
  - ApiControllerConcern : add `model_errors` in json response
@@ -14,14 +14,10 @@ module Agilibox::ApiControllerConcern
14
14
 
15
15
  def render_json_error(any_object, options = {})
16
16
  if any_object.is_a?(ActiveModel::Validations)
17
- model_errors = any_object.errors
18
- .map { |a, m| [a, message: m, full_message: any_object.errors.full_message(a, m)] }
19
- .uniq(&:first)
20
- .to_h
21
-
22
- error = model_errors.values.map { |e| e[:full_message] }.join(", ")
23
-
24
- json = {error: error, model_errors: model_errors}
17
+ json = {
18
+ :error => json_error_string_for_model(any_object),
19
+ :model_errors => json_errors_hash_for_model(any_object),
20
+ }
25
21
  elsif any_object.is_a?(String)
26
22
  json = {error: any_object}
27
23
  else
@@ -33,6 +29,17 @@ module Agilibox::ApiControllerConcern
33
29
  render_json(json, options)
34
30
  end
35
31
 
32
+ def json_errors_hash_for_model(object)
33
+ object.errors
34
+ .map { |a, m| [a, message: m, full_message: object.errors.full_message(a, m)] }
35
+ .uniq(&:first)
36
+ .to_h
37
+ end
38
+
39
+ def json_error_string_for_model(object)
40
+ json_errors_hash_for_model(object).values.map { |e| e[:full_message] }.join(", ")
41
+ end
42
+
36
43
  def render_not_found
37
44
  render_json_error t("errors.not_found"), status: :not_found
38
45
  end
@@ -1,3 +1,3 @@
1
1
  module Agilibox
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agilibox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - agilidée