Module: ArrayValidator::OrderValidator
- Defined in:
- lib/array_validator/order_validator.rb
Class Method Summary collapse
Class Method Details
.call(record, attribute, values, options) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/array_validator/order_validator.rb', line 3 def self.call(record, attribute, values, ) return if [:order].nil? raise ArgumentError, 'Not a supported order option' unless [:asc, :desc].include?([:order]) ordered = if [: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: "#{[:order]}ending") ) end |