Sha256: 6f33bf3a1fccff7f50a579b85f156776854d60c4261e402d61b4ca766f749973

Contents?: true

Size: 1.15 KB

Versions: 188

Compression:

Stored size: 1.15 KB

Contents

# encoding: utf-8
module Mongoid # :nodoc:
  module Relations #:nodoc:

    # This module contains the validating logic for options passed to relation
    # macros.
    module Options
      extend self

      # These options are available to all relations.
      COMMON = [
        :class_name,
        :extend,
        :inverse_class_name,
        :inverse_of,
        :name,
        :relation,
        :validate
      ]

      # Determine if the provided options are valid for the relation.
      #
      # @example Check the options.
      #   Options.validate!(:name => :comments)
      #
      # @param [ Hash ] options The options to check.
      #
      # @raise [ ArgumentError ] If the options are invalid.
      #
      # @return [ true, false ] If the options are valid.
      #
      # @since 2.1.0
      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
    end
  end
end

Version data entries

188 entries across 96 versions & 4 rubygems

Version Path
classiccms-0.5.9 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/options.rb
classiccms-0.5.9 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/options.rb
classiccms-0.5.9 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/options.rb
classiccms-0.5.8 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/options.rb
classiccms-0.5.8 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/options.rb
classiccms-0.5.8 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/options.rb
classiccms-0.5.7 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/options.rb
classiccms-0.5.7 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/options.rb
classiccms-0.5.7 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/options.rb
classiccms-0.5.6 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/options.rb
classiccms-0.5.6 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/options.rb
classiccms-0.5.6 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/options.rb
classiccms-0.5.5 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/options.rb
classiccms-0.5.5 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/options.rb
classiccms-0.5.5 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/options.rb
classiccms-0.5.2 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/options.rb
classiccms-0.5.2 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/options.rb
classiccms-0.5.2 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/options.rb
classiccms-0.5.1 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/options.rb
classiccms-0.5.1 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/options.rb