Module: Gravaty::Utils::Raisers

Overview

This module contains some utility method to raise errors according to (possibly) common conditions.

Author

Marco Bresciani

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

Instance Method Summary collapse

Instance Method Details

#raiser_downcase(name = 'error.value', value = nil, array = nil) ⇒ Object

Raises an ArgumentError according to parameters, unless the array contains a downcased value.

Raises:

  • (ArgumentError)


53
54
55
56
57
# File 'lib/gravaty/utils/raisers.rb', line 53

def raiser_downcase(name = 'error.value', value = nil, array = nil)
  raise ArgumentError, I18n.t(name, value: value) if !value.nil? &&
                                                     !(array.include? value.downcase) &&
                                                     !(array.include? value.downcase)
end

#raiser_to_i(name = 'error.value', value = nil, array = nil) ⇒ Object

Raises an ArgumentError according to parameters, unless the array contains the number of the value.

Raises:

  • (ArgumentError)


61
62
63
64
65
# File 'lib/gravaty/utils/raisers.rb', line 61

def raiser_to_i(name = 'error.value', value = nil, array = nil)
  raise ArgumentError, I18n.t(name, value: value) if !value.nil? &&
                                                     !(array.include? value.to_i) &&
                                                     !(array.include? value.to_i)
end