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.3.7 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/options.rb
classiccms-0.3.7 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/options.rb
classiccms-0.3.7 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/options.rb
classiccms-0.3.6 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/options.rb
classiccms-0.3.6 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/options.rb
classiccms-0.3.6 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/options.rb
classiccms-0.3.5 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/options.rb
classiccms-0.3.5 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/options.rb
classiccms-0.3.5 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/options.rb
mongoid-2.4.11 lib/mongoid/relations/options.rb
classiccms-0.3.4 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/options.rb
classiccms-0.3.4 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/options.rb
classiccms-0.3.4 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/options.rb
classiccms-0.3.3 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/options.rb
classiccms-0.3.3 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/options.rb
classiccms-0.3.3 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/options.rb
classiccms-0.3.2 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/options.rb
classiccms-0.3.2 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/options.rb
classiccms-0.3.2 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/options.rb
classiccms-0.3.1 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/options.rb