class LibyearBundler::CLI
The `libyear-bundler` command line program
Constants
- E_BUNDLE_OUTDATED_FAILED
- E_INVALID_CLI_ARG
- E_NO_GEMFILE
Public Class Methods
new(argv)
click to toggle source
# File lib/libyear_bundler/cli.rb, line 16 def initialize(argv) @options = ::LibyearBundler::Options.new(argv).parse # Command line flags are removed form `argv` in `Options` by # `OptionParser`, leaving non-flag command line arguments, # such as a Gemfile path @argv = argv @gemfile_path = load_gemfile_path end
Public Instance Methods
run()
click to toggle source
# File lib/libyear_bundler/cli.rb, line 25 def run if @options.grand_total? grand_total else print report.to_s end # Update cache cache_path = @options.cache_path if cache_path && release_date_cache release_date_cache.save(cache_path) end end
Private Instance Methods
bundle_outdated()
click to toggle source
# File lib/libyear_bundler/cli.rb, line 63 def bundle_outdated BundleOutdated.new(@gemfile_path, release_date_cache).execute end
calculate_grand_total()
click to toggle source
# File lib/libyear_bundler/cli.rb, line 88 def calculate_grand_total if [:libyears?, :releases?, :versions?].all? { |opt| @options[opt] } [ libyears_grand_total, releases_grand_total, versions_grand_total ].join("\n") elsif @options.releases? releases_grand_total elsif @options.versions? versions_grand_total else libyears_grand_total end end
fallback_gemfile_exists?()
click to toggle source
# File lib/libyear_bundler/cli.rb, line 45 def fallback_gemfile_exists? # The envvar is set or (!ENV["BUNDLE_GEMFILE"].nil? && ::File.exist?(ENV["BUNDLE_GEMFILE"])) || # Default to local Gemfile ::File.exist?("Gemfile") end
first_arg_is_gemfile?()
click to toggle source
# File lib/libyear_bundler/cli.rb, line 41 def first_arg_is_gemfile? !@argv.first.nil? && ::File.exist?(@argv.first) end
grand_total()
click to toggle source
# File lib/libyear_bundler/cli.rb, line 84 def grand_total puts calculate_grand_total end
libyears_grand_total()
click to toggle source
# File lib/libyear_bundler/cli.rb, line 104 def libyears_grand_total report.to_h[:sum_libyears].truncate(1) end
load_gemfile_path()
click to toggle source
# File lib/libyear_bundler/cli.rb, line 52 def load_gemfile_path if first_arg_is_gemfile? @argv.first elsif fallback_gemfile_exists? '' # `bundle outdated` will default to local Gemfile else $stderr.puts "Gemfile not found" exit E_NO_GEMFILE end end
release_date_cache()
click to toggle source
# File lib/libyear_bundler/cli.rb, line 67 def release_date_cache @_release_date_cache ||= begin path = @options.cache_path return if path.nil? ReleaseDateCache.load(path) end end
releases_grand_total()
click to toggle source
# File lib/libyear_bundler/cli.rb, line 108 def releases_grand_total report.to_h[:sum_seq_delta] end
report()
click to toggle source
# File lib/libyear_bundler/cli.rb, line 75 def report @_report ||= Report.new(bundle_outdated, ruby, @options) end
ruby()
click to toggle source
# File lib/libyear_bundler/cli.rb, line 79 def ruby lockfile = @gemfile_path + '.lock' ::LibyearBundler::Models::Ruby.new(lockfile, release_date_cache) end
versions_grand_total()
click to toggle source
# File lib/libyear_bundler/cli.rb, line 112 def versions_grand_total [ report.to_h[:sum_major_version], report.to_h[:sum_minor_version], report.to_h[:sum_patch_version] ].to_s end