123456789_123456789_123456789_123456789_123456789_

Module: RubyInstaller::Runtime::Ridk

Do not use. This module is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Colors
Defined in: lib/ruby_installer/runtime/ridk.rb

Constant Summary

Class Method Summary

Class Method Details

.args_to_tasks(ci, args)

[ GitHub ]

  
# File 'lib/ruby_installer/runtime/ridk.rb', line 103

private def args_to_tasks(ci, args)
  args.join(" ").split(" ").map do |idx_or_name|
    if idx_or_name =~ /\A\d+\z/ && (task=ci.installable_components.find{|c| idx_or_name.to_i == c.task_index })
      task
    elsif idx_or_name =~ /\A\w+\z/ && (task=ci.installable_components.find{|c| idx_or_name == c.name })
      task
    else
      puts red("Can not find component #{idx_or_name.inspect}")
    end
  end.compact
end

.ignore_err

[ GitHub ]

  
# File 'lib/ruby_installer/runtime/ridk.rb', line 126

private def ignore_err
  orig_verbose, $VERBOSE = $VERBOSE, nil
  begin
    yield
  rescue
  end
  $VERBOSE = orig_verbose
end

.install(args)

[ GitHub ]

  
# File 'lib/ruby_installer/runtime/ridk.rb', line 56

def install(args)
  ci = ComponentsInstaller.new
  inst_defaults = DEFAULT_COMPONENTS

  if args.empty?
    # Interactive installation
    loop do
      ci.installable_components.each do |comp|
        puts format("  % 2d - %s", comp.task_index, comp.description)
      end
      puts
      print "Which components shall be installed? If unsure press ENTER [#{inst_defaults.join(",")}] "

      inp = STDIN.gets
      inp = inp.tr(",", " ").strip if inp
      if !inp
        break
      elsif inp.empty? && inst_defaults.empty?
        break
      elsif inp.empty?
        inst_list = inst_defaults
      elsif inp =~ /\A(?:(\d+|\w+)\s*)+\z/
        inst_list = [inp]
      else
        puts red("Please enter a comma separated list of the components to be installed")
      end

      if inst_list
        puts
        begin
          ci.install(args_to_tasks(ci, inst_list).map(&:name))
        rescue => err
          puts red("Installation failed: #{err}")
        end

        ci.reload
        inst_defaults = []
        puts
      end
    end

  else
    # Unattended installation
    ci.install(args_to_tasks(ci, args).map(&:name))
  end
end

.msys_version_info(msys_path)

[ GitHub ]

  
# File 'lib/ruby_installer/runtime/ridk.rb', line 115

def msys_version_info(msys_path)
  require "rexml/document"
  doc = File.open( File.join(msys_path, "components.xml") ) do |fd|
    REXML::Document.new fd
  end
  {
    "title" => doc.elements.to_a("//Packages/Package/Title").first.text,
    "version" => doc.elements.to_a("//Packages/Package/Version").first.text,
  }
end

.run!(args)

[ GitHub ]

  
# File 'lib/ruby_installer/runtime/ridk.rb', line 8

def run!(args)
  enable_colors
  case args[0]
    when 'install'
      
      puts
      install(args[1..-1])
    when 'enable', 'exec'
      puts Runtime::Msys2Installation.new( mingwarch: args[1] ).enable_msys_apps_per_cmd
    when 'disable'
      puts Runtime::Msys2Installation.new.disable_msys_apps_per_cmd
    when 'enableps1', 'execps1'
      puts Runtime::Msys2Installation.new( mingwarch: args[2] ).enable_msys_apps_per_ps1
    when 'disableps1'
      puts Runtime::Msys2Installation.new.disable_msys_apps_per_ps1
    when 'version'
      print_version
    when 'help', '--help', '-?', '/?', nil
      
      print_help
    else
      $stderr.puts "Invalid option #{args[0].inspect}"
  end
end

.sanitize_hash_encoding(hash_or_string)

[ GitHub ]

  
# File 'lib/ruby_installer/runtime/ridk.rb', line 135

def sanitize_hash_encoding(hash_or_string)
  if hash_or_string.respond_to?(:encode)
    hash_or_string.encode('utf-8', invalid: :replace, undef: :replace)
  else
    hash_or_string.map { |k, v| [k, sanitize_hash_encoding(v)] }.to_h
  end
end