Module: FastRI::Util
- Defined in:
- lib/fastri/util.rb
Defined Under Namespace
Modules: MagicHelp
Class Method Summary collapse
- .change_query_method_type(query) ⇒ Object
-
.find_home ⇒ Object
Returns the home directory (win32-aware).
-
.gem_directories_unique ⇒ Object
Return an array of
[name, version, path]
arrays corresponding to the last version of each installed gem. -
.gem_info_for_path(path, gem_dir_info = FastRI::Util.gem_directories_unique) ⇒ Object
Return the
[name, version, path]
array for the gem owning the RI information stored inpath
, ornil
. -
.gem_relpath_to_full_name(relpath) ⇒ Object
Return the
full_name
(in ClassEntry or MethodEntry’s sense) given a path to a .yaml file relative to a “base RI DB path”.
Class Method Details
.change_query_method_type(query) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/fastri/util.rb', line 114 def change_query_method_type(query) if md = /\A(.*)(#|\.|::)([^#.:]+)\z/.match(query) namespace, sep, meth = md.captures case sep when /::/ then "#{namespace}##{meth}" when /#/ then "#{namespace}::#{meth}" else query end else query end end |
.find_home ⇒ Object
Returns the home directory (win32-aware).
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fastri/util.rb', line 94 def find_home # stolen from RubyGems ['HOME', 'USERPROFILE'].each do |homekey| return ENV[homekey] if ENV[homekey] end if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] return "#{ENV['HOMEDRIVE']}:#{ENV['HOMEPATH']}" end begin File.("~") rescue StandardError => ex if File::ALT_SEPARATOR "C:/" else "/" end end end |
.gem_directories_unique ⇒ Object
Return an array of [name, version, path]
arrays corresponding to the last version of each installed gem. path
is the base path of the RI documentation from the gem. If the version cannot be determined, it will be nil
, and the corresponding gem might be repeated in the output array (once per version).
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fastri/util.rb', line 49 def gem_directories_unique return [] unless defined? Gem gemdirs = Gem.path.map{|p| Dir["#{p}/doc/*/ri"]}.flatten gems = Hash.new{|h,k| h[k] = []} gemdirs.each do |path| gemname, version = %r{/([^/]+)-([^-]*)/ri$}.match(path).captures if gemname.nil? # doesn't follow any conventions :( gems[path[%r{/([^/]+)/ri$}, 1]] << [nil, path] else gems[gemname] << [version, path] end end gems.sort_by{|name, _| name}.map do |name, versions| version, path = versions.sort.last [name, version, File.(path)] end end |
.gem_info_for_path(path, gem_dir_info = FastRI::Util.gem_directories_unique) ⇒ Object
Return the [name, version, path]
array for the gem owning the RI information stored in path
, or nil
.
70 71 72 73 74 |
# File 'lib/fastri/util.rb', line 70 def gem_info_for_path(path, gem_dir_info = FastRI::Util.gem_directories_unique) path = File.(path) matches = gem_dir_info.select{|name, version, gem_path| path.index(gem_path) == 0} matches.sort_by{|name, version, gem_path| [gem_path.size, version, name]}.last end |
.gem_relpath_to_full_name(relpath) ⇒ Object
Return the full_name
(in ClassEntry or MethodEntry’s sense) given a path to a .yaml file relative to a “base RI DB path”.
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/fastri/util.rb', line 79 def gem_relpath_to_full_name(relpath) case relpath when %r{^(.*)/cdesc-([^/]*)\.yaml$} path, name = $~.captures (path.split(%r{/})[0..-2] << name).join("::") when %r{^(.*)/([^/]*)-(i|c)\.yaml$} path, escaped_name, type = $~.captures name = RI::RiWriter.external_to_internal(escaped_name) sep = ( type == 'c' ) ? "." : "#" path.gsub("/", "::") + sep + name end end |