Class: GemWrappers::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/gem-wrappers/environment.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.file_nameObject



7
8
9
10
11
12
13
# File 'lib/gem-wrappers/environment.rb', line 7

def self.file_name
  path = Gem.configuration && Gem.configuration[:wrappers_environment_file]
  if path.nil? || path == ""
    path = File.join(Gem.dir, 'environment')
  end
  path
end

Instance Method Details

#ensureObject



25
26
27
28
29
30
31
32
33
# File 'lib/gem-wrappers/environment.rb', line 25

def ensure
  return if File.exist?(file_name)
  FileUtils.mkdir_p(File.dirname(file_name)) unless File.exist?(File.dirname(file_name))
  content = ERB.new(template).result(binding)
  File.open(file_name, 'w') do |file|
    file.write(content)
  end
  File.chmod(0644, file_name)
end

#file_nameObject



15
16
17
# File 'lib/gem-wrappers/environment.rb', line 15

def file_name
  @file_name ||= self.class.file_name
end

#gem_homeObject



47
48
49
# File 'lib/gem-wrappers/environment.rb', line 47

def gem_home
  @gem_home ||= Gem.dir
end

#gem_pathObject



43
44
45
# File 'lib/gem-wrappers/environment.rb', line 43

def gem_path
  @gem_path ||= Gem.path
end

#path(base = ENV['PATH']) ⇒ Object



51
52
53
# File 'lib/gem-wrappers/environment.rb', line 51

def path(base = ENV['PATH'])
  @path ||= base.split(":").take(path_take)
end

#path_takeObject



19
20
21
22
23
# File 'lib/gem-wrappers/environment.rb', line 19

def path_take
  return @path_take if defined? @path_take
  @path_take = Gem.configuration && Gem.configuration[:wrappers_path_take] || 1
  @path_take += gem_path.size
end

#templateObject



35
36
37
38
39
40
41
# File 'lib/gem-wrappers/environment.rb', line 35

def template
  @template ||= <<-TEMPLATE
export PATH="<%= path.join(":") %>:$PATH"
export GEM_PATH="<%= gem_path.join(":") %>"
export GEM_HOME="<%= gem_home %>"
TEMPLATE
end