module WWWJDic::Utils::Raisers
This module contains some utility method to raise errors according to (possibly) common conditions.
- Author
- Copyright
-
© 2014-2021 Marco Bresciani
- License
-
GNU General Public License version 3
Public Instance Methods
raiser_array(name = 'error.value', value = nil, array = nil)
click to toggle source
Raises an ArgumentError
according to parameters, unless the array
contains the exact value
.
# File lib/wwwjdic/utils/raisers.rb 47 def raiser_array(name = 'error.value', value = nil, array = nil) 48 raise ArgumentError, I18n.t(name, value: value) if !value.nil? && !(array.include? value) 49 end
raiser_downcase(name = 'error.value', value = nil, array = nil)
click to toggle source
Raises an ArgumentError
according to parameters, unless the array
contains a downcased value
.
# File lib/wwwjdic/utils/raisers.rb 53 def raiser_downcase(name = 'error.value', value = nil, array = nil) 54 raise ArgumentError, I18n.t(name, value: value) if !value.nil? && !(array.include? value.downcase) 55 end
raiser_to_i(name = 'error.value', value = nil, array = nil)
click to toggle source
Raises an ArgumentError
according to parameters, unless the array
contains the number of the value
.
# File lib/wwwjdic/utils/raisers.rb 59 def raiser_to_i(name = 'error.value', value = nil, array = nil) 60 raise ArgumentError, I18n.t(name, value: value) if !value.nil? && !(array.include? value.to_i) 61 end