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_options ⇒ Object
Returns the value of attribute faraday_options.
-
#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
-
#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.
21 22 23 24 25 26 27 28 |
# File 'lib/solr/configuration.rb', line 21 def initialize @faraday_options = { request: { timeout: 2, open_timeout: 8 }, headers: SOLRB_USER_AGENT_HEADER } @cores = {} @cloud_configuration = Solr::Cloud::Configuration.new end |
Instance Attribute Details
#auth_password ⇒ Object
Returns the value of attribute auth_password.
17 18 19 |
# File 'lib/solr/configuration.rb', line 17 def auth_password @auth_password end |
#auth_user ⇒ Object
Returns the value of attribute auth_user.
17 18 19 |
# File 'lib/solr/configuration.rb', line 17 def auth_user @auth_user end |
#cloud_configuration ⇒ Object (readonly)
Returns the value of attribute cloud_configuration.
19 20 21 |
# File 'lib/solr/configuration.rb', line 19 def cloud_configuration @cloud_configuration end |
#cores ⇒ Object
Returns the value of attribute cores.
17 18 19 |
# File 'lib/solr/configuration.rb', line 17 def cores @cores end |
#faraday_options ⇒ Object
Returns the value of attribute faraday_options.
19 20 21 |
# File 'lib/solr/configuration.rb', line 19 def @faraday_options end |
#test_connection ⇒ Object
Returns the value of attribute test_connection.
17 18 19 |
# File 'lib/solr/configuration.rb', line 17 def test_connection @test_connection end |
#url ⇒ Object
Returns the value of attribute url.
19 20 21 |
# File 'lib/solr/configuration.rb', line 19 def url @url end |
Instance Method Details
#build_env_url_core_config(name: nil) ⇒ Object
77 78 79 80 |
# File 'lib/solr/configuration.rb', line 77 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
40 41 42 |
# File 'lib/solr/configuration.rb', line 40 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
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/solr/configuration.rb', line 66 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
44 45 46 47 48 49 |
# File 'lib/solr/configuration.rb', line 44 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
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/solr/configuration.rb', line 51 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 |
#validate! ⇒ Object
89 90 91 92 93 |
# File 'lib/solr/configuration.rb', line 89 def validate! if !(url || @cloud_configuration.zookeeper_url || ENV['SOLR_URL']) raise Solr::Errors::SolrUrlNotDefinedError end end |
#validate_default_core_config!(default:) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/solr/configuration.rb', line 82 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 |