Module: Mongoid::Relations::Options

Extended by:
Options
Included in:
Options
Defined in:
lib/mongoid/relations/options.rb

Overview

This module contains the validating logic for options passed to relation macros.

Constant Summary collapse

COMMON =

These options are available to all relations.

[
  :class_name,
  :extend,
  :inverse_class_name,
  :inverse_of,
  :name,
  :relation,
  :validate
]

Instance Method Summary collapse

Instance Method Details

#validate!(options) ⇒ true, false

Determine if the provided options are valid for the relation.

Examples:

Check the options.

Options.validate!(:name => :comments)

Parameters:

  • options (Hash)

    The options to check.

Returns:

  • (true, false)

    If the options are valid.

Raises:

  • (ArgumentError)

    If the options are invalid.

Since:

  • 2.1.0



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mongoid/relations/options.rb', line 33

def validate!(options)
  valid_options = options[:relation].valid_options.concat(COMMON)
  options.keys.each do |key|
    if !valid_options.include?(key)
      raise Errors::InvalidOptions.new(
        options[:name],
        key,
        valid_options
      )
    end
  end
end