Sha256: 52ffd4392cc2a453a370ce0a6f121a2cdc7a02b061881eaed965f5138f58c9fd

Contents?: true

Size: 1.74 KB

Versions: 8

Compression:

Stored size: 1.74 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 = [
            @progress_bar_cache[file].progress + increment,
            total
          ].min
        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 vagrant_plugin plugin, constraint = nil
      return [plugin, nil] if constraint.nil?
      return [plugin, Gem::Dependency.new(plugin, constraint)]
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hem-1.2.4 lib/hem/util.rb
hem-1.2.3 lib/hem/util.rb
hem-1.2.2 lib/hem/util.rb
hem-1.2.1 lib/hem/util.rb
hem-1.2.0 lib/hem/util.rb
hem-1.1.2 lib/hem/util.rb
hem-1.1.1 lib/hem/util.rb
hem-1.1.0 lib/hem/util.rb