Module: Mongoid::Fields::Validators::Macro

Extended by:
Macro
Included in:
Macro
Defined in:
build/mongoid-7.0/lib/mongoid/fields/validators/macro.rb

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
]

Instance Method Summary collapse

Instance Method Details

#validate(klass, name, options) ⇒ Object

Validate the field definition.

Examples:

Validate the field definition.

Macro.validate(Model, :name, { localized: true })

Parameters:

  • klass (Class)

    The model class.

  • name (Symbol)

    The field name.

  • options (Hash)

    The provided options.

Since:

  • 3.0.0



34
35
36
37
# File 'build/mongoid-7.0/lib/mongoid/fields/validators/macro.rb', line 34

def validate(klass, name, options)
  validate_name(klass, name, options)
  validate_options(klass, name, options)
end

#validate_relation(klass, name, options = {}) ⇒ Object

Validate the relation definition.

Examples:

Validate the relation definition.

Macro.validate(Model, :name)

Parameters:

  • klass (Class)

    The model class.

  • name (Symbol)

    The field name.

  • options (Hash) (defaults to: {})

    The provided options.

Since:

  • 6.0.0



49
50
51
52
53
54
55
# File 'build/mongoid-7.0/lib/mongoid/fields/validators/macro.rb', line 49

def validate_relation(klass, name, options = {})
  [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