Class: Fvm::CLI::Linker
- Inherits:
-
Object
- Object
- Fvm::CLI::Linker
- Defined in:
- lib/fvm/cli/linker.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#executables ⇒ Object
readonly
Returns the value of attribute executables.
Instance Method Summary collapse
- #files(src) ⇒ Object
-
#initialize(dir, executables) ⇒ Linker
constructor
A new instance of Linker.
- #link(src) ⇒ Object
- #unlink! ⇒ Object
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 ). @executables = executables end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
7 8 9 |
# File 'lib/fvm/cli/linker.rb', line 7 def dir @dir end |
#executables ⇒ Object (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 |
#link(src) ⇒ Object
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 |