module RHC::OutputHelpers

Public Instance Methods

display_app(app,cartridges = nil) click to toggle source
# File lib/rhc/output_helpers.rb, line 7
def display_app(app,cartridges = nil)
  paragraph do
    header [app.name, "@ #{app.app_url}", "(uuid: #{app.uuid})"] do
      section(:bottom => 1) do
        say format_table                nil,
          get_properties(
            app,
            :creation_time,
            :gear_info,
            :git_url,
            :initial_git_url,
            :ssh_string,
            :aliases
          ),
          :delete => true
      end
      cartridges.each{ |c| section(:bottom => 1){ display_cart(c) } } if cartridges
    end
  end
end
display_authorization(auth, default=nil) click to toggle source
# File lib/rhc/output_helpers.rb, line 84
def display_authorization(auth, default=nil)
  say format_table(
    auth.note || "<no description>",
    get_properties(auth, :token, :scopes, :creation_time, :expires_in_seconds),
    {
      :delete => true,
      :color => (:green if auth.token == default),
    }
  )
end
display_cart(cart, *properties) click to toggle source
# File lib/rhc/output_helpers.rb, line 60
def display_cart(cart, *properties)
  say format_table          format_cart_header(cart),
    get_properties(cart, *properties).
      concat([[:downloaded_cartridge_url, cart.url]]).
      concat([[cart.scalable? ? :scaling : :gears, format_cart_gears(cart)]]).
      concat(cart.properties.map{ |p| ["#{table_heading(p['name'])}:", p['value']] }.sort{ |a,b| a[0] <=> b[0] }),
    :delete => true
  
  say format_usage_message(cart) if cart.usage_rate?
end
display_cart_storage_info(cart, title="Storage Info") click to toggle source
# File lib/rhc/output_helpers.rb, line 102
def display_cart_storage_info(cart, title="Storage Info")
  say format_table          title,
    get_properties(cart,:base_gear_storage,:additional_gear_storage)
end
display_cart_storage_list(carts) click to toggle source
# File lib/rhc/output_helpers.rb, line 108
def display_cart_storage_list(carts)
  carts.each{ |cart| paragraph{ display_cart_storage_info(cart, cart.display_name) } }
end
display_key(key, *properties) click to toggle source
# File lib/rhc/output_helpers.rb, line 72
def display_key(key, *properties)
  properties = [:fingerprint, :visible_to_ssh?] if properties.empty?
  say format_table(
    properties.include?(:name) ? nil : format_key_header(key),
    get_properties(key, *properties),
    {
      :delete => true,
      :color => (:green if properties.include?(:visible_to_ssh?) && key.visible_to_ssh?),
    }
  )
end
format_cart_gears(cart) click to toggle source
# File lib/rhc/output_helpers.rb, line 41
def format_cart_gears(cart)
  if cart.scalable?
    format_scaling_info(cart.scaling)
  elsif cart.shares_gears?
    "Located with #{cart.collocated_with.join(", ")}"
  else
    "%d %s" % [format_value(:current_scale, cart.current_scale), format_value(:gear_profile, cart.gear_profile)]
  end
end
format_cart_header(cart) click to toggle source
# File lib/rhc/output_helpers.rb, line 29
def format_cart_header(cart)
  [
    cart.name,
    cart.name != cart.display_name ? "(#{cart.display_name})" : nil,
  ].compact
end
format_gear_info(info) click to toggle source
# File lib/rhc/output_helpers.rb, line 51
def format_gear_info(info)
  "%d (defaults to %s)" %
    [:gear_count, :gear_profile].map{ |key| format_value(key, info[key]) } if info
end
format_key_header(key) click to toggle source
# File lib/rhc/output_helpers.rb, line 95
def format_key_header(key)
  [
    key.name,
    "(type: #{key.type})",
  ].compact
end
format_scaling_info(scaling) click to toggle source
# File lib/rhc/output_helpers.rb, line 36
def format_scaling_info(scaling)
  "x%d (minimum: %s, maximum: %s) on %s gears" %
    [:current_scale, :scales_from, :scales_to, :gear_profile].map{ |key| format_value(key, scaling[key]) } if scaling
end
format_usage_message(cart) click to toggle source
# File lib/rhc/output_helpers.rb, line 112
def format_usage_message(cart)
  "This gear costs an additional $#{cart.usage_rate} per gear after the first 3 gears."
end