Sha256: 2122a52f690343052f27e5fbcb868a22d0a1422f19d32ec00535b55ee19d5a83
Contents?: true
Size: 723 Bytes
Versions: 27
Compression:
Stored size: 723 Bytes
Contents
class TelephoneNumberValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) valid_types = options.fetch(:types, []) args = [value, country(record), valid_types] record.errors.add(attribute, message) if TelephoneNumber.invalid?(*args) end def message options[:message] || :invalid end def country(record) country_option = options[:country] if country_option.is_a? Proc country_option.call(record) elsif country_option.is_a?(Symbol) || country_option.is_a?(String) # make sure its a lowercase symbol country_option.downcase.to_sym else raise ArgumentError.new('country option must be a Proc, Symbol or String') end end end
Version data entries
27 entries across 27 versions & 1 rubygems