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 - :big_decimal.
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
- :big_decimal
Also validates the type of an attribute given a custom type class constant.
class Foo
include ActiveModel::Validations
attr_accessor :thing, :something, :custom_thing
validates_type :thing, :boolean
validates_type :something, :array
validates_type :custom_thing, Custom
end
161 162 163 164 |
# File 'lib/validates_type.rb', line 161 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 |