Module: Rvmify

Defined in:
lib/rvmify.rb

Constant Summary collapse

VERSION =
'0.2.0'

Class Method Summary collapse

Class Method Details

.generate(path) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rvmify.rb', line 37

def generate(path)
  project_name = File.basename(path)

  # .gems file
  write_unless_exists(path, "#{project_name}.gems", "bundler -v0.9.26")

  # Gemfile
  write_unless_exists(path, "Gemfile", "#install all project gems here")

  # Project specific .rvmrc file
  write_unless_exists(path, ".rvmrc", rvmrc_file(project_name))
end

.rvmrc_file(project_name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rvmify.rb', line 15

def rvmrc_file(project_name)

  ruby_path = `which ruby`.strip
  ruby_version = File.basename(ruby_path.gsub(/\/bin\/ruby/,''))

  gem_home = `echo $GEM_HOME`
  environment_path = gem_home.gsub('/gems/', '/environments/').strip

  # Project specific .rvmrc file
  contents = <<-END
if [[ -s "#{environment_path}" ]] ; then
  . "#{environment_path}"
else
  rvm --create use "#{ruby_version}"
fi

[[ -s "#{project_name}.gems" ]] && rvm gemset use #{project_name}

bundle install
END
end

.write_unless_exists(path, filename, contents) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/rvmify.rb', line 6

def write_unless_exists(path, filename, contents)
  writefile = File.join(path, filename)
  unless File.exist?(writefile)
    File.open(writefile, 'w') { |f| f.write(contents) }
  else
    puts "#{writefile} not written, #{writefile} already exists!"
  end
end