Sha256: 6531188d11591b355ace7743b76601ad0f8b4c9ba02a8cfba6db5a4ae98b35b5

Contents?: true

Size: 1.25 KB

Versions: 36

Compression:

Stored size: 1.25 KB

Contents

# encoding: utf-8
module Mongoid
  module Sessions
    module Validators

      # Validates the options passed to :store_in.
      module Storage
        extend self

        VALID_OPTIONS = [ :collection, :database, :session ]

        # 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
        def validate(klass, options)
          if !options.is_a?(::Hash) || !valid_keys?(options)
            raise Errors::InvalidStorageOptions.new(klass, options)
          end
        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.
        #
        # @since 3.0.0
        def valid_keys?(options)
          options.keys.all? do |key|
            VALID_OPTIONS.include?(key)
          end
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 5 rubygems

Version Path
mongoid-3.1.7 lib/mongoid/sessions/validators/storage.rb
mongoid-3.1.6 lib/mongoid/sessions/validators/storage.rb
sepastian-mongoid-rails4-4.0.1.alpha lib/mongoid/sessions/validators/storage.rb
sepastian-mongoid-rails4-4.0.0.alpha lib/mongoid/sessions/validators/storage.rb
mongoid-3.1.5 lib/mongoid/sessions/validators/storage.rb
mongoid_heroku_stable-4.0.0 lib/mongoid/sessions/validators/storage.rb
mongoid_rails4-4.0.0 lib/mongoid/sessions/validators/storage.rb
mongoid-3.1.4 lib/mongoid/sessions/validators/storage.rb
mongoid-3.1.3 lib/mongoid/sessions/validators/storage.rb
mongoid-3.1.2 lib/mongoid/sessions/validators/storage.rb
mongoid-3.0.23 lib/mongoid/sessions/validators/storage.rb
mongoid-3.1.1 lib/mongoid/sessions/validators/storage.rb
mongoid-3.1.0 lib/mongoid/sessions/validators/storage.rb
mongoid-3.0.22 lib/mongoid/sessions/validators/storage.rb
mongoid-3.0.21 lib/mongoid/sessions/validators/storage.rb
mongoid-3.0.20 lib/mongoid/sessions/validators/storage.rb
mongoid-3.0.19 lib/mongoid/sessions/validators/storage.rb
mongoid-3.0.18 lib/mongoid/sessions/validators/storage.rb
mongoid-3.0.17 lib/mongoid/sessions/validators/storage.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.16/lib/mongoid/sessions/validators/storage.rb