module ArrayValidator::OrderValidator
Public Class Methods
call(record, attribute, values, options)
click to toggle source
# File lib/array_validator/order_validator.rb, line 3 def self.call(record, attribute, values, options) return if options[:order].nil? raise ArgumentError, 'Not a supported order option' unless [:asc, :desc].include?(options[:order]) ordered = if options[:order] == :asc values.sort == values else values.sort.reverse == values end return if ordered record.errors[attribute].push( I18n.t('order', scope: I18N_SCOPE, direction: "#{options[:order]}ending") ) end