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.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/solr/configuration.rb', line 27 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.
20 21 22 |
# File 'lib/solr/configuration.rb', line 20 def auth_password @auth_password end |
#auth_user ⇒ Object
Returns the value of attribute auth_user.
20 21 22 |
# File 'lib/solr/configuration.rb', line 20 def auth_user @auth_user end |
#cloud_configuration ⇒ Object (readonly)
Returns the value of attribute cloud_configuration.
22 23 24 |
# File 'lib/solr/configuration.rb', line 22 def cloud_configuration @cloud_configuration end |
#cores ⇒ Object
Returns the value of attribute cores.
20 21 22 |
# File 'lib/solr/configuration.rb', line 20 def cores @cores end |
#faraday_configuration ⇒ Object (readonly)
Returns the value of attribute faraday_configuration.
22 23 24 |
# File 'lib/solr/configuration.rb', line 22 def faraday_configuration @faraday_configuration end |
#faraday_options ⇒ Object
Returns the value of attribute faraday_options.
22 23 24 |
# File 'lib/solr/configuration.rb', line 22 def @faraday_options end |
#logger ⇒ Object
106 107 108 |
# File 'lib/solr/configuration.rb', line 106 def logger @logger || null_logger end |
#master_slave_configuration ⇒ Object (readonly)
Returns the value of attribute master_slave_configuration.
22 23 24 |
# File 'lib/solr/configuration.rb', line 22 def master_slave_configuration @master_slave_configuration end |
#test_connection ⇒ Object
Returns the value of attribute test_connection.
20 21 22 |
# File 'lib/solr/configuration.rb', line 20 def test_connection @test_connection end |
#url ⇒ Object
Returns the value of attribute url.
22 23 24 |
# File 'lib/solr/configuration.rb', line 22 def url @url end |
Instance Method Details
#build_env_url_core_config(name: nil) ⇒ Object
85 86 87 88 |
# File 'lib/solr/configuration.rb', line 85 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
48 49 50 |
# File 'lib/solr/configuration.rb', line 48 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
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/solr/configuration.rb', line 74 def core_name_from_solr_url_env full_solr_core_uri = URI.parse(ENV['SOLR_URL']) core_name = full_solr_core_uri.path.gsub('/solr', '').delete('/') if !core_name || core_name == '' raise Solr::Errors::CouldNotInferImplicitCoreName end core_name end |
#default_core_config ⇒ Object
52 53 54 55 56 57 |
# File 'lib/solr/configuration.rb', line 52 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
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/solr/configuration.rb', line 59 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
44 45 46 |
# File 'lib/solr/configuration.rb', line 44 def faraday_configure(&block) @faraday_configuration = block end |
#validate! ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/solr/configuration.rb', line 97 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
90 91 92 93 94 95 |
# File 'lib/solr/configuration.rb', line 90 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 |