Class: Lam::Build::TravelingRuby

Inherits:
Object
  • Object
show all
Defined in:
lib/lam/build/traveling_ruby.rb

Instance Method Summary collapse

Instance Method Details

#buildObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lam/build/traveling_ruby.rb', line 10

def build
  if File.exist?("#{Lam.root}bundled")
    puts "Ruby bundled already exists."
    puts "To force rebundling: rm -rf bundled"
    return
  end

  check_ruby_version

  FileUtils.mkdir_p(TEMP_BUILD_DIR)
  copy_gemfiles

  Dir.chdir(TEMP_BUILD_DIR) do
    download_traveling_ruby
    unpack_traveling_ruby
    bundle_install
  end

  move_bundled_to_project
end

#bundle_installObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/lam/build/traveling_ruby.rb', line 72

def bundle_install
  puts 'Installing bundle.'
  require "bundler" # dynamicaly require bundler so user can use any bundler
  Bundler.with_clean_env do
    success = system(
      "cd #{TEMP_BUILD_DIR} && " \
      'env BUNDLE_IGNORE_CONFIG=1 bundle install --path bundled/gems --without development'
    )

    abort('Bundle install failed, exiting.') unless success
  end

  puts 'Bundle install success.'
end

#bundled_ruby_destObject



96
97
98
# File 'lib/lam/build/traveling_ruby.rb', line 96

def bundled_ruby_dest
  "bundled/ruby"
end

#check_ruby_versionObject



31
32
33
34
35
36
37
38
# File 'lib/lam/build/traveling_ruby.rb', line 31

def check_ruby_version
  return if ENV['LAM_SKIP_RUBY_CHECK'] # only use if you absolutely need to
  traveling_version = TRAVELING_RUBY_VERSION.match(/-((\d+)\.(\d+)\.(\d+))-/)[1]
  if RUBY_VERSION != traveling_version
    puts "You are using ruby version #{RUBY_VERSION}."
    abort("You must use ruby #{traveling_version} to build the project because it's what Traveling Ruby uses.".colorize(:red))
  end
end

#copy_gemfilesObject



40
41
42
43
# File 'lib/lam/build/traveling_ruby.rb', line 40

def copy_gemfiles
  FileUtils.cp("#{Lam.root}Gemfile", "#{TEMP_BUILD_DIR}/")
  FileUtils.cp("#{Lam.root}Gemfile.lock", "#{TEMP_BUILD_DIR}/")
end

#download_traveling_rubyObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/lam/build/traveling_ruby.rb', line 45

def download_traveling_ruby
  puts "Downloading traveling ruby from #{traveling_ruby_url}."

  FileUtils.rm_rf("#{TEMP_BUILD_DIR}/#{bundled_ruby_dest}")
  File.open(traveling_ruby_tar_file, 'wb') do |saved_file|
    # the following "open" is provided by open-uri
    open(traveling_ruby_url, 'rb') do |read_file|
      saved_file.write(read_file.read)
    end
  end

  puts 'Download complete.'
end

#move_bundled_to_projectObject



87
88
89
90
91
92
93
94
# File 'lib/lam/build/traveling_ruby.rb', line 87

def move_bundled_to_project
  if File.exist?("#{Lam.root}bundled")
    puts "Removing current bundled folder"
    FileUtils.rm_rf("#{Lam.root}bundled")
  end
  puts "Moving bundled ruby to your project."
  FileUtils.mv("#{TEMP_BUILD_DIR}/bundled", Lam.root)
end

#traveling_ruby_tar_fileObject



104
105
106
# File 'lib/lam/build/traveling_ruby.rb', line 104

def traveling_ruby_tar_file
  File.basename(traveling_ruby_url)
end

#traveling_ruby_urlObject



100
101
102
# File 'lib/lam/build/traveling_ruby.rb', line 100

def traveling_ruby_url
  TRAVELING_RUBY_VERSION
end

#unpack_traveling_rubyObject



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/lam/build/traveling_ruby.rb', line 59

def unpack_traveling_ruby
  puts 'Unpacking traveling ruby.'

  FileUtils.mkdir_p(bundled_ruby_dest)

  success = system("tar -xzf #{traveling_ruby_tar_file} -C #{bundled_ruby_dest}")
  abort('Unpacking traveling ruby failed') unless success
  puts 'Unpacking traveling ruby successful.'

  puts 'Removing tar.'
  FileUtils.rm_rf(traveling_ruby_tar_file)
end