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

COMMON =

These options are available to all relations.

[
  :class_name,
  :counter_cache,
  :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



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

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
  true
end