gemlist 0.2.0 → 0.3.0

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
  SHA1:
3
- metadata.gz: 9184e8804d7122179c389dcb2f5f683290f52534
4
- data.tar.gz: 75b596b0c9199be59c9e09458c959a2ff6a5fe94
3
+ metadata.gz: 264c212ec8ff089324641d17b96c67040d2622ec
4
+ data.tar.gz: 3f83087f303792f5e5a8f7710b1df7d1e6e8fa4b
5
5
  SHA512:
6
- metadata.gz: 10b8f8a542d37f276a70f84b17b7456d09ac5636c870978b103344d78fc7ae7afc79da0370c688824648ce7adbd23608f5dc85d957ec7a778b7961c49fa8cc64
7
- data.tar.gz: 0a2cca22e7a371f3e991b9b4f6e9f910569dba833454379ca319f003dc0b20faf3c36c821077ac8b9a4ab9ee55344058a396f59e1c078106ce22e7abef7f50ec
6
+ metadata.gz: 7ddff71153ab79b99ade0c7eb50cddfa95445b262f2eb42725e69c2ca99a5f8bd7e04e2d3330c669e234e5a879a1aca2471a0383daf055167b89e84426fee9d8
7
+ data.tar.gz: 0dc9761a23143309184bac6047064518ae68133a3633d6793cd55363de2e43d7d5382d5d77636d1efc733761350404e8330212c848d438dd7471c964e3f405c7
data/gemlist.gemspec CHANGED
@@ -23,6 +23,4 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "rspec", "~> 3.0"
25
25
  spec.add_development_dependency "pry-byebug"
26
-
27
- spec.add_runtime_dependency "rubytree", "~> 0.9.7"
28
26
  end
data/lib/gemlist.rb CHANGED
@@ -26,7 +26,7 @@ class Gemlist
26
26
 
27
27
  spec_tree
28
28
  .depth_first_children_first
29
- .reject(&:is_root?)
29
+ .reject(&:root?)
30
30
  .select { |node| node.descends_from?(*top_level_dependencies) }
31
31
  .map(&:content)
32
32
  end
@@ -1,11 +1,49 @@
1
- require 'tree'
2
-
3
1
  class Gemlist
4
- class SpecNode < Tree::TreeNode
2
+ class SpecNode
3
+ include Enumerable
4
+
5
+ attr_reader :name, :content, :children
6
+ attr_accessor :parent
7
+
8
+ def initialize(name, content)
9
+ @name = name
10
+ @content = content
11
+ @children = []
12
+ @parent = nil
13
+ end
14
+
15
+ def <<(node)
16
+ @children << node
17
+ node.parent = self
18
+ node
19
+ end
20
+
21
+ def each(&block)
22
+ return to_enum unless block_given?
23
+
24
+ unvisited = [self]
25
+
26
+ until unvisited.empty?
27
+ current = unvisited.shift
28
+
29
+ if current
30
+ yield current
31
+
32
+ unvisited.unshift(*current.children)
33
+ end
34
+ end
35
+
36
+ return self if block_given?
37
+ end
38
+
5
39
  def total_dependency_count
6
40
  size - 1
7
41
  end
8
42
 
43
+ def size
44
+ to_a.size
45
+ end
46
+
9
47
  def depth_first_children_first
10
48
  sorted_children = children.sort_by(&:total_dependency_count)
11
49
  parent = self
@@ -22,12 +60,22 @@ class Gemlist
22
60
  end
23
61
 
24
62
  def lineage
25
- [self, *parentage].reverse.reject(&:is_root?)
63
+ [self, *parentage].reverse.reject(&:root?)
26
64
  end
27
65
 
28
66
  def descends_from?(*dependencies)
29
- !is_root? &&
67
+ !root? &&
30
68
  dependencies.map(&:name).include?(lineage.first.name)
31
69
  end
70
+
71
+ def parentage
72
+ return [] if root?
73
+
74
+ [parent] + parent.parentage
75
+ end
76
+
77
+ def root?
78
+ parent.nil?
79
+ end
32
80
  end
33
81
  end
@@ -1,3 +1,3 @@
1
1
  class Gemlist
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemlist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Hoffman
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rubytree
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: 0.9.7
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: 0.9.7
83
69
  description: Get a list of gems Bundler would install under various conditions. Built
84
70
  to be used in build tools.
85
71
  email: