Class: Solr::Configuration

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/solr/configuration.rb

Constant Summary collapse

SOLRB_USER_AGENT_HEADER =
{ user_agent: "Solrb v#{Solr::VERSION}" }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_passwordObject

Returns the value of attribute auth_password.



21
22
23
# File 'lib/solr/configuration.rb', line 21

def auth_password
  @auth_password
end

#auth_userObject

Returns the value of attribute auth_user.



21
22
23
# File 'lib/solr/configuration.rb', line 21

def auth_user
  @auth_user
end

#cloud_configurationObject (readonly)

Returns the value of attribute cloud_configuration.



23
24
25
# File 'lib/solr/configuration.rb', line 23

def cloud_configuration
  @cloud_configuration
end

#coresObject

Returns the value of attribute cores.



21
22
23
# File 'lib/solr/configuration.rb', line 21

def cores
  @cores
end

#faraday_configurationObject (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_optionsObject

Returns the value of attribute faraday_options.



23
24
25
# File 'lib/solr/configuration.rb', line 23

def faraday_options
  @faraday_options
end

#loggerObject



100
101
102
# File 'lib/solr/configuration.rb', line 100

def logger
  @logger || null_logger
end

#master_slave_configurationObject (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_connectionObject

Returns the value of attribute test_connection.



21
22
23
# File 'lib/solr/configuration.rb', line 21

def test_connection
  @test_connection
end

#urlObject

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_envObject



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_configObject



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

Yields:

  • (builder)


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