Module: Solargraph::YardMap::CoreDocs
- Defined in:
- lib/solargraph/yard_map/core_docs.rb
Overview
Tools for managing core documentation.
Constant Summary collapse
- SOURCE =
'https://solargraph.org/download'
Class Method Summary collapse
- .available ⇒ Object
- .best_download ⇒ Object
- .best_match ⇒ Object
- .cache_dir ⇒ Object
- .clear ⇒ Object
- .download(version) ⇒ Object
-
.require_minimum ⇒ Object
Ensure installation of minimum documentation.
- .valid?(ver) ⇒ Boolean
- .versions ⇒ Object
- .yard_stdlib_file(ver = best_match) ⇒ Object
- .yardoc_file(ver = best_match) ⇒ Object
Class Method Details
.available ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/solargraph/yard_map/core_docs.rb', line 53 def available uri = URI.parse("#{SOURCE}/versions.json") response = Net::HTTP.get_response(uri) obj = JSON.parse(response.body) raise SourceNotAvailableError.new("Error connecting to #{SOURCE}") unless obj['status'] == 'ok' obj['cores'] end |
.best_download ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/solargraph/yard_map/core_docs.rb', line 61 def best_download rv = Gem::Version.new(RUBY_VERSION) available.each do |ver| return ver if Gem::Version.new(ver) <= rv end obj['cores'].last end |
.best_match ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/solargraph/yard_map/core_docs.rb', line 45 def best_match available = versions available.each do |v| return v if Gem::Version.new(v) <= Gem::Version.new(RUBY_VERSION) end return available.last end |
.cache_dir ⇒ Object
14 15 16 |
# File 'lib/solargraph/yard_map/core_docs.rb', line 14 def cache_dir @cache_dir ||= File.join(Dir.home, '.solargraph', 'cache') end |
.clear ⇒ Object
88 89 90 91 |
# File 'lib/solargraph/yard_map/core_docs.rb', line 88 def clear FileUtils.rm_rf cache_dir, secure: true require_minimum end |
.download(version) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/solargraph/yard_map/core_docs.rb', line 79 def download version FileUtils.mkdir_p cache_dir uri = URI.parse("#{SOURCE}/#{version}.tar.gz") response = Net::HTTP.get_response(uri) zipfile = File.join(cache_dir, "#{version}.tar.gz") File.binwrite zipfile, response.body install_archive zipfile end |
.require_minimum ⇒ Object
Ensure installation of minimum documentation.
20 21 22 23 24 25 26 27 28 |
# File 'lib/solargraph/yard_map/core_docs.rb', line 20 def require_minimum return unless best_match.nil? FileUtils.mkdir_p cache_dir version_dir = File.join(cache_dir, '2.2.2') unless File.exist?(version_dir) FileUtils.cp File.join(Solargraph::YARDOC_PATH, '2.2.2.tar.gz'), cache_dir install_archive File.join(cache_dir, '2.2.2.tar.gz') end end |
.valid?(ver) ⇒ Boolean
30 31 32 33 34 35 36 |
# File 'lib/solargraph/yard_map/core_docs.rb', line 30 def valid?(ver) dir = File.join(cache_dir, ver) return false unless File.directory?(dir) return false unless File.directory?(File.join(dir, 'yardoc')) return false unless File.directory?(File.join(dir, 'yardoc-stdlib')) true end |
.versions ⇒ Object
38 39 40 41 42 43 |
# File 'lib/solargraph/yard_map/core_docs.rb', line 38 def versions dirs = Dir[File.join(cache_dir, '*')].map{|d| File.basename(d)} dirs.keep_if{|d| valid?(d)} dirs.sort!{|a, b| Gem::Version.new(b) <=> Gem::Version.new(a)} dirs end |
.yard_stdlib_file(ver = best_match) ⇒ Object
74 75 76 77 |
# File 'lib/solargraph/yard_map/core_docs.rb', line 74 def yard_stdlib_file(ver = best_match) raise ArgumentError.new("Invalid core yardoc version #{ver}") unless valid?(ver) File.join(cache_dir, ver, 'yardoc-stdlib') end |
.yardoc_file(ver = best_match) ⇒ Object
69 70 71 72 |
# File 'lib/solargraph/yard_map/core_docs.rb', line 69 def yardoc_file(ver = best_match) raise ArgumentError.new("Invalid core yardoc version #{ver}") unless valid?(ver) File.join(cache_dir, ver, 'yardoc') end |