class CF::App::Base
Public Instance Methods
app_status(a)
click to toggle source
# File lib/cf/cli/app/base.rb, line 26 def app_status(a) health = a.health if a.debug_mode == "suspend" && health == "0%" c("suspended", :neutral) else c(health.downcase, state_color(health)) end end
human_mb(num)
click to toggle source
# File lib/cf/cli/app/base.rb, line 40 def human_mb(num) human_size(num * 1024 * 1024, 0) end
human_size(num, precision = 1)
click to toggle source
# File lib/cf/cli/app/base.rb, line 44 def human_size(num, precision = 1) sizes = %w(G M K) sizes.each.with_index do |suf, i| pow = sizes.size - i unit = 1024.0 ** pow if num >= unit return format("%.#{precision}f%s", num / unit, suf) end end format("%.#{precision}fB", num) end
megabytes(str)
click to toggle source
# File lib/cf/cli/app/base.rb, line 57 def megabytes(str) if str =~ /T$/i str.to_i * 1024 * 1024 elsif str =~ /G$/i str.to_i * 1024 elsif str =~ /M$/i str.to_i elsif str =~ /K$/i str.to_i / 1024 else # assume megabytes str.to_i end end
memory_choices()
click to toggle source
# File lib/cf/cli/app/base.rb, line 36 def memory_choices [128, 256, 512, 1024].map{|n| human_mb(n)} end
state_color(s)
click to toggle source
choose the right color for app/instance state
# File lib/cf/cli/app/base.rb, line 9 def state_color(s) case s when "STARTING" :neutral when "STARTED", "RUNNING" :good when "DOWN" :bad when "FLAPPING" :error when "N/A" :unknown else :warning end end