Module: Mongoid::Fields::Validators::Macro
Overview
Validates the params passed to the field macro.
Constant Summary collapse
- OPTIONS =
[ :as, :default, :identity, :label, :localize, :fallbacks, :association, :pre_processed, :subtype, :type, :overwrite, :encrypt ]
Instance Method Summary collapse
-
#validate(klass, name, options) ⇒ Object
Validate the field definition.
-
#validate_field_name(klass, name) ⇒ Object
private
Determine if the field name is valid, if not raise an error.
-
#validate_relation(klass, name, options = {}) ⇒ Object
Validate the association definition.
Instance Method Details
#validate(klass, name, options) ⇒ Object
Validate the field definition.
35 36 37 38 39 |
# File 'lib/mongoid/fields/validators/macro.rb', line 35 def validate(klass, name, ) validate_field_name(klass, name) validate_name_uniqueness(klass, name, ) (klass, name, ) end |
#validate_field_name(klass, name) ⇒ Object
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 if the field name is valid, if not raise an error.
68 69 70 71 72 73 74 |
# File 'lib/mongoid/fields/validators/macro.rb', line 68 def validate_field_name(klass, name) [name, "#{name}?".to_sym, "#{name}=".to_sym].each do |n| if Mongoid.destructive_fields.include?(n) raise Errors::InvalidField.new(klass, name, n) end end end |
#validate_relation(klass, name, options = {}) ⇒ Object
Validate the association definition.
49 50 51 52 53 54 55 |
# File 'lib/mongoid/fields/validators/macro.rb', line 49 def validate_relation(klass, name, = {}) [name, "#{name}?".to_sym, "#{name}=".to_sym].each do |n| if Mongoid.destructive_fields.include?(n) raise Errors::InvalidRelation.new(klass, n) end end end |