module Mongoid::Clients::Validators::Storage
Validates the options passed to :store_in.
Constants
- VALID_OPTIONS
The valid options for storage.
@since 3.0.0
Public Instance Methods
validate(klass, options)
click to toggle source
Validate the options provided to :store_in.
@example Validate the options.
Storage.validate(:collection_name)
@param [ Class ] klass The model class. @param [ Hash, String, Symbol ] options The provided options.
@since 3.0.0
# File lib/mongoid/clients/validators/storage.rb, line 26 def validate(klass, options) valid_keys?(options) or raise Errors::InvalidStorageOptions.new(klass, options) valid_parent?(klass) or raise Errors::InvalidStorageParent.new(klass) end
Private Instance Methods
valid_keys?(options)
click to toggle source
Determine if all keys in the options hash are valid.
@api private
@example Are all keys valid?
validator.valid_keys?({ collection: "name" })
@param [ Hash ] options The options hash.
@return [ true, false ] If all keys are valid.
@since 3.0.0
# File lib/mongoid/clients/validators/storage.rb, line 58 def valid_keys?(options) return false unless options.is_a?(::Hash) options.keys.all? do |key| VALID_OPTIONS.include?(key) end end
valid_parent?(klass)
click to toggle source
Determine if the current klass is valid to change store_in options
@api private
@param [ Class ] klass
@return [ true, false ] If the class is valid
@since 4.0.0
# File lib/mongoid/clients/validators/storage.rb, line 42 def valid_parent?(klass) !klass.superclass.include?(Mongoid::Document) end