Module: ActiveModel::Validations::ClassMethods
- Defined in:
- lib/validates_type.rb
Instance Method Summary collapse
-
#validates_type(attribute_name, attribute_type, options = {}) ⇒ Object
Validates the type of an attribute with supported types: - :array - :boolean - :float - :hash - :integer - :string - :symbol - :time - :date.
Instance Method Details
#validates_type(attribute_name, attribute_type, options = {}) ⇒ Object
Validates the type of an attribute with supported types:
- :array
- :boolean
- :float
- :hash
- :integer
- :string
- :symbol
- :time
- :date
class Foo
include ActiveModel::Validations
attr_accessor :thing, :something
validates_type :thing, :boolean
validates_type :something, :array
end
138 139 140 141 |
# File 'lib/validates_type.rb', line 138 def validates_type(attribute_name, attribute_type, = {}) args = ValidatesType::Arguments.new(attribute_name, attribute_type, ) validates_with TypeValidator, _merge_attributes(args.to_validation_attributes) end |