Sha256: 57c549dc794d478dce45f939bf4daf85e5732f1be3c3ff7bbc16b7396fd0f025

Contents?: true

Size: 2 KB

Versions: 2

Compression:

Stored size: 2 KB

Contents

module Hem
  class << self

    attr_accessor :project_bar_cache

    def relaunch! env = {}
      Kernel.exec(env, 'hem', '--skip-host-checks', *$HEM_ARGV)
    end

    def in_project?
      !!Hem.project_path
    end

    def progress file, increment, total, type, opts = {}
      require 'ruby-progressbar'

      opts = {
        :title => File.basename(file),
        :total => total,
        :format => "%t [%B] %p%% %e"
      }.merge(opts)

      # Hack to stop newline spam on windows
      opts[:length] = 79 if Gem::win_platform?

      @progress_bar_cache ||= {}

      if type == :reset
        type = :update
        @progress_bar_cache.delete file
      end

      @progress_bar_cache[file] ||= ProgressBar.create(opts)

      case type
        when :update
          @progress_bar_cache[file].progress += increment
        when :finished
          @progress_bar_cache[file].finish
      end

      return @progress_bar_cache[file]
    end

    def aws_credentials
      {
        :access_key_id => maybe(Hem.user_config.aws.access_key_id) || ENV['AWS_ACCESS_KEY_ID'],
        :secret_access_key => maybe(Hem.user_config.aws.secret_access_key) || ENV['AWS_SECRET_ACCESS_KEY']
      }
    end

    def windows?
      require 'rbconfig'
      !!(RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/)
    end

    def system_ruby?
      require 'rbconfig'
      File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"]).match(/\/rvm\/|\/\.rvm\/|\/\.rbenv/) != nil
    end

    def chefdk_compat
      return if maybe(Hem.user_config.hem.disable_chefdk_compat) || ENV['HEM_DISABLE_CHEFDK_COMPAT']
      return if Hem.windows?
      which_ruby = File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"])
      if which_ruby =~ /rbenv/
        split_path = ENV['PATH'].split ':'
        paths = split_path.reject do |p|
          p =~ /chefdk/
        end
        chef_paths = split_path - paths
        ENV['PATH'] = (chef_paths + paths).join ':'
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hem-1.0.1.beta2 lib/hem/util.rb
hem-1.0.1.beta1 lib/hem/util.rb