Class: FlexValidations::Call
- Inherits:
-
Object
- Object
- FlexValidations::Call
- Includes:
- Validation
- Defined in:
- lib/flex_validations/call.rb
Defined Under Namespace
Classes: FailedMessage, NotRespondMessage, SuccessMessage
Instance Method Summary collapse
-
#initialize(method, *args) ⇒ Call
constructor
A new instance of Call.
- #to_s ⇒ String
- #validate(value) ⇒ FlexValidations::Result
Methods included from Validation
Constructor Details
#initialize(method, *args) ⇒ Call
Returns a new instance of Call.
7 8 9 10 |
# File 'lib/flex_validations/call.rb', line 7 def initialize(method, *args) @method = method @args = args end |
Instance Method Details
#to_s ⇒ String
27 28 29 30 31 |
# File 'lib/flex_validations/call.rb', line 27 def to_s args = "(#{@args.map(&:inspect).join(', ')})" if @args.length > 0 "value.#{@method}#{args} should not raise error" end |
#validate(value) ⇒ FlexValidations::Result
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/flex_validations/call.rb', line 15 def validate(value) return not_respond(value) unless value.respond_to?(@method, false) begin ret = value.public_send(@method, *@args) success(value, ret) rescue => e failed(value, e) end end |