Class: BehaviorValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- BehaviorValidator
- Defined in:
- lib/behavior_validator.rb,
lib/behavior_validator/engine.rb,
lib/behavior_validator/version.rb
Defined Under Namespace
Classes: Engine
Constant Summary collapse
- VERSION =
'0.0.3'
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.reserved_options ⇒ Object
10 11 12 |
# File 'lib/behavior_validator.rb', line 10 def [:allow_nil, :allow_blank, :message, :on, :if, :unless] end |
.valid?(value, options = {}) ⇒ Boolean
3 4 5 6 7 8 |
# File 'lib/behavior_validator.rb', line 3 def valid?(value, = {}) = .reject { |option| .include?(option) } .each_pair.all? do |method, expected_result| value.respond_to?(method) && value.__send__(method) == expected_result end end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
15 16 17 18 19 |
# File 'lib/behavior_validator.rb', line 15 def validate_each(record, attribute, value) unless self.class.valid?(value, ) record.errors.add(attribute, [:message] || :invalid_behavior) end end |