Class: Gem::Source::Local
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::Gem::Source
|
|
Instance Chain:
self,
::Gem::Source ,
::Gem::Text ,
Comparable
|
|
Inherits: |
Gem::Source
|
Defined in: | lib/rubygems/source/local.rb |
Overview
The local source finds gems in the current directory for fulfilling dependencies.
Constant Summary
::Gem::Source
- Inherited
Class Method Summary
- .new ⇒ Local constructor Internal use only
::Gem::Source
- Inherited
.new | Creates a new |
Instance Attribute Summary
::Gem::Source
- Inherited
#update_cache? | Returns true when it is possible and safe to update the cache directory. |
#uri | The URI this source will fetch gems from. |
Instance Method Summary
-
#<=>(other)
Local
sorts before::Gem::Source
and afterInstalled
- #download(spec, cache_dir = nil) Internal use only
- #fetch_spec(name) Internal use only
- #find_gem(gem_name, version = Gem::Requirement.default, prerelease = false) Internal use only
- #inspect Internal use only
- #load_specs(type) Internal use only
- #pretty_print(q) Internal use only
::Gem::Source
- Inherited
#<=> | Sources are ordered by installation preference. |
#cache_dir | Returns the local directory to write #uri to. |
#download | Downloads |
#fetch_spec | Fetches a specification for the given |
#load_specs | Loads |
#typo_squatting?, #enforce_trailing_slash, #==, | |
#dependency_resolver_set | Returns a Set that can fetch specifications from this source. |
#eql? | Alias for #==. |
#hash, #pretty_print |
::Gem::Text
- Included
#clean_text | Remove any non-printable characters and make the text suitable for printing. |
#format_text | Wraps |
#levenshtein_distance | Returns a value representing the “cost” of transforming str1 into str2 Vendored version of |
#truncate_text, #min3 |
Constructor Details
.new ⇒ Local
# File 'lib/rubygems/source/local.rb', line 8
def initialize # :nodoc: @specs = nil @api_uri = nil @uri = nil @load_specs_names = {} end
Instance Method Details
#<=>(other)
Local
sorts before ::Gem::Source
and after Installed
#download(spec, cache_dir = nil)
# File 'lib/rubygems/source/local.rb', line 114
def download(spec, cache_dir = nil) # :nodoc: load_specs :complete @specs.each do |name, data| return data[0] if data[1].spec == spec end raise Gem::Exception, "Unable to find file for '#{spec.full_name}'" end
#fetch_spec(name)
# File 'lib/rubygems/source/local.rb', line 104
def fetch_spec(name) # :nodoc: load_specs :complete if data = @specs[name] data.last.spec else raise Gem::Exception, "Unable to find spec for #{name.inspect}" end end
#find_gem(gem_name, version = Gem::Requirement.default, prerelease = false)
# File 'lib/rubygems/source/local.rb', line 81
def find_gem(gem_name, version = Gem::Requirement.default, # :nodoc: prerelease = false) load_specs :complete found = [] @specs.each do |n, data| if n.name == gem_name s = data[1].spec if version.satisfied_by?(s.version) if prerelease found << s elsif !s.version.prerelease? || version.prerelease? found << s end end end end found.max_by {|s| s.version } end
#inspect
# File 'lib/rubygems/source/local.rb', line 32
def inspect # :nodoc: keys = @specs ? @specs.keys.sort : "NOT LOADED" "#<%s specs: %p>" % [self.class, keys] end
#load_specs(type)
# File 'lib/rubygems/source/local.rb', line 37
def load_specs(type) # :nodoc: @load_specs_names[type] ||= begin names = [] @specs = {} Dir["*.gem"].each do |file| begin pkg = Gem::Package.new(file) rescue SystemCallError, Gem::Package::FormatError # ignore else tup = pkg.spec.name_tuple @specs[tup] = [File. (file), pkg] case type when :released unless pkg.spec.version.prerelease? names << pkg.spec.name_tuple end when :prerelease if pkg.spec.version.prerelease? names << pkg.spec.name_tuple end when :latest tup = pkg.spec.name_tuple cur = names.find {|x| x.name == tup.name } if !cur names << tup elsif cur.version < tup.version names.delete cur names << tup end else names << pkg.spec.name_tuple end end end names end end
#pretty_print(q)
# File 'lib/rubygems/source/local.rb', line 124
def pretty_print(q) # :nodoc: q.group 2, "[Local gems:", "]" do q.breakable q.seplist @specs.keys do |v| q.text v.full_name end end end