Class: ThinkingSphinx::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/thinking_sphinx/settings.rb

Constant Summary collapse

ALWAYS_ABSOLUTE =
%w[ socket ]
FILE_KEYS =
%w[
  indices_location configuration_file bin_path log query_log pid_file
  binlog_path snippets_file_prefix sphinxql_state path stopwords wordforms
  exceptions global_idf rlp_context rlp_root rlp_environment plugin_dir
  lemmatizer_base mysql_ssl_cert mysql_ssl_key mysql_ssl_ca
].freeze
DEFAULTS =
{
  "configuration_file"       => "config/ENVIRONMENT.sphinx.conf",
  "indices_location"         => "db/sphinx/ENVIRONMENT",
  "pid_file"                 => "log/ENVIRONMENT.sphinx.pid",
  "log"                      => "log/ENVIRONMENT.searchd.log",
  "query_log"                => "log/ENVIRONMENT.searchd.query.log",
  "binlog_path"              => "tmp/binlog/ENVIRONMENT",
  "workers"                  => "threads",
  "mysql_encoding"           => "utf8",
  "maximum_statement_length" => (2 ** 23) - 5,
  "real_time_tidy"           => false,
  "cutoff"                   => 0
}.freeze
YAML_SAFE_LOAD =
YAML.method(:safe_load).parameters.any? do |parameter|
  parameter == [:key, :aliases]
end

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Settings

Returns a new instance of Settings.



34
35
36
# File 'lib/thinking_sphinx/settings.rb', line 34

def initialize(configuration)
  @configuration = configuration
end

Class Method Details

.call(configuration) ⇒ Object



30
31
32
# File 'lib/thinking_sphinx/settings.rb', line 30

def self.call(configuration)
  new(configuration).call
end

Instance Method Details

#callObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/thinking_sphinx/settings.rb', line 38

def call
  return defaults unless File.exist? file

  merged.inject({}) do |hash, (key, value)|
    if absolute_key?(key)
      hash[key] = absolute value
    else
      hash[key] = value
    end
    hash
  end
end