Class: Sunspot::Solr::Installer::ConfigInstaller

Inherits:
Object
  • Object
show all
Includes:
TaskHelper
Defined in:
sunspot_solr/lib/sunspot/solr/installer/config_installer.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from TaskHelper

#say

Constructor Details

- (ConfigInstaller) initialize(config_path, options)

A new instance of ConfigInstaller



15
16
17
18
19
# File 'sunspot_solr/lib/sunspot/solr/installer/config_installer.rb', line 15

def initialize(config_path, options)
  @config_path = config_path
  @verbose = !!options[:verbose]
  @force   = !!options[:force]
end

Class Method Details

+ (Object) execute(config_path, options = {})



10
11
12
# File 'sunspot_solr/lib/sunspot/solr/installer/config_installer.rb', line 10

def execute(config_path, options = {})
  new(config_path, options).execute
end

Instance Method Details

- (Object) execute



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'sunspot_solr/lib/sunspot/solr/installer/config_installer.rb', line 21

def execute
  sunspot_config_path = File.join(File.dirname(__FILE__), '..', '..',
                                  '..', '..', 'solr', 'solr', 'conf')
  return if File.expand_path(sunspot_config_path) == File.expand_path(@config_path)

  FileUtils.mkdir_p(@config_path)
  Dir.glob(File.join(sunspot_config_path, '*.*')).each do |file|
    file = File.expand_path(file)
    dest = File.join(@config_path, File.basename(file))

    if File.exist?(dest)
      if @force
        say("Removing existing file #{dest}")
      else
        next
      end
    end

    say("Copying #{file} => #{dest}")
    FileUtils.cp(file, dest)
  end
end