Class: Solr::Configuration
- Inherits:
-
Object
- Object
- Solr::Configuration
- Extended by:
- Forwardable
- Defined in:
- lib/solr/configuration.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#auth_password ⇒ Object
Returns the value of attribute auth_password.
-
#auth_user ⇒ Object
Returns the value of attribute auth_user.
-
#cloud_configuration ⇒ Object
readonly
Returns the value of attribute cloud_configuration.
-
#cores ⇒ Object
Returns the value of attribute cores.
-
#faraday_configuration ⇒ Object
readonly
Returns the value of attribute faraday_configuration.
-
#faraday_options ⇒ Object
Returns the value of attribute faraday_options.
- #logger ⇒ Object
-
#master_slave_configuration ⇒ Object
readonly
Returns the value of attribute master_slave_configuration.
-
#test_connection ⇒ Object
Returns the value of attribute test_connection.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #build_env_url_core_config(name: nil) ⇒ Object
- #core_config_by_name(core) ⇒ Object
- #core_name_from_solr_url_env ⇒ Object
- #default_core_config ⇒ Object
- #define_core(name: nil, default: false) {|builder| ... } ⇒ Object
- #faraday_configure(&block) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #validate! ⇒ Object
- #validate_default_core_config!(default:) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/solr/configuration.rb', line 28 def initialize @faraday_options = { request: { timeout: 2, open_timeout: 8 }, headers: SOLRB_USER_AGENT_HEADER } @faraday_configuration = nil @cores = {} @cloud_configuration = Solr::Cloud::Configuration.new @master_slave_configuration = Solr::MasterSlave::Configuration.new end |
Instance Attribute Details
#auth_password ⇒ Object
Returns the value of attribute auth_password.
21 22 23 |
# File 'lib/solr/configuration.rb', line 21 def auth_password @auth_password end |
#auth_user ⇒ Object
Returns the value of attribute auth_user.
21 22 23 |
# File 'lib/solr/configuration.rb', line 21 def auth_user @auth_user end |
#cloud_configuration ⇒ Object (readonly)
Returns the value of attribute cloud_configuration.
23 24 25 |
# File 'lib/solr/configuration.rb', line 23 def cloud_configuration @cloud_configuration end |
#cores ⇒ Object
Returns the value of attribute cores.
21 22 23 |
# File 'lib/solr/configuration.rb', line 21 def cores @cores end |
#faraday_configuration ⇒ Object (readonly)
Returns the value of attribute faraday_configuration.
23 24 25 |
# File 'lib/solr/configuration.rb', line 23 def faraday_configuration @faraday_configuration end |
#faraday_options ⇒ Object
Returns the value of attribute faraday_options.
23 24 25 |
# File 'lib/solr/configuration.rb', line 23 def @faraday_options end |
#logger ⇒ Object
100 101 102 |
# File 'lib/solr/configuration.rb', line 100 def logger @logger || null_logger end |
#master_slave_configuration ⇒ Object (readonly)
Returns the value of attribute master_slave_configuration.
23 24 25 |
# File 'lib/solr/configuration.rb', line 23 def master_slave_configuration @master_slave_configuration end |
#test_connection ⇒ Object
Returns the value of attribute test_connection.
21 22 23 |
# File 'lib/solr/configuration.rb', line 21 def test_connection @test_connection end |
#url ⇒ Object
Returns the value of attribute url.
23 24 25 |
# File 'lib/solr/configuration.rb', line 23 def url @url end |
Instance Method Details
#build_env_url_core_config(name: nil) ⇒ Object
79 80 81 82 |
# File 'lib/solr/configuration.rb', line 79 def build_env_url_core_config(name: nil) name ||= core_name_from_solr_url_env Solr::CoreConfiguration::EnvUrlCoreConfig.new(name: name) end |
#core_config_by_name(core) ⇒ Object
49 50 51 |
# File 'lib/solr/configuration.rb', line 49 def core_config_by_name(core) cores[core.to_sym] || build_env_url_core_config(name: core) end |
#core_name_from_solr_url_env ⇒ Object
75 76 77 |
# File 'lib/solr/configuration.rb', line 75 def core_name_from_solr_url_env Solr::Support::UrlHelper.core_name_from_url(ENV['SOLR_URL']) end |
#default_core_config ⇒ Object
53 54 55 56 57 58 |
# File 'lib/solr/configuration.rb', line 53 def default_core_config defined_default_core_config = cores.values.detect(&:default?) return defined_default_core_config if defined_default_core_config raise Solr::Errors::AmbiguousCoreError if cores.count > 1 cores.values.first || build_env_url_core_config end |
#define_core(name: nil, default: false) {|builder| ... } ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/solr/configuration.rb', line 60 def define_core(name: nil, default: false) validate_default_core_config!(default: default) builder = Solr::CoreConfiguration::CoreConfigBuilder.new( name: name, default: default ) yield builder core = builder.build if cores.has_key?(core.name) raise "A core with name '#{core.name}' has been already defined" else cores[core.name] = core end end |
#faraday_configure(&block) ⇒ Object
45 46 47 |
# File 'lib/solr/configuration.rb', line 45 def faraday_configure(&block) @faraday_configuration = block end |
#validate! ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/solr/configuration.rb', line 91 def validate! if !(url || @cloud_configuration.zookeeper_url || (@master_slave_configuration.master_url && @master_slave_configuration.slave_url) || ENV['SOLR_URL']) raise Solr::Errors::SolrUrlNotDefinedError end end |
#validate_default_core_config!(default:) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/solr/configuration.rb', line 84 def validate_default_core_config!(default:) return unless default if cores.any? { |name, core_config| core_config.default? } raise ArgumentError, 'Only one default core can be specified' end end |