blood 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/blood/version.rb +1 -1
  3. data/lib/blood.rb +20 -2
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca4c81c2a0441fc352dc9766727920ecd19b5af2111df1a875fb10460e502db8
4
- data.tar.gz: 9443b8f066c0494b38d2a6ee8885043bee26d8218da487e4ecaf62cec13e09f5
3
+ metadata.gz: 761ec35533a1ca239737387f6db021aff647615513d94f3a863d544cff6f829d
4
+ data.tar.gz: 77c985d7880aa0ec40a88ad5835b666cffbbae181e31c7c2bee9be1696ad8a33
5
5
  SHA512:
6
- metadata.gz: 1556831015757b2e488068b0a7a5c69f2ed449ae5a3be15d9da0fc6611c9db0abe4f773c3701e5168fee58daaef84757ff203b2ee20d8df699f861edffb74da4
7
- data.tar.gz: 759cbe9670bd1f49481a2e8e65f1e3bc6293a0703d540f549daca96f08bed1431a1e7061419b086889bf149007e3911d54565e50959f300a40b9f4a07676ebe4
6
+ metadata.gz: 913f867664ab4c5ea34c16a07ac93128007cff92f3d9d5f0b817e814cf2e7d6488063d6d227187cbdd4d3e891bcafe829f09d033cb842d7b67c44fbf4bdd0e3c
7
+ data.tar.gz: e18c7a9b0152137dbef1cbb6efd06fba6bd2f33482866082db6ab228ec3f28c2322d882490ab27017acfcf7c95b8d7daa55da6daf7683d496f924b67594778da
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.1"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/blood.rb CHANGED
@@ -9,6 +9,7 @@ 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
+ # maybe [Class, [Module, Module], ...]
12
13
  ances = mod.ancestors.reduce([]) do |arr, a|
13
14
  next arr << a if Class === a
14
15
  arr << Modules.new unless Modules === arr[-1]
@@ -32,6 +33,8 @@ module Blood
32
33
  @to_s ||= (@mods.count == 1 ? @mods[0].to_s : @mods.to_s)
33
34
  end
34
35
 
36
+ alias_method :name, :to_s
37
+
35
38
  def hash
36
39
  to_s.hash
37
40
  end
@@ -50,16 +53,31 @@ module Blood
50
53
  end
51
54
 
52
55
  def label_for_tree_html
53
- name = ::CGI.escapeHTML(@mod.to_s)
56
+ name = ::CGI.escapeHTML(@mod.name || @mod.to_s)
54
57
  Class === @mod ? "<span class='hl'>#{name}</span>" : name
55
58
  end
56
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
+
57
75
  def children_for_tree_html
58
76
  children.map{ |sub| Node.new(sub, @hier) }
59
77
  end
60
78
 
61
79
  def css_for_tree_html
62
- '.hl{color: #cc342d;}'
80
+ '.hl{color: #cc342d;} .sd{color: #9e9e9e;}'
63
81
  end
64
82
 
65
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.1
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