devpack 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e0060c2ad41fd138a702fdd931eafdd5798940ea173e6a2aa30cb638a9975ee
4
- data.tar.gz: 79d3b3d0c6de5c4dfc3795d6bdb6a58d5e0316e95dd85d609a1bcb6f3172f39e
3
+ metadata.gz: 2ec75af91bddba1020bdc23508c881dfc9da92c5c0a69793935c1839d699139e
4
+ data.tar.gz: 7751b678c8a59010a8a5160a108e3c0c672d37104ca44e41c8f4d0c2c6ec280c
5
5
  SHA512:
6
- metadata.gz: c78cedc44a1fdab0fd5086776e9b6bb9a96c8ccffd34d83cf62e9b1b48da9fb3ae28161bacb048de8fbfc8c438c4c9bb4bcb63a5a56548e437facc6f3d7de042
7
- data.tar.gz: e32424c2f6d7cc63fadbff9542c0980469837d0821378987e82830db4262e1c323b62e69c49188b9acf44a2823c78a262697ee383e2887ec748f78bbaee90f28
6
+ metadata.gz: '09208ee73b785fbf9c67ad5375ab672e15241bf561216e27cab3db7292d0e7f2ed198d0cf159f544acaef4cd6241f9ed1f0e9e44beb31b1fef236f8ccd47fe36'
7
+ data.tar.gz: e4301ef053caf42a34463f9ffc1f816d6203144d36e9920c21895d92cbb17354c27b90716c1e5177b878d0d4cae73b6523a7e2e2f96db3643be6164144d68ccb
@@ -15,3 +15,9 @@ Load latest version of gem by default. Allow specifying version with rubygems sy
15
15
  Permit comments in config file.
16
16
 
17
17
  Use `Gem::Specification` to load "rendered" gemspec (i.e. the file created by rubygems when the gem is installed). This version of the gemspec will load very quickly so no need to do custom gemspec parsing any more. This also accounts for "missing" gemspecs.
18
+
19
+ ## 0.1.2
20
+
21
+ Recursively include gem dependencies in `$LOAD_PATH` rather than assuming that any dependencies are already loaded.
22
+
23
+ Include original error message when warning that a gem was unable to be loaded.
data/README.md CHANGED
@@ -8,7 +8,7 @@ Add the gem to your `Gemfile`:
8
8
 
9
9
  ```ruby
10
10
  group :development, :test do
11
- gem 'devpack', '~> 0.1.1'
11
+ gem 'devpack', '~> 0.1.2'
12
12
  end
13
13
  ```
14
14
 
@@ -9,17 +9,28 @@ module Devpack
9
9
  @glob = glob
10
10
  end
11
11
 
12
- def require_paths
12
+ def require_paths(visited = Set.new)
13
13
  return [] unless gemspec_path&.exist? && gem_path&.exist?
14
14
 
15
- Gem::Specification
16
- .load(gemspec_path.to_s)
17
- .require_paths
18
- .map { |path| gem_path.join(path).to_s }
15
+ (immediate_require_paths + dependency_require_paths(visited))
16
+ .compact.flatten.uniq
19
17
  end
20
18
 
21
19
  private
22
20
 
21
+ def dependency_require_paths(visited)
22
+ dependencies.map do |dependency|
23
+ next nil if visited.include?(dependency)
24
+
25
+ visited << dependency
26
+ GemPath.new(@glob, name_with_version(dependency)).require_paths(visited)
27
+ end
28
+ end
29
+
30
+ def dependencies
31
+ gemspec.runtime_dependencies
32
+ end
33
+
23
34
  def gem_path
24
35
  return nil if located_gem.nil?
25
36
 
@@ -33,6 +44,23 @@ module Devpack
33
44
  .expand_path
34
45
  end
35
46
 
47
+ def gemspec
48
+ @gemspec ||= Gem::Specification.load(gemspec_path.to_s)
49
+ end
50
+
51
+ def immediate_require_paths
52
+ gemspec
53
+ .require_paths
54
+ .map { |path| gem_path.join(path).to_s }
55
+ end
56
+
57
+ def name_with_version(dependency)
58
+ spec = dependency.to_spec
59
+ "#{spec.name}:#{spec.version}"
60
+ rescue Gem::MissingSpecError
61
+ dependency.name
62
+ end
63
+
36
64
  def located_gem
37
65
  @located_gem ||= @glob.find(@name)
38
66
  end
@@ -31,8 +31,8 @@ module Devpack
31
31
  def load_gem(name)
32
32
  update_load_path(name)
33
33
  [name, Kernel.require(name)]
34
- rescue LoadError
35
- warn(Messages.failure_message(name))
34
+ rescue LoadError => e
35
+ warn(Messages.failure_message(name, e))
36
36
  nil
37
37
  end
38
38
 
@@ -3,10 +3,10 @@
3
3
  module Devpack
4
4
  # Generates output messages.
5
5
  class Messages
6
- def self.failure_message(name)
6
+ def self.failure_message(name, error)
7
7
  base = "Failed to load `#{name}`"
8
8
  install = "bundle exec gem install #{name}"
9
- "#{base}. Try `#{install}`"
9
+ "#{base}. Try `#{install}` (#{error})"
10
10
  end
11
11
 
12
12
  def self.loaded_message(path, gems, time)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Devpack
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Farrell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-05 00:00:00.000000000 Z
11
+ date: 2020-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug