Class: Interdependence::Types::ValidatorClassCoercer

Inherits:
Object
  • Object
show all
Defined in:
lib/interdependence/types.rb

Overview

Coerce and validate that an argument is an ActiveModel::Validator

Class Method Summary collapse

Class Method Details

.call(value) ⇒ value passed in

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

returns value given so that success can test it

Returns:

  • (value passed in)


181
182
183
# File 'lib/interdependence/types.rb', line 181

def self.call(value)
  value
end

.success?(primitive, value) ⇒ TrueClass, FalseClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Determine whether a validator class is valid

Parameters:

  • primitive (Class)
    primitive class expected
  • value (coerced value)

Returns:

  • (TrueClass, FalseClass)
    outcome


194
195
196
# File 'lib/interdependence/types.rb', line 194

def self.success?(primitive, value)
  value.instance_of?(primitive) && value.ancestors.include?(::ActiveModel::Validator)
end