Sha256: 349433a6d243acbbb332dbd2e3f5a3ab1fcdae3849093bffe99072bcd5528ef5

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

require_relative "content_resolver"
require "tty-which"

#
# require Heroku-cli
#

module HerokuAppInfo
  class Fetcher
    #
    # @param [Options] options
    #
    def initialize(options = nil)
      @options = options
      raise HerokuCliNotFound if TTY::Which.which("heroku").nil?
    end

    #
    # @param [String] app
    # @return [String]
    #
    def app(app)
      if (path = cache_file(app: app))
        File.read(path)
      else
        `heroku apps:info #{app}`
      end
    end

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

    #
    # @param [String] app
    # @return [String]
    #
    def addons(app)
      if (path = cache_file(app: app))
        File.read(path)
      else
        `heroku addons -a #{app}`
      end
    end

    #
    # @return [String]
    #
    def all_apps
      if (path = cache_file)
        File.read(path)
      else
        `heroku apps -A`
      end
    end

    #
    # @param [String] app
    # @param [String] sort
    # @return [String, false]
    #
    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
heroku-app-info-0.1.1 lib/heroku_app_info/fetcher.rb