Class: Dapp::CLI::Command::Update
- Defined in:
- lib/dapp/cli/command/update.rb
Constant Summary
Constants inherited from Dapp::CLI
Instance Method Summary collapse
Methods inherited from Dapp::CLI
Methods included from Helper::Cli
#cli_wrapper, #composite_options, #in_validate!, #list_msg_format, #parse_options, #parse_subcommand, #prepare_subcommand, #print_error_with_help_and_die!, #required_argument, #run_subcommand
Methods included from Helper::Trivia
#check_path?, #check_subpath?, #class_to_lowercase, class_to_lowercase, #delete_file, #ignore_path?, #ignore_path_base, #kwargs, #make_path, #path_checker, #search_file_upward
Constructor Details
This class inherits a constructor from Dapp::CLI
Instance Method Details
#latest_beta_version(current_spec) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dapp/cli/command/update.rb', line 28 def latest_beta_version(current_spec) minor_version = current_spec.version.approximate_recommendation url = "https://rubygems.org/api/v1/versions/#{current_spec.name}.json" response = Excon.get(url) if response.status == 200 JSON.parse(response.body) .reduce([]) { |versions, spec| versions << Gem::Version.new(spec['number']) } .reject { |spec_version| minor_version != spec_version.approximate_recommendation || current_spec.version >= spec_version } .first else warn "Cannot get `#{url}`: got bad http status `#{response.status}`" end end |
#run(argv = ARGV) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dapp/cli/command/update.rb', line 13 def run(argv = ARGV) self.class.(self, argv) spec = Gem::Specification.find do |s| File.fnmatch?(File.join(s.full_gem_path, '**', '*'), __FILE__, File::FNM_PATHNAME) end unless (latest_version = latest_beta_version(spec)).nil? try_lock do Gem.install(spec.name, latest_version) end end rescue Gem::FilePermissionError => e raise Errno::EACCES, e. end |
#try_lock ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/dapp/cli/command/update.rb', line 42 def try_lock old_umask = File.umask(0) file = nil begin begin file = ::File.open('/tmp/dapp-update-running.lock', ::File::RDWR | ::File::CREAT, 0777) ensure File.umask(old_umask) end if file.flock(::File::LOCK_EX | ::File::LOCK_NB) yield else puts 'There are other active dapp update process, exiting without update' end ensure file.close unless file.nil? end end |