How to use specification method of Gem Package

Best Rr_ruby code snippet using Gem.specification

gem_dependency.rb

Source:gem_dependency.rb Github

copy

Full Screen

...27 directory_name_parts = File.basename(directory_name).split('-')28 name = directory_name_parts[0..-2].join('-')29 version = directory_name_parts.last30 result = self.new(name, :version => version)31 spec_filename = File.join(directory_name, '.specification')32 if load_spec33 raise "Missing specification file in #{File.dirname(spec_filename)}. Perhaps you need to do a 'rake gems:refresh_specs'?" unless File.exists?(spec_filename)34 spec = YAML::load_file(spec_filename)35 result.specification = spec36 end37 result38 rescue ArgumentError => e39 raise "Unable to determine gem name and version from '#{directory_name}'"40 end41 def initialize(name, options = {})42 require 'rubygems' unless Object.const_defined?(:Gem)43 if options[:requirement]44 req = options[:requirement]45 elsif options[:version]46 req = Gem::Requirement.create(options[:version])47 else48 req = Gem::Requirement.default49 end50 @lib = options[:lib]51 @source = options[:source]52 @loaded = @frozen = @load_paths_added = false53 super(name, req)54 end55 def add_load_paths56 self.class.add_frozen_gem_path57 return if @loaded || @load_paths_added58 if framework_gem?59 @load_paths_added = @loaded = @frozen = true60 return61 end62 gem self63 @spec = Gem.loaded_specs[name]64 @frozen = @spec.loaded_from.include?(self.class.unpacked_path) if @spec65 @load_paths_added = true66 rescue Gem::LoadError67 end68 def dependencies69 return [] if framework_gem?70 return [] unless installed?71 specification.dependencies.reject do |dependency|72 dependency.type == :development73 end.map do |dependency|74 GemDependency.new(dependency.name, :requirement => dependency.version_requirements)75 end76 end77 def specification78 # code repeated from Gem.activate. Find a matching spec, or the currently loaded version.79 # error out if loaded version and requested version are incompatible.80 @spec ||= begin81 matches = Gem.source_index.search(self)82 matches << @@framework_gems[name] if framework_gem?83 if Gem.loaded_specs[name] then84 # This gem is already loaded. If the currently loaded gem is not in the85 # list of candidate gems, then we have a version conflict.86 existing_spec = Gem.loaded_specs[name]87 unless matches.any? { |spec| spec.version == existing_spec.version } then88 raise Gem::Exception,89 "can't activate #{@dep}, already activated #{existing_spec.full_name}"90 end91 # we're stuck with it, so change to match92 version_requirements = Gem::Requirement.create("=#{existing_spec.version}")93 existing_spec94 else95 # new load96 matches.last97 end98 end99 end100 def specification=(s)101 @spec = s102 end103 def requirement104 r = version_requirements105 (r == Gem::Requirement.default) ? nil : r106 end107 def built?108 return false unless frozen?109 if vendor_gem?110 specification.extensions.each do |ext|111 makefile = File.join(unpacked_gem_directory, File.dirname(ext), 'Makefile')112 return false unless File.exists?(makefile)113 end114 end115 true116 end117 def framework_gem?118 @@framework_gems.has_key?(name)119 end120 def frozen?121 @frozen ||= vendor_rails? || vendor_gem?122 end123 def installed?124 Gem.loaded_specs.keys.include?(name)125 end126 def load_paths_added?127 # always try to add load paths - even if a gem is loaded, it may not128 # be a compatible version (ie random_gem 0.4 is loaded and a later spec129 # needs >= 0.5 - gem 'random_gem' will catch this and error out)130 @load_paths_added131 end132 def loaded?133 @loaded ||= begin134 if vendor_rails?135 true136 elsif specification.nil?137 false138 else139 # check if the gem is loaded by inspecting $"140 # specification.files lists all the files contained in the gem141 gem_files = specification.files142 # select only the files contained in require_paths - typically in bin and lib143 require_paths_regexp = Regexp.new("^(#{specification.require_paths*'|'})/")144 gem_lib_files = gem_files.select { |f| require_paths_regexp.match(f) }145 # chop the leading directory off - a typical file might be in146 # lib/gem_name/file_name.rb, but it will be 'require'd as gem_name/file_name.rb147 gem_lib_files.map! { |f| f.split('/', 2)[1] }148 # if any of the files from the above list appear in $", the gem is assumed to149 # have been loaded150 !(gem_lib_files & $").empty?151 end152 end153 end154 def vendor_rails?155 Gem.loaded_specs.has_key?(name) && Gem.loaded_specs[name].loaded_from.empty?156 end157 def vendor_gem?158 specification && File.exists?(unpacked_gem_directory)159 end160 def build(options={})161 require 'rails/gem_builder'162 return if specification.nil?163 if options[:force] || !built?164 return unless File.exists?(unpacked_specification_filename)165 spec = YAML::load_file(unpacked_specification_filename)166 Rails::GemBuilder.new(spec, unpacked_gem_directory).build_extensions167 puts "Built gem: '#{unpacked_gem_directory}'"168 end169 dependencies.each { |dep| dep.build(options) }170 end171 def install172 unless installed?173 cmd = "#{gem_command} #{install_command.join(' ')}"174 puts cmd175 puts %x(#{cmd})176 end177 end178 def load179 return if @loaded || @load_paths_added == false180 require(@lib || name) unless @lib == false181 @loaded = true182 rescue LoadError183 puts $!.to_s184 $!.backtrace.each { |b| puts b }185 end186 def refresh187 Rails::VendorGemSourceIndex.silence_spec_warnings = true188 real_gems = Gem.source_index.installed_source_index189 exact_dep = Gem::Dependency.new(name, "= #{specification.version}")190 matches = real_gems.search(exact_dep)191 installed_spec = matches.first192 if frozen?193 if installed_spec194 # we have a real copy195 # get a fresh spec - matches should only have one element196 # note that there is no reliable method to check that the loaded197 # spec is the same as the copy from real_gems - Gem.activate changes198 # some of the fields199 real_spec = Gem::Specification.load(matches.first.loaded_from)200 write_specification(real_spec)201 puts "Reloaded specification for #{name} from installed gems."202 else203 # the gem isn't installed locally - write out our current specs204 write_specification(specification)205 puts "Gem #{name} not loaded locally - writing out current spec."206 end207 else208 if framework_gem?209 puts "Gem directory for #{name} not found - check if it's loading before rails."210 else211 puts "Something bad is going on - gem directory not found for #{name}."212 end213 end214 end215 def unpack(options={})216 unless frozen? || framework_gem?217 FileUtils.mkdir_p unpack_base218 Dir.chdir unpack_base do219 Gem::GemRunner.new.run(unpack_command)220 end221 # Gem.activate changes the spec - get the original222 real_spec = Gem::Specification.load(specification.loaded_from)223 write_specification(real_spec)224 end225 dependencies.each { |dep| dep.unpack(options) } if options[:recursive]226 end227 def write_specification(spec)228 # copy the gem's specification into GEMDIR/.specification so that229 # we can access information about the gem on deployment systems230 # without having the gem installed231 File.open(unpacked_specification_filename, 'w') do |file|232 file.puts spec.to_yaml233 end234 end235 def ==(other)236 self.name == other.name && self.requirement == other.requirement237 end238 alias_method :"eql?", :"=="239 private240 def gem_command241 case RUBY_PLATFORM242 when /win32/243 'gem.bat'244 when /java/245 'jruby -S gem'246 else247 'gem'248 end249 end250 def install_command251 cmd = %w(install) << name252 cmd << "--version" << %("#{requirement.to_s}") if requirement253 cmd << "--source" << @source if @source254 cmd255 end256 def unpack_command257 cmd = %w(unpack) << name258 cmd << "--version" << "= "+specification.version.to_s if requirement259 cmd260 end261 def unpack_base262 Rails::GemDependency.unpacked_path263 end264 def unpacked_gem_directory265 File.join(unpack_base, specification.full_name)266 end267 def unpacked_specification_filename268 File.join(unpacked_gem_directory, '.specification')269 end270 end271end...

Full Screen

Full Screen

specification

Using AI Code Generation

copy

Full Screen

1pp Gem::Specification.find_by_name("rake")2pp Gem::Specification.find_all_by_name("rake")3pp Gem::Specification.load("rake.gemspec")4pp Gem::Specification.latest_specs(true)5pp Gem::Specification.map(&:name)

Full Screen

Full Screen

specification

Using AI Code Generation

copy

Full Screen

1puts Gem::Specification.find_by_name("rails").version2puts Gem::Version.new(Gem::Specification.find_by_name("rails").version.to_s)3puts Gem::Specification.find_by_name("rails").version.to_s4puts Gem::Specification.find_by_name("rails").version.version5Your name to display (optional):

Full Screen

Full Screen

specification

Using AI Code Generation

copy

Full Screen

1Bundler.require(:default)2Bundler.require(:development)3Bundler.require(:test)4Bundler.require(:production)5Bundler.require(:development, :test)6Bundler.require(:development, :test, :production)7Bundler.require(:development, :test, :production, :custom)8Bundler.require(:development, :test, :production, :custom, :another)9Bundler.require(:development, :test, :production, :custom, :another, :last)10Bundler.require(:development, :test, :production, :custom, :another, :last, :group)11Bundler.require(:development, :test, :production, :custom, :another, :last, :group, :groups)

Full Screen

Full Screen

specification

Using AI Code Generation

copy

Full Screen

1spec = Gem::Specification.find_by_name('rake', '0.8.3')2spec = Gem::Specification.find_by_name('rake')3spec = Gem::Specification.find_by_name('rake')4spec = Gem::Specification.find_by_name('rake', '0.8.3')5spec = Gem::Specification.find_by_name('rake', '0.8.3')6spec = Gem::Specification.find_by_name('rake')7spec = Gem::Specification.find_by_name('rake')8spec = Gem::Specification.find_by_name('r

Full Screen

Full Screen

specification

Using AI Code Generation

copy

Full Screen

1Gem.load_path('rspec')2Gem.load_path('rspec')3Gem.load_path('rspec')

Full Screen

Full Screen

specification

Using AI Code Generation

copy

Full Screen

1spec = Gem::Specification.find_by_name('rake', '0.8.3')2spec = Gem::Specification.find_by_name('rake')3spec = Gem::Specification.find_by_name('rake')4spec = Gem::Specification.find_by_name('rake', '0.8.3')5spec = Gem::Specification.find_by_name('rake', '0.8.3')6spec = Gem::Specification.find_by_name('rake')7spec = Gem::Specification.find_by_name('rake')8spec = Gem::Specification.find_by_name('r

Full Screen

Full Screen

specification

Using AI Code Generation

copy

Full Screen

1Gem.load_path('rspec')2Gem.load_path('rspec')3Gem.load_path('rspec')

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