module Gravaty::Utils::Raisers
This module contains some utility method to raise errors according to (possibly) common conditions.
- Author
rubocop:disable Style/AsciiComments
- Copyright
-
Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
rubocop:enable Style/AsciiComments
- License
-
GNU General Public License version 3
Public Instance Methods
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/gravaty/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? && 55 !(array.include? value.downcase) && 56 !(array.include? value.downcase) 57 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/gravaty/utils/raisers.rb 61 def raiser_to_i(name = 'error.value', value = nil, array = nil) 62 raise ArgumentError, I18n.t(name, value: value) if !value.nil? && 63 !(array.include? value.to_i) && 64 !(array.include? value.to_i) 65 end