Class: Sunspot::Installer::LibraryInstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/sunspot/installer/library_installer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(library_path, options) ⇒ LibraryInstaller

Returns a new instance of LibraryInstaller.



12
13
14
15
16
# File 'lib/sunspot/installer/library_installer.rb', line 12

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

Class Method Details

.execute(library_path, options) ⇒ Object



7
8
9
# File 'lib/sunspot/installer/library_installer.rb', line 7

def execute(library_path, options)
  new(library_path, options).execute
end

Instance Method Details

#executeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sunspot/installer/library_installer.rb', line 18

def execute
  sunspot_library_path = File.join(File.dirname(__FILE__), '..', '..',
                                   '..', 'solr', 'solr', 'lib')
  return if File.expand_path(sunspot_library_path) == File.expand_path(@library_path)
  FileUtils.mkdir_p(@library_path)
  Dir.glob(File.join(sunspot_library_path, '*.jar')).each do |jar|
    jar = File.expand_path(jar)
    dest = File.join(@library_path, File.basename(jar))
    if File.exist?(dest)
      if @force
        say("Removing existing library #{dest}")
      else
        next
      end
    end
    say("Copying #{jar} => #{dest}")
    FileUtils.cp(jar, dest)
                     end
end

#say(message) ⇒ Object



38
39
40
41
42
# File 'lib/sunspot/installer/library_installer.rb', line 38

def say(message)
  if @verbose
    STDOUT.puts(message)
  end
end