Class: Bun::VersionFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/bun/version_fetcher.rb

Constant Summary collapse

RUBYGEMS_GEM_URL =
"https://rubygems.org/api/v1/gems"

Instance Method Summary collapse

Constructor Details

#initialize(gem, arguments) ⇒ VersionFetcher



9
10
11
12
# File 'lib/bun/version_fetcher.rb', line 9

def initialize(gem, arguments)
  @gem = gem
  @arguments = arguments
end

Instance Method Details

#fetch_latest_versionObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/bun/version_fetcher.rb', line 14

def fetch_latest_version
  version = nil

  with_optional_spinner do
    json_response = JSON.parse(fetch)
    version = json_response["version"]
  end

  version
end

#with_optional_spinnerObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/bun/version_fetcher.rb', line 25

def with_optional_spinner
  if arguments.print?
    yield
  else
    spinner = TTY::Spinner.new("[:spinner] Finding latest gem version for \"#{gem}\"...")
    spinner.auto_spin
    yield
    spinner.stop("Done!")
  end
end