constree 0.1.0 → 0.1.4

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
- SHA1:
3
- metadata.gz: fd2b780d56b1776a610fc399ffbbc161843146f3
4
- data.tar.gz: dae4b75255c0105ab09a46b39286a862f5766dcb
2
+ SHA256:
3
+ metadata.gz: 693722766c01345820780cf89237dd09ccd37694804c93110d5319ddcbb6342d
4
+ data.tar.gz: 6ebbea44b57efecbe35ffacf3edf08251c6f9599cd0621996400b077aba759a5
5
5
  SHA512:
6
- metadata.gz: bc5445f233c122acbb4db2ca7123adcd3d9825245a7010f4f4f065f39766b28cc45b5f340c03c5eac936572a61d2252cfb825fa36296821ba8cec56b6a882b07
7
- data.tar.gz: db1d5c3861311b7a473b2ce528d67bb8293d9af9eb554b943e7ce6a37b0277d39109c78e706aa5764b1e223790eb4ddde009f76577875f9bc76e24193dd7d119
6
+ metadata.gz: bbc9b456a79675d4a73de1e275dc3c835a6d3407947048065f6bc8e83ed6dacdb67b8c1f85813df76364c1d6de3542c577f5d28a9848f864754db1d98de206e5
7
+ data.tar.gz: 5d3e360dde618693120f04518fb259f7e53fadac5e437427f993dd616262d1b14d63124da665ad01e37066160e7adcf0154248f275e12b72cd2b2c455b3cc3a0
data/README.md CHANGED
@@ -27,16 +27,16 @@ Or install it yourself as:
27
27
  => true
28
28
  2.2.2 :003 > Minitest::Spec.constreep
29
29
  Minitest::Spec (Class)
30
- DSL (Module)
31
- TYPES (Array)
32
- InstanceMethods (Module)
33
- TYPES Minitest::Spec::DSL::TYPES
34
- PASSTHROUGH_EXCEPTIONS (Array)
35
- TEARDOWN_METHODS (Array)
36
- LifecycleHooks (Module)
37
- UNDEFINED (Object)
38
- E (String)
39
- SIGNALS (Hash)
30
+ ├─DSL (Module)
31
+ ├─TYPES (Array)
32
+ └─InstanceMethods (Module)
33
+ ├─TYPESMinitest::Spec::DSL::TYPES
34
+ ├─PASSTHROUGH_EXCEPTIONS (Array)
35
+ ├─TEARDOWN_METHODS (Array)
36
+ ├─LifecycleHooks (Module)
37
+ ├─UNDEFINED (Object)
38
+ ├─E (String)
39
+ └─SIGNALS (Hash)
40
40
  => nil
41
41
  ```
42
42
 
data/constree.gemspec CHANGED
@@ -20,7 +20,9 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.13"
23
+ spec.add_development_dependency "bundler", "> 1.13"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency "minitest", "~> 5.0"
26
+
27
+ spec.add_development_dependency "tree_graph", "~> 0.2.0"
26
28
  end
data/lib/constree.rb CHANGED
@@ -11,6 +11,7 @@ module Constree
11
11
 
12
12
  node.sub_nodes.each do |sub_n|
13
13
  seen << sub_n
14
+ node.children_for_tree_graph << sub_n
14
15
  list(sub_n, seen) if sub_n.not_yet? seen
15
16
  end
16
17
 
@@ -18,9 +19,7 @@ module Constree
18
19
  end
19
20
 
20
21
  def of mod
21
- list(mod).
22
- map(&:level).
23
- join("\n")
22
+ list(mod).first.tree_graph
24
23
  end
25
24
 
26
25
  def p mod
data/lib/constree/node.rb CHANGED
@@ -1,53 +1,31 @@
1
+ require 'tree_graph'
2
+
1
3
  module Constree
2
- Node = Struct.new :constant, :name, :parent, :is_last do
4
+ Node = Struct.new :constant, :name, :parent do
3
5
 
4
- attr_accessor :ref
6
+ include TreeGraph
5
7
 
6
- def sub_nodes
7
- return [] unless constant.is_a? Module
8
- names = constant.constants
9
- names.reduce([]) do |nodes, name|
10
- nodes << Node.new(constant.const_get(name), name, self, nodes.count == names.count - 1)
11
- end
8
+ def label_for_tree_graph
9
+ display_name + ' ' + type
12
10
  end
13
11
 
14
- def ancestors
15
- return [] unless parent
16
- p, anc = parent, []
17
- while p
18
- anc.unshift p
19
- p = p.parent
20
- end
21
- anc
12
+ def children_for_tree_graph
13
+ @sub_consts ||= []
22
14
  end
23
15
 
24
- def last?
25
- is_last ? true : false
16
+ attr_accessor :ref
17
+
18
+ def sub_nodes
19
+ return [] unless constant.is_a? Module
20
+ constant.constants.map do |name|
21
+ Node.new(constant.const_get(name), name, self)
22
+ end
26
23
  end
27
24
 
28
25
  def top?
29
26
  parent ? false : true
30
27
  end
31
28
 
32
- def branch
33
- return '' unless parent
34
- last? ? '└─' : '├─'
35
- end
36
-
37
- def indent
38
- ancestors.map do |a|
39
- if a.top?
40
- ''
41
- else
42
- a.last? ? ' ' : '│ '
43
- end
44
- end.join
45
- end
46
-
47
- def level
48
- indent + branch + display_name + ' ' + type
49
- end
50
-
51
29
  def display_name
52
30
  (name || constant.name).to_s
53
31
  end
@@ -62,7 +40,9 @@ module Constree
62
40
  end
63
41
 
64
42
  def type
65
- ref ? "→ #{ref.full_name}" : "(#{constant.class.to_s})"
43
+ return "→ #{ref.full_name}" if ref
44
+ return "(#{constant.class.to_s})" unless Class === constant
45
+ "< " + constant.ancestors[1..].map(&:to_s).join(" < ")
66
46
  end
67
47
 
68
48
  def not_yet? seen
@@ -1,3 +1,3 @@
1
1
  module Constree
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: constree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ken
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-21 00:00:00.000000000 Z
11
+ date: 2021-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.13'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.13'
27
27
  - !ruby/object:Gem::Dependency
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: tree_graph
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.2.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.2.0
55
69
  description:
56
70
  email:
57
71
  - block24block@gmail.com
@@ -92,8 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
106
  - !ruby/object:Gem::Version
93
107
  version: '0'
94
108
  requirements: []
95
- rubyforge_project:
96
- rubygems_version: 2.4.8
109
+ rubygems_version: 3.2.3
97
110
  signing_key:
98
111
  specification_version: 4
99
112
  summary: recursively show the structure of constants in a module