bundler-ri 0.1.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -2
  3. data/lib/bundler/ri.rb +62 -25
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0aaafcdd90268bda86bf7c039c956432ff4cebaf5ddef7fde68ed293cc57aada
4
- data.tar.gz: c0eb7b1c3fed3995a9caf396374dbd743faf49dc7e6d957b68954b5fa4246e91
3
+ metadata.gz: e20850cc5c40c8956e3a50cf6c4aa297a60a98c01e7a060b6e013a7b4293df5f
4
+ data.tar.gz: 48c2c0765c72c5e3162894693ea86119ea4a188a54f0e7b7db6b6f51e06bfdf5
5
5
  SHA512:
6
- metadata.gz: 9648c1197c8df7e39e06d5dbeea25aadf2d2798fec5c42378a0625dbf9d6c81dbcce42e8bdeb0543bf2924c7cbce894e9207df93fcb238b0626a12924a67d5f9
7
- data.tar.gz: 0a735338428d972a131cc3c5b55f2795462f353d6d2ce1e64be65dd94f1901eee4392c04eb575b4607071406b6984bdfaef383313f2decb350aa78bc01695d1e
6
+ metadata.gz: 255138dc53a7524d3ed5c05ca2c8913947ad3409e63d6fa97e59a1e2037776990d3b110a158ce84fd780ecf658fecb0bd17c3211711bcf50b0c83066041065c6
7
+ data.tar.gz: ba116a44f8389a20d43b0258d98553c89b4500207425bfad18668964b9e9022dfaad6c0bf1a3b89bafc4c8f0b0883f7db8c70cdeed47b340c3e2c168255d7794
data/README.md CHANGED
@@ -25,8 +25,7 @@ See: https://guides.rubygems.org/bundler_plugins/
25
25
  ### TODO
26
26
 
27
27
  * tests
28
- * don't regenerate docs we've already generated
29
- * transitive dependencies (some things like `rails` really rely on them)
28
+ * handle rdoc finickiness
30
29
 
31
30
  ## Contributing
32
31
 
data/lib/bundler/ri.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rdoc"
4
+ require "digest/sha2"
4
5
 
5
6
  module Bundler
6
7
  class RI < Plugin::API
7
- VERSION = "0.1.1"
8
+ VERSION = "1.0.0"
8
9
 
9
10
  def self.register
10
11
  Bundler::Plugin.add_command("ri", Command)
@@ -14,24 +15,16 @@ module Bundler
14
15
  end
15
16
 
16
17
  module Helpers
17
- def ri_path
18
- Bundler::Plugin.root.join("ri")
19
- end
20
-
21
- def ri_path_for(dep)
22
- ri_path.join(resolved_name_for(dep))
18
+ def plugin_data_path
19
+ Bundler::Plugin.root.join("bundler-ri")
23
20
  end
24
21
 
25
- def resolved_name_for(dep)
26
- abs_path_for(dep).split("/").last
22
+ def ri_path
23
+ plugin_data_path.join("ri")
27
24
  end
28
25
 
29
- def abs_path_for(dep)
30
- if dep.source
31
- Bundler.root.to_s
32
- else
33
- dep.to_spec.full_gem_path
34
- end
26
+ def checksum_path
27
+ plugin_data_path.join("checksum")
35
28
  end
36
29
  end
37
30
 
@@ -41,7 +34,7 @@ module Bundler
41
34
  def exec(command, args)
42
35
  raise BundlerError.new("must run command 'ri' in root") unless SharedHelpers.in_bundle?
43
36
 
44
- Bundler.definition.dependencies.map { ri_path_for(_1).to_s }.each do |p|
37
+ Dir.glob(ri_path.join("*")).select do |p|
45
38
  next unless File.directory?(p)
46
39
 
47
40
  args << "--doc-dir"
@@ -59,32 +52,76 @@ module Bundler
59
52
  @deps = deps
60
53
  end
61
54
 
55
+ def checksum_for(spec)
56
+ normalized_filenames = RDoc::RDoc.new.tap { _1.options = RDoc::Options.new }.gather_files([spec.full_gem_path])
57
+ content = normalized_filenames.map { |f| File.read(f) }.join("\n")
58
+ ::Digest::SHA256.hexdigest(content)
59
+ end
60
+
61
+ def checksum_path_for(spec)
62
+ checksum_path.join(slug(spec))
63
+ end
64
+
65
+ def slug(spec)
66
+ "#{spec.name}-#{spec.version}"
67
+ end
68
+
62
69
  def run
63
- puts "bundler-ri: installing ri docs"
70
+ FileUtils.mkdir_p checksum_path
71
+ current_gems = []
72
+
73
+ Bundler.ui.info "bundler-ri: installing ri docs"
74
+
75
+ Bundler.load.specs.materialized_for_all_platforms.each do |spec|
76
+ Bundler.ui.debug "installing docs for #{slug(spec)}"
77
+ current_gems << slug(spec)
78
+
79
+ new_checksum = checksum_for(spec)
80
+ Bundler.ui.debug "checksum: #{spec.full_gem_path} -> #{new_checksum}"
64
81
 
65
- current_docs = []
82
+ old_checksum = begin
83
+ File.read(checksum_path_for(spec))
84
+ rescue
85
+ ""
86
+ end
66
87
 
67
- @deps.each do |dep|
68
- src_path = abs_path_for(dep).to_s
69
- doc_path = ri_path_for(dep).to_s
88
+ if old_checksum == new_checksum
89
+ Bundler.ui.debug "checksums match, skipping"
90
+ next
91
+ end
92
+
93
+ Bundler.ui.debug "checksum mismatch, regenerating ri docs"
94
+
95
+ src_path = spec.full_gem_path
96
+ doc_path = ri_path.join(slug(spec)).to_s
70
97
 
71
98
  RDoc::RDoc.new.document(
72
99
  [
73
100
  "--root", src_path,
74
101
  "-o", doc_path,
102
+ "-x", %q(\.rbs\z),
75
103
  "-r",
76
104
  "-q"
77
105
  ]
78
106
  )
79
107
 
80
- current_docs << doc_path
108
+ File.write(checksum_path_for(spec), new_checksum)
81
109
  end
82
110
 
83
- puts "bundler-ri: docs installed"
84
- current_docs.each { puts _1 }
111
+ Bundler.ui.info "bundler-ri: docs installed"
85
112
 
86
113
  Dir.glob(ri_path.join("*")).each do |p|
87
- FileUtils.rm_rf(p) unless current_docs.include? p
114
+ unless current_gems.include?(File.basename(p))
115
+ Bundler.ui.debug "deleting stale ri data: #{p}"
116
+ FileUtils.rm_rf(p)
117
+ end
118
+ end
119
+
120
+ Dir.glob(checksum_path.join("*")).each do |p|
121
+ unless current_gems.include?(File.basename(p))
122
+ Bundler.ui.debug "deleting stale ri data: #{p}"
123
+ FileUtils.rm_rf(p)
124
+ end
88
125
  end
89
126
  end
90
127
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bundler-ri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aidan Coyle