Sha256: 3e974981c359e2a1fc66c358179e8fccfd3a9d2a6fdb0c90c84b61aa43e56f64
Contents?: true
Size: 1.27 KB
Versions: 11
Compression:
Stored size: 1.27 KB
Contents
# frozen_string_literal: true module Mongoid module Clients module Validators # Validates the options passed to :store_in. module Storage extend self # The valid options for storage. VALID_OPTIONS = [ :collection, :collection_options, :database, :client ].freeze # 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. def validate(klass, options) valid_keys?(options) or raise Errors::InvalidStorageOptions.new(klass, options) end private # 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. def valid_keys?(options) return false unless options.is_a?(::Hash) options.keys.all? do |key| VALID_OPTIONS.include?(key) end end end end end end
Version data entries
11 entries across 11 versions & 1 rubygems