class RailsParam::Validator::Format

Constants

STRING_OR_TIME_TYPES
TIME_TYPES

Public Instance Methods

valid_value?() click to toggle source
# File lib/rails_param/validator/format.rb, line 4
def valid_value?
  matches_time_types? || string_in_format?
end

Private Instance Methods

error_message() click to toggle source
# File lib/rails_param/validator/format.rb, line 13
def error_message
  "Parameter #{name} must be a string if using the format validation" unless matches_string_or_time_types?
  "Parameter #{name} must match format #{options[:format]}" unless string_in_format?
end
matches_string_or_time_types?() click to toggle source
# File lib/rails_param/validator/format.rb, line 22
def matches_string_or_time_types?
  STRING_OR_TIME_TYPES.any? { |cls| value.is_a? cls }
end
matches_time_types?() click to toggle source
# File lib/rails_param/validator/format.rb, line 18
def matches_time_types?
  TIME_TYPES.any? { |cls| value.is_a? cls }
end
string_in_format?() click to toggle source
# File lib/rails_param/validator/format.rb, line 26
def string_in_format?
  value =~ options[:format] && value.kind_of?(String)
end