Class: FlexValidations::Call

Inherits:
Object
  • Object
show all
Includes:
Validation
Defined in:
lib/flex_validations/call.rb

Defined Under Namespace

Classes: FailedMessage, NotRespondMessage, SuccessMessage

Instance Method Summary collapse

Methods included from Validation

#===, #to_proc

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_sString

Returns:

  • (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

Parameters:

  • value (Object)

    Value to be validated

Returns:



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