class Sunspot::Solr::Installer

Attributes

config_path[R]
options[R]

Public Class Methods

execute(solr_home, options = {}) click to toggle source
# File lib/sunspot/solr/installer.rb, line 8
def execute(solr_home, options = {})
  new(Pathname(solr_home).expand_path, options).execute
end
new(config_path, options) click to toggle source
# File lib/sunspot/solr/installer.rb, line 21
def initialize(config_path, options)
  @config_path = config_path
  @options     = options
end

Public Instance Methods

config_source_files() click to toggle source
# File lib/sunspot/solr/installer.rb, line 60
def config_source_files
  @config_source_files ||= glob_source_files
end
execute() click to toggle source
# File lib/sunspot/solr/installer.rb, line 34
def execute
  return if sunspot_config_path == config_path

  config_source_files.each do |source_path|
    destination_path = get_destination_path(source_path)

    if destination_path.exist?
      next unless force?
      output "Removing existing file #{ destination_path }"
    end

    destination_dir = destination_path.dirname
    unless destination_dir.exist?
      output "Creating directory #{ destination_dir }"
      destination_dir.mkpath
    end

    output "Copying #{ source_path } => #{ destination_path }"
    FileUtils.copy(source_path, destination_path)
  end
end
force?() click to toggle source
# File lib/sunspot/solr/installer.rb, line 26
def force?
  !!@options[:force]
end
sunspot_config_path() click to toggle source
# File lib/sunspot/solr/installer.rb, line 56
def sunspot_config_path
  @sunspot_config_path ||= Pathname(__FILE__).join("../../../../solr/solr")
end
verbose?() click to toggle source
# File lib/sunspot/solr/installer.rb, line 30
def verbose?
  !!@options[:verbose]
end

Private Instance Methods

get_destination_path(source_path) click to toggle source
# File lib/sunspot/solr/installer.rb, line 66
def get_destination_path(source_path)
  source_path.sub(sunspot_config_path.to_s, config_path.to_s)
end
glob_source_files() click to toggle source
# File lib/sunspot/solr/installer.rb, line 70
def glob_source_files
  source_files = []
  source_files += Pathname.glob(sunspot_config_path.join("solr.xml"))
  source_files += Pathname.glob(sunspot_config_path.join("configsets/**/*"))
  source_files += Pathname.glob(sunspot_config_path.join("**/core.properties"))
  source_files.select(&:file?).map(&:expand_path)
end
output(message) click to toggle source
# File lib/sunspot/solr/installer.rb, line 78
def output message
  STDOUT.puts(message) if verbose?
end