How to use update method of Gem Package

Best Rr_ruby code snippet using Gem.update

update_command.rb

Source:update_command.rb Github

copy

Full Screen

1require 'rubygems/command'2require 'rubygems/command_manager'3require 'rubygems/dependency_installer'4require 'rubygems/install_update_options'5require 'rubygems/local_remote_options'6require 'rubygems/spec_fetcher'7require 'rubygems/version_option'8require 'rubygems/install_message' # must come before rdoc for messaging9require 'rubygems/rdoc'10class Gem::Commands::UpdateCommand < Gem::Command11 include Gem::InstallUpdateOptions12 include Gem::LocalRemoteOptions13 include Gem::VersionOption14 attr_reader :installer # :nodoc:15 def initialize16 super 'update', 'Update installed gems to the latest version',17 :document => %w[rdoc ri],18 :force => false19 add_install_update_options20 OptionParser.accept Gem::Version do |value|21 Gem::Version.new value22 value23 end24 add_option('--system [VERSION]', Gem::Version,25 'Update the RubyGems system software') do |value, options|26 value = true unless value27 options[:system] = value28 end29 add_local_remote_options30 add_platform_option31 add_prerelease_option "as update targets"32 @updated = []33 @installer = nil34 end35 def arguments # :nodoc:36 "GEMNAME name of gem to update"37 end38 def defaults_str # :nodoc:39 "--document --no-force --install-dir #{Gem.dir}"40 end41 def usage # :nodoc:42 "#{program_name} GEMNAME [GEMNAME ...]"43 end44 def execute45 hig = {}46 if options[:system] then47 update_rubygems48 return49 else50 say "Updating installed gems"51 hig = {} # highest installed gems52 Gem::Specification.each do |spec|53 if hig[spec.name].nil? or hig[spec.name].version < spec.version then54 hig[spec.name] = spec55 end56 end57 end58 gems_to_update = which_to_update hig, options[:args].uniq59 updated = update_gems gems_to_update60 if updated.empty? then61 say "Nothing to update"62 else63 say "Gems updated: #{updated.map { |spec| spec.name }.join ' '}"64 end65 end66 def update_gem name, version = Gem::Requirement.default67 return if @updated.any? { |spec| spec.name == name }68 @installer ||= Gem::DependencyInstaller.new options69 success = false70 say "Updating #{name}"71 begin72 @installer.install name, version73 success = true74 rescue Gem::InstallError => e75 alert_error "Error installing #{name}:\n\t#{e.message}"76 success = false77 end78 @installer.installed_gems.each do |spec|79 @updated << spec80 end81 end82 def update_gems gems_to_update83 gems_to_update.uniq.sort.each do |(name, version)|84 update_gem name, version85 end86 @updated87 end88 ##89 # Update RubyGems software to the latest version.90 def update_rubygems91 unless options[:args].empty? then92 alert_error "Gem names are not allowed with the --system option"93 terminate_interaction 194 end95 options[:user_install] = false96 # TODO: rename version and other variable name conflicts97 # TODO: get rid of all this indirection on name and other BS98 version = options[:system]99 if version == true then100 version = Gem::Version.new Gem::VERSION101 requirement = Gem::Requirement.new ">= #{Gem::VERSION}"102 else103 version = Gem::Version.new version104 requirement = Gem::Requirement.new version105 end106 rubygems_update = Gem::Specification.new107 rubygems_update.name = 'rubygems-update'108 rubygems_update.version = version109 hig = {110 'rubygems-update' => rubygems_update111 }112 gems_to_update = which_to_update hig, options[:args], :system113 name, up_ver = gems_to_update.first114 current_ver = Gem.rubygems_version115 target = if options[:system] == true then116 up_ver117 else118 version119 end120 if current_ver == target then121 # if options[:system] != true and version == current_ver then122 say "Latest version currently installed. Aborting."123 terminate_interaction124 end125 update_gem name, target126 installed_gems = Gem::Specification.find_all_by_name 'rubygems-update', requirement127 version = installed_gems.last.version128 args = []129 args << '--prefix' << Gem.prefix if Gem.prefix130 # TODO use --document for >= 1.9 , --no-rdoc --no-ri < 1.9131 args << '--no-rdoc' unless options[:document].include? 'rdoc'132 args << '--no-ri' unless options[:document].include? 'ri'133 args << '--no-format-executable' if options[:no_format_executable]134 update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}"135 Dir.chdir update_dir do136 say "Installing RubyGems #{version}"137 setup_cmd = "#{Gem.ruby} setup.rb #{args.join ' '}"138 # Make sure old rubygems isn't loaded139 old = ENV["RUBYOPT"]140 ENV.delete("RUBYOPT") if old141 installed = system setup_cmd142 say "RubyGems system software updated" if installed143 ENV["RUBYOPT"] = old if old144 end145 end146 def which_to_update highest_installed_gems, gem_names, system = false147 result = []148 highest_installed_gems.each do |l_name, l_spec|149 next if not gem_names.empty? and150 gem_names.all? { |name| /#{name}/ !~ l_spec.name }151 dependency = Gem::Dependency.new l_spec.name, "> #{l_spec.version}"152 dependency.prerelease = options[:prerelease]153 fetcher = Gem::SpecFetcher.fetcher154 spec_tuples, _ = fetcher.search_for_dependency dependency155 matching_gems = spec_tuples.select do |g,_|156 g.name == l_name and g.match_platform?157 end158 highest_remote_gem = matching_gems.sort_by { |g,_| g.version }.last159 highest_remote_gem ||= [Gem::NameTuple.null]160 highest_remote_ver = highest_remote_gem.first.version...

Full Screen

Full Screen

update_checker.rb

Source:update_checker.rb Github

copy

Full Screen

...6require_relative '../ui/ui'7module FastlaneCore8 # Verifies, the user runs the latest version of this gem9 class UpdateChecker10 def self.start_looking_for_update(gem_name)11 return if Helper.test?12 return if FastlaneCore::Env.truthy?("FASTLANE_SKIP_UPDATE_CHECK")13 @start_time = Time.now14 Thread.new do15 begin16 server_results[gem_name] = fetch_latest(gem_name)17 rescue18 # we don't want to show a stack trace if something goes wrong19 end20 end21 end22 def self.server_results23 @results ||= {}24 end25 class << self26 attr_reader :start_time27 end28 def self.update_available?(gem_name, current_version)29 latest = server_results[gem_name]30 return (latest and Gem::Version.new(latest) > Gem::Version.new(current_version))31 end32 def self.show_update_status(gem_name, current_version)33 if update_available?(gem_name, current_version)34 show_update_message(gem_name, current_version)35 end36 end37 # Show a message to the user to update to a new version of fastlane (or a sub-gem)38 # Use this method, as this will detect the current Ruby environment and show an39 # appropriate message to the user40 def self.show_update_message(gem_name, current_version)41 available = server_results[gem_name]42 puts("")43 puts('#######################################################################')44 if available45 puts("# #{gem_name} #{available} is available. You are on #{current_version}.")46 else47 puts("# An update for #{gem_name} is available. You are on #{current_version}.")48 end49 puts("# You should use the latest version.")50 puts("# Please update using `#{self.update_command(gem_name: gem_name)}`.")51 puts("# To see what's new, open https://github.com/fastlane/#{gem_name}/releases.") if FastlaneCore::Env.truthy?("FASTLANE_HIDE_CHANGELOG")52 if !Helper.bundler? && !Helper.contained_fastlane? && Random.rand(5) == 153 # We want to show this message from time to time, if the user doesn't use bundler, nor bundled fastlane54 puts('#######################################################################')55 puts("# Run `sudo gem cleanup` from time to time to speed up fastlane")56 end57 puts('#######################################################################')58 Changelog.show_changes(gem_name, current_version, update_gem_command: UpdateChecker.update_command(gem_name: gem_name)) unless FastlaneCore::Env.truthy?("FASTLANE_HIDE_CHANGELOG")59 ensure_rubygems_source60 end61 # The command that the user should use to update their mac62 def self.update_command(gem_name: "fastlane")63 if Helper.bundler?64 "bundle update #{gem_name.downcase}"65 elsif Helper.contained_fastlane? || Helper.homebrew?66 "fastlane update_fastlane"67 elsif Helper.mac_app?68 "the Fabric app. Launch the app and navigate to the fastlane tab to get the most recent version."69 else70 "sudo gem install #{gem_name.downcase}"71 end72 end73 # Check if RubyGems is set as a gem source74 # on some machines that might not be the case75 # and then users can't find the update when76 # running the specified command77 def self.ensure_rubygems_source78 return if Helper.contained_fastlane?79 return if `gem sources`.include?("https://rubygems.org")80 puts("")81 UI.error("RubyGems is not listed as your Gem source")82 UI.error("You can run `gem sources` to see all your sources")83 UI.error("Please run the following command to fix this:")84 UI.command("gem sources --add https://rubygems.org")85 end86 def self.fetch_latest(gem_name)87 JSON.parse(Excon.get(generate_fetch_url(gem_name)).body)["version"]88 end89 def self.generate_fetch_url(gem_name)...

Full Screen

Full Screen

update

Using AI Code Generation

copy

Full Screen

1gem = Gem.new(2, 3, 4)2gem.update(5, 6, 7)3gem.update(8, 9, 10)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful