class HerokuCLI::PG::Database
Attributes
info[R]
pg[R]
url_names[R]
Public Class Methods
new(info, pg = nil)
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 7 def initialize(info, pg = nil) @pg = pg parse_info(info) end
Public Instance Methods
behind?()
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 80 def behind? behind_by.positive? end
behind_by()
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 84 def behind_by info['Behind By']&.match(/(\d+)/)&.to_s&.to_i || 0 end
data_size()
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 36 def data_size info['Data Size'] end
follower?()
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 76 def follower? info.key?('Following') end
followers()
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 52 def followers info['Followers'] end
following()
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 64 def following info['Following'].strip end
fork?()
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 72 def fork? !(main? || follower?) && forked_from&.any? end
forked_from()
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 60 def forked_from info['Forked From']&.split(',')&.map(&:strip) end
forks()
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 56 def forks info['Forks']&.split(',')&.map(&:strip) end
main?()
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 68 def main? @url_names.include?('DATABASE_URL') end
name()
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 28 def name @name ||= url_name.gsub(/_URL\z/, '') end
parse_info(info)
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 96 def parse_info(info) info = info.split("\n") if info.is_a?(String) @url_names = info.shift @url_names = @url_names.sub('=== ','').split(',').map(&:strip) @info = {} info.each do |line| k = line.split(':')[0].strip v = line.split(':')[1..-1].join(':').strip next if k.nil? || v.nil? @info[k] = v end end
plan()
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 32 def plan info['Plan'].gsub(' ', '-').downcase end
region()
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 88 def region info['Region'] end
reload()
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 13 def reload parse_info(pg.heroku("pg:info #{url_name}")) if pg.present? end
resource_name()
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 92 def resource_name info['Add-on'] end
status()
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 40 def status info['Status'] end
tables()
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 44 def tables info['Tables'].match(/(\d+)/)[0]&.to_i || 0 end
to_s()
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 21 def to_s result = ["=== #{@url_names.join(', ')}"] result.concat(info.map { |k, v| format("%-22.22s %s", "#{k}:", v)}) result.concat(['']) result.join("\n") end
url_name()
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 17 def url_name @url_names.first end
version()
click to toggle source
# File lib/heroku_cli/pg/database.rb, line 48 def version Gem::Version.new(info['PG Version']) end