Module: Mongoid::Config::Validators::Client
Relationships & Source Files | |
Defined in: | lib/mongoid/config/validators/client.rb |
Overview
Validator for client specific configuration.
Constant Summary
-
STANDARD =
Standard configuration options.
[ :database, :hosts, :username, :password ].freeze
Instance Method Summary
-
#validate(clients)
Validate the client configuration.
-
#both_uri_and_standard?(config) ⇒ true | false
private
Internal use only
Internal use only
Return true if the configuration has both standard options and a uri defined.
-
#no_database_or_uri?(config) ⇒ true | false
private
Internal use only
Internal use only
Return true if the configuration has no database or uri option defined.
-
#no_hosts_or_uri?(config) ⇒ true | false
private
Internal use only
Internal use only
Return true if the configuration has no hosts or uri option defined.
-
#validate_client_database(name, config)
private
Internal use only
Internal use only
Validate that the client config has database.
-
#validate_client_hosts(name, config)
private
Internal use only
Internal use only
Validate that the client config has hosts.
-
#validate_client_uri(name, config)
private
Internal use only
Internal use only
Validate that not both a uri and standard options are provided for a single client.
Instance Method Details
#both_uri_and_standard?(config) ⇒ true
| false
(private)
Return true if the configuration has both standard options and a uri defined.
#no_database_or_uri?(config) ⇒ true
| false
(private)
Return true if the configuration has no database or uri option defined.
#no_hosts_or_uri?(config) ⇒ true
| false
(private)
Return true if the configuration has no hosts or uri option defined.
#validate(clients)
Validate the client configuration.
# File 'lib/mongoid/config/validators/client.rb', line 21
def validate(clients) unless clients.has_key?(:default) raise Errors::NoDefaultClient.new(clients.keys) end clients.each_pair do |name, config| validate_client_database(name, config) validate_client_hosts(name, config) validate_client_uri(name, config) end end
#validate_client_database(name, config) (private)
Validate that the client config has database.
# File 'lib/mongoid/config/validators/client.rb', line 43
def validate_client_database(name, config) if no_database_or_uri?(config) raise Errors::NoClientDatabase.new(name, config) end end
#validate_client_hosts(name, config) (private)
Validate that the client config has hosts.
# File 'lib/mongoid/config/validators/client.rb', line 58
def validate_client_hosts(name, config) if no_hosts_or_uri?(config) raise Errors::NoClientHosts.new(name, config) end end
#validate_client_uri(name, config) (private)
Validate that not both a uri and standard options are provided for a single client.
# File 'lib/mongoid/config/validators/client.rb', line 74
def validate_client_uri(name, config) if both_uri_and_standard?(config) raise Errors::MixedClientConfiguration.new(name, config) end end