arkaan 0.8.14 → 0.8.15

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: a79841bf0726117debd62b451cfd9b427cfb2862
4
- data.tar.gz: ecdcd43fbde0731d2fc8a44a9982c5f013d8bcc3
3
+ metadata.gz: 34d91dc905b5495ced602cb92395a82b64d4f4fc
4
+ data.tar.gz: 33cdbdfba417dd06ef9fbf595f19dbcc1c75d321
5
5
  SHA512:
6
- metadata.gz: 686a70be27d895fecb3c52711b1cca6061d4935bae7ece3bb2448c4803f6fc9e990e12eb8506ec95c596cdb67eba1f6a34bedaff1fe39800f2a96576a38bf458
7
- data.tar.gz: bcf7c23ad40cf2b0a11ad77b862dfe3417b96a887109cd06200e1d49323b8135cbce192fbe7c9bcca3a33dcc204cfeda050589b6e2da40681650d075e886ad4e
6
+ metadata.gz: 0a18aea82a1a79b5cc6d85856dea528057dce0b5b8545b5fa2dba60339a211e180e065fca25835ba55ca231b9a5151cb3548ae7a3d0172d52a0efcf9da339c24
7
+ data.tar.gz: c5346b5cf93ab7b6ca9432511cc2b6f2ea0677545b65e241794217bd09914d173fef7e83380ad549c2bbf7df757ca2bd5bf19b5af23d5a88d9bbac74c244ef88
@@ -93,21 +93,18 @@ module Arkaan
93
93
 
94
94
  # Halts the application and creates the returned body from the parameters and the errors config file.
95
95
  # @param status [Integer] the HTTP status to halt the application with.
96
- # @param field [String] the value of the :value key in the returned JSON body, corresponding to the field in error.
97
- # @param error [String] the name of the error affecing the field.
98
- # @param suffix [String] the eventual suffix of the URL in the doc.
99
- def custom_error(status, field, error, suffix: '')
100
- url = settings.errors[field][error]
101
- halt status, {status: status, field: field, error: error, docs: "#{url}#{suffix}"}.to_json
96
+ # @param path [String] the path in the configuration file to access the URL.
97
+ def custom_error(status, path)
98
+ route, field, error = path.split('.')
99
+ halt status, {status: status, field: field, error: error, docs: settings.errors[route][field][error]}.to_json
102
100
  end
103
101
 
104
102
  # Halts the application with a Bad Request error affecting a field of a model.
105
103
  # @param instance [Mongoid::Document] the document having a field in error.
106
- # @param suffix [String] the eventual suffix of the URL in the doc.
107
- def model_error(instance, suffix: '')
108
- field = instance.errors.messages.keys.first
109
- error = instance.errors.messages[field].first
110
- custom_error(400, field, error, suffix: suffix)
104
+ # @param route [String] the type of action you're currently doing (e.g: 'creation')
105
+ def model_error(instance, route)
106
+ messages = instance.errors.messages
107
+ custom_error(400, "#{route}.#{messages.keys.first}.#{messages[field].first}")
111
108
  end
112
109
  end
113
110
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arkaan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.14
4
+ version: 0.8.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Courtois
@@ -250,7 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
250
  version: '0'
251
251
  requirements: []
252
252
  rubyforge_project:
253
- rubygems_version: 2.6.11
253
+ rubygems_version: 2.5.1
254
254
  signing_key:
255
255
  specification_version: 4
256
256
  summary: The model layer for my table-RPG application