Class: ThinkingSphinx::Configuration

Inherits:
Riddle::Configuration
  • Object
show all
Defined in:
lib/thinking_sphinx/configuration.rb

Defined Under Namespace

Modules: Defaults Classes: ConsistentIds

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration



10
11
12
13
14
# File 'lib/thinking_sphinx/configuration.rb', line 10

def initialize
  super

  setup
end

Instance Attribute Details

#configuration_fileObject

Returns the value of attribute configuration_file



4
5
6
# File 'lib/thinking_sphinx/configuration.rb', line 4

def configuration_file
  @configuration_file
end

#controllerObject



28
29
30
31
32
33
34
# File 'lib/thinking_sphinx/configuration.rb', line 28

def controller
  @controller ||= begin
    rc = Riddle::Controller.new self, configuration_file
    rc.bin_path = bin_path.gsub(/([^\/])$/, '\1/') if bin_path.present?
    rc
  end
end

#index_pathsObject (readonly)

Returns the value of attribute index_paths



5
6
7
# File 'lib/thinking_sphinx/configuration.rb', line 5

def index_paths
  @index_paths
end

#indices_locationObject

Returns the value of attribute indices_location



4
5
6
# File 'lib/thinking_sphinx/configuration.rb', line 4

def indices_location
  @indices_location
end

#versionObject

Returns the value of attribute version



4
5
6
# File 'lib/thinking_sphinx/configuration.rb', line 4

def version
  @version
end

Class Method Details

.instanceObject



16
17
18
# File 'lib/thinking_sphinx/configuration.rb', line 16

def self.instance
  @instance ||= new
end

.resetObject



20
21
22
# File 'lib/thinking_sphinx/configuration.rb', line 20

def self.reset
  @instance = nil
end

Instance Method Details

#bin_pathObject



24
25
26
# File 'lib/thinking_sphinx/configuration.rb', line 24

def bin_path
  settings['bin_path']
end

#engine_index_pathsObject



46
47
48
49
50
# File 'lib/thinking_sphinx/configuration.rb', line 46

def engine_index_paths
  return [] unless defined?(Rails)

  engine_indice_paths.flatten.compact
end

#engine_indice_pathsObject



52
53
54
55
56
# File 'lib/thinking_sphinx/configuration.rb', line 52

def engine_indice_paths
  Rails::Engine::Railties.engines.collect do |engine|
    engine.paths['app/indices'].existent if engine.paths['app/indices']
  end
end

#frameworkObject



36
37
38
# File 'lib/thinking_sphinx/configuration.rb', line 36

def framework
  @framework ||= ThinkingSphinx::Frameworks.current
end

#framework=(framework) ⇒ Object



40
41
42
43
44
# File 'lib/thinking_sphinx/configuration.rb', line 40

def framework=(framework)
  @framework = framework
  setup
  framework
end

#indices_for_references(*references) ⇒ Object



58
59
60
61
# File 'lib/thinking_sphinx/configuration.rb', line 58

def indices_for_references(*references)
  preload_indices
  indices.select { |index| references.include?(index.reference) }
end

#next_offset(reference) ⇒ Object



63
64
65
# File 'lib/thinking_sphinx/configuration.rb', line 63

def next_offset(reference)
  @offsets[reference] ||= @offsets.keys.count
end

#preload_indicesObject



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/thinking_sphinx/configuration.rb', line 67

def preload_indices
  return if @preloaded_indices

  index_paths.each do |path|
    Dir["#{path}/**/*.rb"].each do |file|
      ActiveSupport::Dependencies.require_or_load file
    end
  end

  @preloaded_indices = true
end

#renderObject



79
80
81
82
83
84
85
# File 'lib/thinking_sphinx/configuration.rb', line 79

def render
  preload_indices

  ThinkingSphinx::Configuration::ConsistentIds.new(indices).reconcile

  super
end

#render_to_fileObject



87
88
89
90
91
# File 'lib/thinking_sphinx/configuration.rb', line 87

def render_to_file
  FileUtils.mkdir_p searchd.binlog_path

  open(configuration_file, 'w') { |file| file.write render }
end

#settingsObject



93
94
95
# File 'lib/thinking_sphinx/configuration.rb', line 93

def settings
  @settings ||= File.exists?(settings_file) ? settings_to_hash : {}
end