Method: Muto::Muto#initialize

Defined in:
lib/deploy_scripts/muto.rb

#initializeMuto

Returns a new instance of Muto.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/deploy_scripts/muto.rb', line 15

def initialize
  @commands = []
  @ruby_versions = []
  @all_bin_paths = []
  yml_path = File.expand_path('ruby_versions.yml', File.dirname(__FILE__))

  begin
    @versions_yml = YAML.load_file(yml_path)
  rescue Exception => msg
    puts "An Exception occurred while trying to parse your yml file: #{yml_path}"
    raise msg
  end


  if @versions_yml['ruby_versions'].nil?
    puts "There aren't any version of Ruby defined in your ruby_versions.yml yet"
    puts "Update #{File.expand_path(File.join(File.dirname(__FILE__), "ruby_versions.yml")).to_s.gsub(/\//, '\\')} first and try again"
    puts "\nCurrently using:"
    exit!
  else

    @versions_yml['ruby_versions'].each do |key, val|
      @ruby_versions << @versions_yml['ruby_versions'][key]['shortcut'].to_s
      #Convert the following paths to ruby paths so that they can be escaped more easily later on

      @all_bin_paths << File.expand_path(@versions_yml['ruby_versions'][key]['bin_folder'])

      begin
        exe_name = (@versions_yml['ruby_versions'][key]['exe_name']) ? @versions_yml['ruby_versions'][key]['exe_name'] : 'ruby.exe'
        ruby_exe = File.expand_path(File.join(@versions_yml['ruby_versions'][key]['bin_folder'], exe_name))
        ruby_version = `"#{ruby_exe}" -v`

        if File.exist?(ruby_exe)
          add_version(:"#{@versions_yml['ruby_versions'][key]['shortcut'].to_s}", ruby_version)
        else
          puts "File does not exist: #{ruby_exe.to_s}"
        end

      rescue
        puts "Error: File does not exist: #{ruby_exe.to_s}"
      end

    end
  end
end