Sha256: aba52c14c46da66cfe07768c8506ed1fbf273a04df4f441b87f9247369e5314b

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

module Rvmify
  VERSION = '0.1.0'
  
  class << self
  
    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
  
    def rvmrc_file(project_name)

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

      gem_home = `echo $GEM_HOME` # /Users/steve/.rvm/gems/ree-1.8.7-2010.02
      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 import #{project_name}.gems

bundle install
END
    end
  
    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

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rvmify-0.1.0 lib/rvmify.rb