arkaan 1.1.1 → 1.2.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: 2739aca73dc59ad21f94432cfbacddffe63d166a
4
- data.tar.gz: 70bae638a7670eb846e95a1fda21bedc36aa95cb
3
+ metadata.gz: ca91b0682b2c5963082d4ce0974d3695057a47e6
4
+ data.tar.gz: 8010676e37c2305d326a33d843e88f92e79d7570
5
5
  SHA512:
6
- metadata.gz: 0e6a4f24e061f3bc84fcb584aadd89c4a83eced300d7fcdd240053748829d4da7c7201e2997bc27a38c6c89dae20a6765bebeee8d8c66eed563afd22d6e8a32b
7
- data.tar.gz: 1e4c83ff9edd541a045053d9cabdf060cbf69a739f81a0ce5e89d26f2b3729b2b1f80626515033e663090f98ae04b20d2834951d14cde28d7fa13bcbfb14d414
6
+ metadata.gz: 5e7e74877243902f1fe8c3d399657c99a93dfccab364b752c84d0e18c1fdb5b3a3df3a4866158badc8320b55a72fdf7995dd5168ac5e75fa0f3fe509fcfe2b8a
7
+ data.tar.gz: 5306f5291eafe02c5daebe629a7d5d8ee4123bbe9d7d1e433690c09b080734d64b9e2ef70032d9204848011d2cd57e9dabb67e6b272a6e08634fe04f98607943
@@ -70,12 +70,24 @@ module Arkaan
70
70
 
71
71
  # Checks the presence of several fields given as parameters and halts the execution if it's not present.
72
72
  # @param fields [Array<String>] an array of fields names to search in the parameters
73
+ # @param route [String] the name of the route you're requiring to put in the error message.
73
74
  def check_presence(*fields, route:)
74
75
  fields.each do |field|
75
76
  custom_error(400, "#{route}.#{field}.required") if params[field].nil? || params[field] == ''
76
77
  end
77
78
  end
78
79
 
80
+ # Checks the presence of either fields given in parameters. It halts with an error only if ALL parameters are not given.
81
+ # @param fields [Array<String>] an array of fields names to search in the parameters
82
+ # @param route [String] the name of the route you're requiring to put in the error message.
83
+ # @param key [String] the key to search in the errors configuration file.
84
+ def check_either_presence(*fields, route:, key:)
85
+ fields.each do |field|
86
+ return true if !params[field].nil? && params[field] != ''
87
+ end
88
+ custom_error 400, "#{route}.#{key}.required"
89
+ end
90
+
79
91
  # Checks if the session ID is given in the parameters and if the session exists.
80
92
  # @param action [String] the action used to get the errors from the errors file.
81
93
  # @return [Arkaan::Authentication::Session] the session when it exists.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arkaan
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Courtois
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-24 00:00:00.000000000 Z
11
+ date: 2018-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec