Sha256: d3f1904e690efc5e6b8c0538b3489d95fe27a543578eb3e079032472adcb7fca

Contents?: true

Size: 1.43 KB

Versions: 13

Compression:

Stored size: 1.43 KB

Contents

require 'active_support/core_ext/hash'

module Ufo
  module Util
    # The default cluster normally defaults to the Ufo.env value.
    # But it can be overriden by ufo/settings.yml cluster
    #
    # More info: http://ufoships.com/docs/settings/
    def default_cluster
      settings["cluster"] || Ufo.env
    end

    # Keys are strings for simplicity.
    def settings
      @settings ||= Setting.new.data
    end

    # Naming it default_params because params is too commonly used in ufo.
    # Param keys must be symbols for the aws-sdk calls.
    def default_params
      @default_params ||= Param.new.data.deep_symbolize_keys
    end

    def execute(command, local_options={})
      if @options[:noop] && !local_options[:live]
        say "NOOP: #{command}"
        result = true # always success with no noop for specs
      else
        if local_options[:use_system]
          result = system(command)
        else
          result = `#{command}`
        end
      end
      result
    end

    # http://stackoverflow.com/questions/4175733/convert-duration-to-hoursminutesseconds-or-similar-in-rails-3-or-ruby
    def pretty_time(total_seconds)
      minutes = (total_seconds / 60) % 60
      seconds = total_seconds % 60
      if total_seconds < 60
        "#{seconds.to_i}s"
      else
        "#{minutes.to_i}m #{seconds.to_i}s"
      end
    end

    def display_params(options)
      puts YAML.dump(options.deep_stringify_keys)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ufo-3.5.7 lib/ufo/util.rb
ufo-3.5.6 lib/ufo/util.rb
ufo-3.5.5 lib/ufo/util.rb
ufo-3.5.4 lib/ufo/util.rb
ufo-3.5.3 lib/ufo/util.rb
ufo-3.5.2 lib/ufo/util.rb
ufo-3.5.1 lib/ufo/util.rb
ufo-3.5.0 lib/ufo/util.rb
ufo-3.4.4 lib/ufo/util.rb
ufo-3.4.3 lib/ufo/util.rb
ufo-3.4.2 lib/ufo/util.rb
ufo-3.4.1 lib/ufo/util.rb
ufo-3.4.0 lib/ufo/util.rb