Class: FlexValidations::Predicate
- Inherits:
-
Object
- Object
- FlexValidations::Predicate
- Includes:
- Validation
- Defined in:
- lib/flex_validations/predicate.rb
Overview
Call predicate on object
Defined Under Namespace
Classes: FailedMessage, NotRespondMessage, SuccessMessage
Instance Method Summary collapse
-
#initialize(method, *args) ⇒ Predicate
constructor
A new instance of Predicate.
- #to_s ⇒ String
- #validate(value) ⇒ FlexValidations::Result
Methods included from Validation
Constructor Details
#initialize(method, *args) ⇒ Predicate
Returns a new instance of Predicate.
28 29 30 31 |
# File 'lib/flex_validations/predicate.rb', line 28 def initialize(method, *args) @method = method @args = args end |
Instance Method Details
#to_s ⇒ String
47 48 49 50 51 |
# File 'lib/flex_validations/predicate.rb', line 47 def to_s args = "(#{@args.map(&:inspect).join(', ')})" if @args.length > 0 "value.#{@method}#{args} should succeed" end |
#validate(value) ⇒ FlexValidations::Result
36 37 38 39 40 41 42 43 44 |
# File 'lib/flex_validations/predicate.rb', line 36 def validate(value) return not_respond(value) unless value.respond_to?(@method, false) ret = value.public_send(@method, *@args) return failed(value, ret) unless ret success(value, ret) end |