Class: Fvm::CLI::Linker

Inherits:
Object
  • Object
show all
Defined in:
lib/fvm/cli/linker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, executables) ⇒ Linker

Returns a new instance of Linker.



8
9
10
11
# File 'lib/fvm/cli/linker.rb', line 8

def initialize( dir, executables )
  @dir = Pathname.new( dir ).expand_path
  @executables = executables
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



7
8
9
# File 'lib/fvm/cli/linker.rb', line 7

def dir
  @dir
end

#executablesObject (readonly)

Returns the value of attribute executables.



7
8
9
# File 'lib/fvm/cli/linker.rb', line 7

def executables
  @executables
end

Instance Method Details

#files(src) ⇒ Object



13
14
15
# File 'lib/fvm/cli/linker.rb', line 13

def files( src )
  Dir[ File.join( src, '*' ) ].select { |name| executables.include? File.basename( name ) }
end


17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fvm/cli/linker.rb', line 17

def link( src )
  files( src ).each do |file|
    Dir.chdir dir do
      # thanks, homebrew!
      rv = system 'ln', '-sf', file
      unless rv and $? == 0
        raise <<-EOS.undent
          Could not create symlink to #{file.to_s}.
          Check that you have permissions on #{dir}.
        EOS
      end
    end
  end
end

#unlink!Object



32
33
34
# File 'lib/fvm/cli/linker.rb', line 32

def unlink!
  files( dir ).each { |file| File.delete file }
end