How to use installed_spec_directories method of Gem Package

Best Rr_ruby code snippet using Gem.installed_spec_directories

source_index.rb

Source:source_index.rb Github

copy

Full Screen

...38 # SourceIndex instance39 #40 def from_installed_gems(*deprecated)41 if deprecated.empty?42 from_gems_in(*installed_spec_directories)43 else44 from_gems_in(*deprecated)45 end46 end47 48 # Return a list of directories in the current gem path that49 # contain specifications.50 # 51 # return::52 # List of directory paths (all ending in "../specifications").53 #54 def installed_spec_directories55 Gem.path.collect { |dir| File.join(dir, "specifications") }56 end57 # Factory method to construct a source index instance for a58 # given path.59 # 60 # spec_dirs::61 # List of directories to search for specifications. Each62 # directory should have a "specifications" subdirectory63 # containing the gem specifications.64 #65 # return::66 # SourceIndex instance67 #68 def from_gems_in(*spec_dirs)69 self.new.load_gems_in(*spec_dirs)70 end71 72 # Load a specification from a file (eval'd Ruby code)73 # 74 # file_name:: [String] The .gemspec file75 # return:: Specification instance or nil if an error occurs76 #77 def load_specification(file_name)78 begin79 spec_code = File.read(file_name).untaint80 gemspec = eval(spec_code)81 if gemspec.is_a?(Gem::Specification)82 gemspec.loaded_from = file_name83 return gemspec84 end85 alert_warning "File '#{file_name}' does not evaluate to a gem specification"86 rescue SyntaxError => e87 alert_warning e88 alert_warning spec_code89 rescue Exception => e90 alert_warning(e.inspect.to_s + "\n" + spec_code)91 alert_warning "Invalid .gemspec format in '#{file_name}'"92 end93 return nil94 end95 96 end97 # Instance Methods -----------------------------------------------98 # Constructs a source index instance from the provided99 # specifications100 #101 # specifications::102 # [Hash] hash of [Gem name, Gem::Specification] pairs103 #104 def initialize(specifications={})105 @gems = specifications106 end107 108 # Reconstruct the source index from the list of source109 # directories.110 def load_gems_in(*spec_dirs)111 @gems.clear112 Dir.glob("{#{spec_dirs.join(',')}}/*.gemspec").each do |file_name|113 gemspec = self.class.load_specification(file_name.untaint)114 add_spec(gemspec) if gemspec115 end116 self117 end118 # Add a gem specification to the source index.119 def add_spec(gem_spec)120 @gems[gem_spec.full_name] = gem_spec121 end122 # Remove a gem specification named +full_name+.123 def remove_spec(full_name)124 @gems.delete(full_name)125 end126 # Iterate over the specifications in the source index.127 #128 # &block:: [yields gem.full_name, Gem::Specification]129 #130 def each(&block)131 @gems.each(&block)132 end133 # The gem specification given a full gem spec name.134 def specification(full_name)135 @gems[full_name]136 end137 # The signature for the source index. Changes in the signature138 # indicate a change in the index.139 def index_signature140 Digest::SHA256.new(@gems.keys.sort.join(',')).to_s141 end142 # The signature for the given gem specification.143 def gem_signature(gem_full_name)144 Digest::SHA256.new(@gems[gem_full_name].to_yaml).to_s145 end146 def_delegators :@gems, :size, :length147 # Find a gem by an exact match on the short name.148 def find_name(gem_name, version_requirement=Version::Requirement.new(">= 0"))149 search(/^#{gem_name}$/, version_requirement)150 end151 # Search for a gem by short name pattern and optional version152 #153 # gem_name::154 # [String] a partial for the (short) name of the gem, or155 # [Regex] a pattern to match against the short name156 # version_requirement::157 # [String | default=Version::Requirement.new(">= 0")] version to158 # find159 # return::160 # [Array] list of Gem::Specification objects in sorted (version)161 # order. Empty if not found.162 #163 def search(gem_pattern, version_requirement=Version::Requirement.new(">= 0"))164 #FIXME - remove duplication between this and RemoteInstaller.search165 gem_pattern = /#{ gem_pattern }/i if String === gem_pattern166 version_requirement = Gem::Version::Requirement.create(version_requirement)167 result = []168 @gems.each do |full_spec_name, spec|169 next unless spec.name =~ gem_pattern170 result << spec if version_requirement.satisfied_by?(spec.version)171 end172 result = result.sort173 result174 end175 # Refresh the source index from the local file system.176 #177 # return:: Returns a pointer to itself.178 #179 def refresh!180 load_gems_in(self.class.installed_spec_directories)181 end182 183 end184 # Cache is an alias for SourceIndex to allow older YAMLized source185 # index objects to load properly.186 Cache = SourceIndex187end...

Full Screen

Full Screen

installed_spec_directories

Using AI Code Generation

copy

Full Screen

1 - RUBY VERSION: 1.8.6 (2008-08-11 patchlevel 111) [universal-darwin8.0]2actionmailer (1.3.3)3actionpack (1.13.3)4activerecord (1.15.3)5activeresource (1.4.3)6activesupport (1.4.4)7builder (2.0.0)8erubis (2.5.2)9hpricot (0.6)10i18n (0.1.1)11libxml-ruby (0.8.0)12mail (2.0.2)13mime-types (1.11)14mysql (2.7)15mysqlplus (0.1.2)16polyglot (0.3.1)17rack (0.9.1)18rails (1.2.6)19rake (0.8.1)20RedCloth (3.0.4)

Full Screen

Full Screen

installed_spec_directories

Using AI Code Generation

copy

Full Screen

1puts Gem::Specification.find_by_name("rake")2puts Gem::Specification.find_by_name("rake", "0.8.7")3puts Gem::Specification.find_by_name("rake", "0.8.7").version4puts Gem::Specification.find_by_name("rake", "0.8.7").version.to_s5puts Gem::Specification.find_by_name("rake", "0.8.7").version.to_s + " " + Gem::Specification.find_by_name("rake", "0.8.7").name6puts Gem::Specification.find_by_name("rake", "0.8.7").version.to_s + " " + Gem::Specification.find_by_name("rake", "0.8.7").name + " " + Gem::Specification.find_by_name("rake", "0.8.7").summary

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