Class: GemWrappers::Environment
- Inherits:
-
Object
- Object
- GemWrappers::Environment
- Defined in:
- lib/gem-wrappers/environment.rb
Class Method Summary collapse
Instance Method Summary collapse
- #ensure ⇒ Object
- #file ⇒ Object
- #gem_home ⇒ Object
- #gem_path ⇒ Object
- #path(base = ENV['PATH']) ⇒ Object
- #path_take ⇒ Object
- #template ⇒ Object
Class Method Details
.file ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/gem-wrappers/environment.rb', line 6 def self.file path = Gem.configuration && Gem.configuration[:wrappers_environment_file] if path.nil? || path == "" path = File.join(Gem.dir, 'environment') end path end |
Instance Method Details
#ensure ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/gem-wrappers/environment.rb', line 24 def ensure return if File.exist?(file) FileUtils.mkdir_p(File.dirname(file)) unless File.exist?(File.dirname(file)) content = ERB.new(template).result(binding) File.open(file, 'w') do |file| file.write(content) end File.chmod(0644, file) end |
#file ⇒ Object
14 15 16 |
# File 'lib/gem-wrappers/environment.rb', line 14 def file @file ||= self.class.file end |
#gem_home ⇒ Object
46 47 48 |
# File 'lib/gem-wrappers/environment.rb', line 46 def gem_home @gem_home ||= Gem.dir end |
#gem_path ⇒ Object
42 43 44 |
# File 'lib/gem-wrappers/environment.rb', line 42 def gem_path @gem_path ||= Gem.path end |
#path(base = ENV['PATH']) ⇒ Object
50 51 52 |
# File 'lib/gem-wrappers/environment.rb', line 50 def path(base = ENV['PATH']) @path ||= base.split(":").take(path_take) end |
#path_take ⇒ Object
18 19 20 21 22 |
# File 'lib/gem-wrappers/environment.rb', line 18 def path_take return @path_take if @path_take @path_take = Gem.configuration && Gem.configuration[:wrappers_path_take] || 1 @path_take += gem_path.size end |
#template ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/gem-wrappers/environment.rb', line 34 def template @template ||= <<-TEMPLATE export PATH="<%= path.join(":") %>:$PATH" export GEM_PATH="<%= gem_path.join(":") %>" export GEM_HOME="<%= gem_home %>" TEMPLATE end |