How to use released_gems method of Gem Package

Best Rr_ruby code snippet using Gem.released_gems


Source:source_index.rb Github


Full Screen

...20 alias old_initialize initialize21 undef old_initialize22 %w(all_gems prerelease_gems load_gems_in latest_specs prerelease_specs23 released_specs add_spec add_specs remove_spec each specification24 index_signature gem_signature size length find_name search released_gems25 refresh! outdated == dump gems spec_dirs spec_dirs=).each do |meth|26 undef_method(meth) if method_defined?(meth)27 end28 include Enumerable29 attr_reader :gems # :nodoc:30 ##31 # Directories to use to refresh this SourceIndex when calling refresh!32 attr_accessor :spec_dirs33 class << self34 # Undef old methods35 %w(from_installed_gems installed_spec_directories36 from_gems_in load_specification).each do |meth|37 undef_method(meth) if instance_methods(true).find {|m| m.to_s == meth }38 end39 ##40 # Factory method to construct a source index instance for a given41 # path.42 #43 # deprecated::44 # If supplied, from_installed_gems will act just like45 # +from_gems_in+. This argument is deprecated and is provided46 # just for backwards compatibility, and should not generally47 # be used.48 #49 # return::50 # SourceIndex instance51 def from_installed_gems(*deprecated)52 if deprecated.empty?53 from_gems_in(*installed_spec_directories)54 else55 from_gems_in(*deprecated) # HACK: warn56 end57 end58 ##59 # Returns a list of directories from Gem.path that contain specifications.60 def installed_spec_directories61 Gem.path.collect {|dir| File.join(dir, "specifications") }62 end63 ##64 # Creates a new SourceIndex from the ruby format gem specifications in65 # +spec_dirs+.66 def from_gems_in(*spec_dirs)67 source_index = new68 source_index.spec_dirs = spec_dirs69 source_index.refresh!70 end71 ##72 # Loads a ruby-format specification from +file_name+ and returns the73 # loaded spec.74 def load_specification(file_name)75 Gem::Specification.load file_name76 end77 end78 ##79 # Constructs a source index instance from the provided specifications, which80 # is a Hash of gem full names and Gem::Specifications.81 #--82 # TODO merge @gems and @prerelease_gems and provide a separate method83 # #prerelease_gems84 def initialize(specifications = {})85 @gems = {}86 specifications.each {|_full_name, spec| add_spec spec }87 @spec_dirs = nil88 end89 # TODO: remove method90 def all_gems91 @gems92 end93 def prerelease_gems94 @gems.reject {|_name, gem| !gem.version.prerelease? }95 end96 def released_gems97 @gems.reject {|_name, gem| gem.version.prerelease? }98 end99 ##100 # Reconstruct the source index from the specifications in +spec_dirs+.101 def load_gems_in(*spec_dirs)102 @gems.clear103 spec_dirs.reverse_each do |spec_dir|104 spec_files = Dir.glob File.join(spec_dir, '*.gemspec')105 spec_files.each do |spec_file|106 gemspec = Gem::Specification.load spec_file107 add_spec gemspec if gemspec108 end109 end110 self111 end112 ##113 # Returns an Array specifications for the latest released versions114 # of each gem in this index.115 def latest_specs(include_prerelease = false)116 result = {|h, k| h[k] = [] }117 latest = {}118 sort.each do |_, spec|119 name = spec.name120 curr_ver = spec.version121 prev_ver = latest.key?(name) ? latest[name].version : nil122 next if !include_prerelease && curr_ver.prerelease?123 next unless prev_ver.nil? || curr_ver >= prev_ver ||124 latest[name].platform != Gem::Platform::RUBY125 if prev_ver.nil? ||126 (curr_ver > prev_ver && spec.platform == Gem::Platform::RUBY)127 result[name].clear128 latest[name] = spec129 end130 if spec.platform != Gem::Platform::RUBY131 result[name].delete_if do |result_spec|132 result_spec.platform == spec.platform133 end134 end135 result[name] << spec136 end137 # TODO: why is this a hash while @gems is an array? Seems like138 # structural similarity would be good.139 result.values.flatten140 end141 ##142 # An array including only the prerelease gemspecs143 def prerelease_specs144 prerelease_gems.values145 end146 ##147 # An array including only the released gemspecs148 def released_specs149 released_gems.values150 end151 ##152 # Add a gem specification to the source index.153 def add_spec(gem_spec, name = gem_spec.full_name)154 # No idea why, but the Indexer wants to insert them using original_name155 # instead of full_name. So we make it an optional arg.156 @gems[name] = gem_spec157 end158 ##159 # Add gem specifications to the source index.160 def add_specs(*gem_specs)161 gem_specs.each do |spec|162 add_spec spec163 end...

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:


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?