blood 0.1.0 → 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: d68b62c2e2a24cd8195e951957aef1e134fba03d149f955fdb6d50818e284b1a
4
- data.tar.gz: f21fd7f0e71d778ce15f82407539595dc427de0efdd3747f3797d95e82c6f8b4
3
+ metadata.gz: 761ec35533a1ca239737387f6db021aff647615513d94f3a863d544cff6f829d
4
+ data.tar.gz: 77c985d7880aa0ec40a88ad5835b666cffbbae181e31c7c2bee9be1696ad8a33
5
5
  SHA512:
6
- metadata.gz: b532773779d7395194b4a2d0cd518291ccc2f9f29e3c58be7fe6857c7055b00da7dcc3f74e2133f44f9d3b10e70a4af8ab51977b7a29e50497f3fb7650bedc03
7
- data.tar.gz: f4d57e9a01119cda50948603270728e8bca299bea8b67da4a8f6b282efd37ff0169f21ddc6754d82cd4b87814c007150f02e940606a4ec82beeb76433212afba
6
+ metadata.gz: 913f867664ab4c5ea34c16a07ac93128007cff92f3d9d5f0b817e814cf2e7d6488063d6d227187cbdd4d3e891bcafe829f09d033cb842d7b67c44fbf4bdd0e3c
7
+ data.tar.gz: e18c7a9b0152137dbef1cbb6efd06fba6bd2f33482866082db6ab228ec3f28c2322d882490ab27017acfcf7c95b8d7daa55da6daf7683d496f924b67594778da
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- blood (0.1.0)
4
+ blood (0.1.1)
5
5
  tree_html (~> 0.1.10)
6
6
 
7
7
  GEM
data/lib/blood/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Blood
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/blood.rb CHANGED
@@ -9,7 +9,13 @@ module Blood
9
9
  def self.source(mods)
10
10
  hier = Hash.new{ |h, k| h[k] = Set.new }
11
11
  mods.each do |mod|
12
- ances = mod.ancestors
12
+ # maybe [Class, [Module, Module], ...]
13
+ ances = mod.ancestors.reduce([]) do |arr, a|
14
+ next arr << a if Class === a
15
+ arr << Modules.new unless Modules === arr[-1]
16
+ arr[-1].add(a)
17
+ arr
18
+ end
13
19
  ances.each_with_index do |child, i|
14
20
  parent = ances[i + 1]
15
21
  hier[parent] << child
@@ -18,6 +24,26 @@ module Blood
18
24
  Node.new(BasicObject, hier)
19
25
  end
20
26
 
27
+ class Modules
28
+ def add(mod)
29
+ (@mods ||= []) << mod
30
+ end
31
+
32
+ def to_s
33
+ @to_s ||= (@mods.count == 1 ? @mods[0].to_s : @mods.to_s)
34
+ end
35
+
36
+ alias_method :name, :to_s
37
+
38
+ def hash
39
+ to_s.hash
40
+ end
41
+
42
+ def eql?(other)
43
+ to_s.eql?(other.to_s)
44
+ end
45
+ end
46
+
21
47
  class Node
22
48
  include TreeHtml
23
49
 
@@ -27,16 +53,31 @@ module Blood
27
53
  end
28
54
 
29
55
  def label_for_tree_html
30
- name = ::CGI.escapeHTML(@mod.to_s)
56
+ name = ::CGI.escapeHTML(@mod.name || @mod.to_s)
31
57
  Class === @mod ? "<span class='hl'>#{name}</span>" : name
32
58
  end
33
59
 
60
+ NORMAL_NAME = /^[A-Z][A-Za-z0-9]*(::[A-Z][A-Za-z0-9]*)*$/
61
+
62
+ if Module.method_defined?(:const_source_location)
63
+ alias_method :raw_label_for_tree_html, :label_for_tree_html
64
+
65
+ def label_for_tree_html
66
+ return raw_label_for_tree_html if Modules === @mod
67
+ return raw_label_for_tree_html unless @mod.name =~ NORMAL_NAME
68
+ loc = Module.const_source_location(@mod.name)
69
+ return raw_label_for_tree_html unless loc
70
+ loc = ::CGI.escapeHTML(loc.join(':'))
71
+ "#{raw_label_for_tree_html} <span class='sd'>#{loc}</span>"
72
+ end
73
+ end
74
+
34
75
  def children_for_tree_html
35
76
  children.map{ |sub| Node.new(sub, @hier) }
36
77
  end
37
78
 
38
79
  def css_for_tree_html
39
- '.hl{color: #cc342d;}'
80
+ '.hl{color: #cc342d;} .sd{color: #9e9e9e;}'
40
81
  end
41
82
 
42
83
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blood
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ken
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-26 00:00:00.000000000 Z
11
+ date: 2024-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tree_html