Class: GemWrappers::Installer
- Inherits:
-
Object
- Object
- GemWrappers::Installer
- Defined in:
- lib/gem-wrappers/installer.rb
Instance Attribute Summary collapse
-
#environment_file ⇒ Object
readonly
Returns the value of attribute environment_file.
Class Method Summary collapse
Instance Method Summary collapse
- #ensure ⇒ Object
-
#initialize(environment_file) ⇒ Installer
constructor
A new instance of Installer.
- #install(executable) ⇒ Object
- #template ⇒ Object
- #wrappers_path ⇒ Object
Constructor Details
#initialize(environment_file) ⇒ Installer
Returns a new instance of Installer.
7 8 9 |
# File 'lib/gem-wrappers/installer.rb', line 7 def initialize(environment_file) @environment_file = environment_file end |
Instance Attribute Details
#environment_file ⇒ Object (readonly)
Returns the value of attribute environment_file.
5 6 7 |
# File 'lib/gem-wrappers/installer.rb', line 5 def environment_file @environment_file end |
Class Method Details
.wrappers_path ⇒ Object
11 12 13 14 |
# File 'lib/gem-wrappers/installer.rb', line 11 def self.wrappers_path Gem.configuration && Gem.configuration[:wrappers_path] || File.join(Gem.dir, 'wrappers') end |
Instance Method Details
#ensure ⇒ Object
20 21 22 23 24 |
# File 'lib/gem-wrappers/installer.rb', line 20 def ensure FileUtils.mkdir_p(wrappers_path) unless File.exist?(wrappers_path) # exception based on Gem::Installer.generate_bin raise Gem::FilePermissionError.new(wrappers_path) unless File.writable?(wrappers_path) end |
#install(executable) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/gem-wrappers/installer.rb', line 26 def install(executable) content = ERB.new(template).result(binding) file = File.join(wrappers_path, executable) File.open(file, 'w') do |file| file.write(content) end File.chmod(0755, file) end |
#template ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/gem-wrappers/installer.rb', line 35 def template @template ||= <<-TEMPLATE #!/usr/bin/env bash if [[ -s "<%= environment_file %>" ]] then source "<%= environment_file %>" exec <%= executable %> "$@" else echo "ERROR: Missing RVM environment file: '<%= environment_file %>'" >&2 exit 1 fi TEMPLATE end |
#wrappers_path ⇒ Object
16 17 18 |
# File 'lib/gem-wrappers/installer.rb', line 16 def wrappers_path @wrappers_path ||= self.class.wrappers_path end |