module Gravaty::Utils::Raisers
This module contains some utility method to raise errors according to (possibly) common conditions.
- Author
- Copyright
-
Copyright © 2013, 2014, 2015, 2016, 2017, 2018,
2019 Marco Bresciani
- 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 46 def raiser_downcase(name = 'error.value', value = nil, array = nil) 47 unless value.nil? 48 raise ArgumentError, 49 I18n.t(name, value: value) unless array.include? value.downcase 50 end 51 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 55 def raiser_to_i(name = 'error.value', value = nil, array = nil) 56 unless value.nil? 57 raise ArgumentError, 58 I18n.t(name, value: value) unless array.include? value.to_i 59 end 60 end