class BehaviorValidator

Constants

VERSION

Public Class Methods

reserved_options() click to toggle source
# File lib/behavior_validator.rb, line 10
def reserved_options
  [:allow_nil, :allow_blank, :message, :on, :if, :unless]
end
valid?(value, options = {}) click to toggle source
# File lib/behavior_validator.rb, line 3
def valid?(value, options = {})
  options = options.reject { |option| reserved_options.include?(option) }
  options.each_pair.all? do |method, expected_result|
    value.respond_to?(method) && value.__send__(method) == expected_result
  end
end

Public Instance Methods

validate_each(record, attribute, value) click to toggle source
# File lib/behavior_validator.rb, line 15
def validate_each(record, attribute, value)
  unless self.class.valid?(value, options)
    record.errors.add(attribute, options[:message] || :invalid_behavior)
  end
end