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 =
# File 'lib/mongoid/config/validators/client.rb', line 11
Standard configuration options.
%i[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 19
def validate(clients) raise Errors::NoDefaultClient.new(clients.keys) unless clients.has_key?(:default) 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 40
def validate_client_database(name, config) return unless no_database_or_uri?(config) raise Errors::NoClientDatabase.new(name, config) end
#validate_client_hosts(name, config) (private)
Validate that the client config has hosts.
# File 'lib/mongoid/config/validators/client.rb', line 55
def validate_client_hosts(name, config) return unless no_hosts_or_uri?(config) raise Errors::NoClientHosts.new(name, config) 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 71
def validate_client_uri(name, config) return unless both_uri_and_standard?(config) raise Errors::MixedClientConfiguration.new(name, config) end