#-- # gravaty # Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani # # This file is part of gravaty. # # gravaty is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation, either version 3 of the License, or (at your # option) any later version. # # gravaty is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License # along with gravaty. If not, see . #++ require 'i18n' module Gravaty # This module is a simple collection of useful things and methods that # I prefer to keep as DRYer as possible. Just include it and use the # methods... # # Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it] # Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018, # 2019 Marco Bresciani # License:: GNU General Public License version 3 module Utils # This module contains some utility method to raise errors according # to (possibly) common conditions. # # Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it] # Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018, # 2019 Marco Bresciani # License:: GNU General Public License version 3 module Raisers # Raises an +ArgumentError+ according to parameters, unless the # +array+ contains a downcased +value+. def raiser_downcase(name = 'error.value', value = nil, array = nil) unless value.nil? raise ArgumentError, I18n.t(name, value: value) unless array.include? value.downcase end end # Raises an +ArgumentError+ according to parameters, unless the # +array+ contains the number of the +value+. def raiser_to_i(name = 'error.value', value = nil, array = nil) unless value.nil? raise ArgumentError, I18n.t(name, value: value) unless array.include? value.to_i end end end end end