constree 0.1.7 → 0.1.9

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: bdccf3b020fb9b2b3a5c599bab8e5acedf62f08b8ed77b7f6afcdb9dbee7e074
4
- data.tar.gz: 85c983124f2990e636e60ddddbe05fc19519a11bf3d9a69d63a3b416b35be6b9
3
+ metadata.gz: 1bcfc7a688043ae320be5ab2ded3d28f2631c7c2eb8e72175d5813f410c9ce11
4
+ data.tar.gz: 36fdeedbd8924a5407d5ce519937db857a19233c48fa4bceadb8393f3d9ff8ff
5
5
  SHA512:
6
- metadata.gz: f4162527720c2ba191a1b8cd7668100c43767e10935d3ec7eba79a77f4b90991d60d0e59390546fd0aa4745cb58cd623d6cd3b05c8ffc1bc7b8b7a22da424b5c
7
- data.tar.gz: 1159cfc11945b68a73533552e6f019873da48a42930f1d37b6a42147e031542a366f6c51e2d7bdd5f869661263f6ffa7c1546ee2292f00d59236bf0317d0ae26
6
+ metadata.gz: 3e0a14a48ee6e30df121beef8f0a6c66319f1b0b1a2ce49285e3489fb1b2d57b2daef463b1f79c6e2a2f8f76795f784b473bd1f48b5c10edc3aed129d4a56358
7
+ data.tar.gz: 1b14c36e7d3ecb7a8169bd1838fe04225a607ad8ee5a1bab37a0fe094798439495441bc76ad826cd616127d78054ea93a76ba24d9a8d827715a9792e62282efc
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /tmp/
10
10
  *.swp
11
11
  *.gem
12
+ .ruby-version
data/README.md CHANGED
@@ -18,12 +18,47 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install constree
20
20
 
21
- ## Example: constants in Minitest::Spec
21
+ ## Example: find distinct module/class under a module
22
+
23
+ ```ruby
24
+ [1] pry(main)> require "concurrent-ruby"
25
+ => true
26
+ [2] pry(main)> require "constree"
27
+ => true
28
+ [3] pry(main)> Constree.uniq(Concurrent)
29
+ => #<Set:
30
+ {Concurrent,
31
+ Concurrent::AtomicDirectUpdate,
32
+ Concurrent::AtomicNumericCompareAndSetWrapper,
33
+ Concurrent::CyclicBarrier,
34
+ Concurrent::Synchronization::Volatile::ClassMethods,
35
+ Concurrent::Promises,
36
+ Concurrent::Promises::FactoryMethods,
37
+ Concurrent::Promises::FactoryMethods::Configuration,
38
+ Concurrent::Promises::Resolvable,
39
+ Concurrent::Promises::InternalStates::State,
40
+ Concurrent::Promises::InternalStates::Pending,
41
+ Concurrent::Promises::InternalStates::Reserved,
42
+ Concurrent::Promises::InternalStates::ResolvedWithResult,
43
+ Concurrent::Promises::InternalStates::Fulfilled,
44
+ Concurrent::Promises::InternalStates::FulfilledArray,
45
+ ...
46
+ ```
47
+
48
+ ## Example: output tree to html
49
+
50
+ ```ruby
51
+ File.open('somewhere', 'w') do |f|
52
+ f.puts Constree.html_of SomeConstant
53
+ end
54
+ ```
55
+
56
+ ## Example: check constants in concurrent-ruby, in irb console
22
57
 
23
58
  ```ruby
24
59
  irb(main):001:0> require "concurrent-ruby"
25
60
  => true
26
- irb(main):002:0> Constree.p Minitest::Spec
61
+ irb(main):002:0> Constree.p Concurrent
27
62
  Concurrent {:kla=>Module}
28
63
  ├─AbstractExchanger {:kla=>Class, :aft=>[Concurrent::Synchronization::Object, Concurrent::Synchronization::MriObject, Concurrent::Synchronization::MriAttrVolatile, Concurrent::Synchronization::AbstractObject, Object, Kernel, BasicObject]}
29
64
  │ └─ClassMethods {:kla=>Module}
data/constree.gemspec CHANGED
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "minitest", "~> 5.0"
26
26
 
27
27
  spec.add_dependency "tree_graph", "~> 0.2.0"
28
+ spec.add_dependency "tree_html", "~> 0.1.10"
28
29
  end
data/lib/constree/node.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'tree_graph'
2
+ require 'tree_html'
2
3
 
3
4
  module Constree
4
5
  Node = Struct.new :constant, :name, :parent do
@@ -13,6 +14,18 @@ module Constree
13
14
  @sub_consts ||= []
14
15
  end
15
16
 
17
+ include TreeHtml
18
+
19
+ def label_for_tree_html
20
+ "<span class='hl'>#{display_name}</span> #{verbose}"
21
+ end
22
+
23
+ alias_method :children_for_tree_html, :children_for_tree_graph
24
+
25
+ def css_for_tree_html
26
+ '.hl{color: coral;}'
27
+ end
28
+
16
29
  attr_accessor :ref
17
30
 
18
31
  def sub_nodes
@@ -36,6 +49,7 @@ module Constree
36
49
  end
37
50
 
38
51
  def == other
52
+ return false unless constant.is_a? Module
39
53
  return false unless other.is_a? Node
40
54
  constant == other.constant
41
55
  end
@@ -1,3 +1,3 @@
1
1
  module Constree
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.9"
3
3
  end
data/lib/constree.rb CHANGED
@@ -1,9 +1,17 @@
1
1
  require 'constree/version'
2
2
  require 'constree/node'
3
+ require 'set'
3
4
 
4
5
  module Constree
5
-
6
6
  class << self
7
+ def uniq(mod, set = Set.new)
8
+ set << mod
9
+ mod.constants.each do |name|
10
+ sub_mod = mod.const_get(name)
11
+ uniq(sub_mod, set) if ::Module === sub_mod && !set.include?(sub_mod)
12
+ end
13
+ set
14
+ end
7
15
 
8
16
  def list node, seen=[]
9
17
  node = Node.new node unless node.is_a? Node
@@ -22,10 +30,12 @@ module Constree
22
30
  list(mod).first.tree_graph
23
31
  end
24
32
 
33
+ def html_of mod
34
+ list(mod).first.tree_html_full
35
+ end
36
+
25
37
  def p mod
26
38
  puts of mod
27
39
  end
28
-
29
40
  end
30
-
31
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: constree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - ken
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-10 00:00:00.000000000 Z
11
+ date: 2024-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,7 +66,21 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.2.0
69
- description:
69
+ - !ruby/object:Gem::Dependency
70
+ name: tree_html
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.10
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.1.10
83
+ description:
70
84
  email:
71
85
  - block24block@gmail.com
72
86
  executables: []
@@ -91,7 +105,7 @@ homepage: https://github.com/turnon/constree
91
105
  licenses:
92
106
  - MIT
93
107
  metadata: {}
94
- post_install_message:
108
+ post_install_message:
95
109
  rdoc_options: []
96
110
  require_paths:
97
111
  - lib
@@ -106,8 +120,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
120
  - !ruby/object:Gem::Version
107
121
  version: '0'
108
122
  requirements: []
109
- rubygems_version: 3.1.6
110
- signing_key:
123
+ rubygems_version: 3.4.1
124
+ signing_key:
111
125
  specification_version: 4
112
126
  summary: recursively show the structure of constants in a module
113
127
  test_files: []