123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Clients::Validators::Storage

Relationships & Source Files
Defined in: lib/mongoid/clients/validators/storage.rb

Overview

Validates the options passed to :store_in.

Constant Summary

Instance Method Summary

Instance Method Details

#valid_keys?(options) ⇒ true | false (private)

This method is for internal use only.

Determine if all keys in the options hash are valid.

Examples:

Are all keys valid?

validator.valid_keys?({ collection: "name" })

Parameters:

  • options (Hash)

    The options hash.

Returns:

  • (true | false)

    If all keys are valid.

[ GitHub ]

  
# File 'lib/mongoid/clients/validators/storage.rb', line 38

def valid_keys?(options)
  return false unless options.is_a?(::Hash)
  options.keys.all? do |key|
    VALID_OPTIONS.include?(key)
  end
end

#validate(klass, options)

Validate the options provided to :store_in.

Examples:

Validate the options.

Storage.validate(:collection_name)

Parameters:

  • klass (Class)

    The model class.

  • options (Hash | String | Symbol)

    The provided options.

[ GitHub ]

  
# File 'lib/mongoid/clients/validators/storage.rb', line 22

def validate(klass, options)
  valid_keys?(options) or raise Errors::InvalidStorageOptions.new(klass, options)
end