Class: Rhail::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/rhail/generator.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type: 'plain', folder: './', rvm_ruby: '2.3.3', rvm_gemset: nil) ⇒ Generator

Returns a new instance of Generator.



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

def initialize(type: 'plain', folder: './', rvm_ruby: '2.3.3', rvm_gemset: nil)
  @type       = type
  folder      = (folder == nil || folder.size == 0) ? './' : folder
  @folder     = File.expand_path(folder)
  @rvm_ruby   = rvm_ruby
  @rvm_gemset = rvm_gemset || "ruby-hail-generated-#{@type}"
end

Instance Attribute Details

#folderObject (readonly)

Returns the value of attribute folder.



5
6
7
# File 'lib/rhail/generator.rb', line 5

def folder
  @folder
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/rhail/generator.rb', line 5

def type
  @type
end

Instance Method Details

#create_folder_with_appObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rhail/generator.rb', line 15

def create_folder_with_app
  unless Dir.exists? @folder
    FileUtils.mkdir_p @folder
  end

  FileUtils.cp_r File.expand_path("../../../generator_folders/#{@type}", __FILE__), @folder

  if @rvm_ruby
    File.open("#{@folder}/#{@type}/.ruby-version", 'w+') do |f|
      f.write "#{@rvm_ruby}@#{@rvm_gemset}\n"
    end
  end
end

#install_dependenciesObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rhail/generator.rb', line 29

def install_dependencies
  rvm_cmd = `which rvm`.chomp
  rvm_full_cmd = ''
  if rvm_cmd.length > 0
    rvm_full_cmd = "#{rvm_cmd} #{@rvm_ruby}@#{@rvm_gemset} do"
  end

  install_bundler_cmd = "cd #{@folder}/#{@type} && #{rvm_full_cmd} gem install bundler"
  puts install_bundler_cmd
  system(install_bundler_cmd)

  bundle_install_cmd = "cd #{@folder}/#{@type} && #{rvm_full_cmd} bundle install"
  puts bundle_install_cmd
  system(bundle_install_cmd)
end