Class: HerokuAppInfo::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/heroku_app_info/fetcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Fetcher

Returns a new instance of Fetcher.

Parameters:

  • options (Options) (defaults to: nil)

Raises:



13
14
15
16
# File 'lib/heroku_app_info/fetcher.rb', line 13

def initialize(options = nil)
  @options = options
  raise HerokuCliNotFound if TTY::Which.which("heroku").nil?
end

Instance Method Details

#addons(app) ⇒ String

Parameters:

  • app (String)

Returns:

  • (String)


46
47
48
49
50
51
52
# File 'lib/heroku_app_info/fetcher.rb', line 46

def addons(app)
  if (path = cache_file(app: app))
    File.read(path)
  else
    `heroku addons -a #{app}`
  end
end

#all_appsString

Returns:

  • (String)


57
58
59
60
61
62
63
# File 'lib/heroku_app_info/fetcher.rb', line 57

def all_apps
  if (path = cache_file)
    File.read(path)
  else
    `heroku apps -A`
  end
end

#app(app) ⇒ String

Parameters:

  • app (String)

Returns:

  • (String)


22
23
24
25
26
27
28
# File 'lib/heroku_app_info/fetcher.rb', line 22

def app(app)
  if (path = cache_file(app: app))
    File.read(path)
  else
    `heroku apps:info #{app}`
  end
end

#cache_file(app: nil, sort: nil) ⇒ String, false

Parameters:

  • app (String) (defaults to: nil)
  • sort (String) (defaults to: nil)

Returns:

  • (String, false)


70
71
72
73
74
75
76
77
# File 'lib/heroku_app_info/fetcher.rb', line 70

def cache_file(app: nil, sort: nil)
  return false if @options.no_cache?

  filename, = ContentResolver.resolve(app || "apps", "", sort: sort)
  path = File.join(@options.out_dir, filename)

  (File.exist?(path) && File.readable?(path)) ? path : false
end

#pg(app) ⇒ String

Parameters:

  • app (String)

Returns:

  • (String)


34
35
36
37
38
39
40
# File 'lib/heroku_app_info/fetcher.rb', line 34

def pg(app)
  if (path = cache_file(app: app, sort: "pg"))
    File.read(path)
  else
    `heroku pg -a #{app}`
  end
end