ruby_var_dump 0.1.6 → 0.3.0
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.
- checksums.yaml +4 -4
- data/.rspec_status +16 -13
- data/lib/ruby_var_dump/version.rb +1 -1
- data/lib/ruby_var_dump.rb +60 -7
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68bd2adc9a3d1388b40b55dcdcfc8093b719c84341aa05babf48235319ee592d
|
4
|
+
data.tar.gz: 47726151d3cdfe8be8d0a1ba21bbbd203336918c5dcd5277752edfb39741fb6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43e87259f0741c9517d7918c66e6166c92aca62cb3dab44e91b0cf381ad72f556ace05c53a4859a939d014dc7d363e5bf4fdb47be349afca93671acfd6ef4a67
|
7
|
+
data.tar.gz: d698c17ea7903336b094fbba26ae3355c67517c836a6466280d8ed07caa60f68bdcee356c3d06a836d01b51304aa08c6bb50d64184951b9b722a692397626275
|
data/.rspec_status
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
example_id | status | run_time |
|
2
2
|
--------------------------------------- | ------ | --------------- |
|
3
|
-
./spec/ruby_var_dump_spec.rb[1:1:1] | passed | 0.
|
4
|
-
./spec/ruby_var_dump_spec.rb[1:1:2:1
|
5
|
-
./spec/ruby_var_dump_spec.rb[1:1:2:
|
6
|
-
./spec/ruby_var_dump_spec.rb[1:1:2:
|
7
|
-
./spec/ruby_var_dump_spec.rb[1:1:
|
8
|
-
./spec/ruby_var_dump_spec.rb[1:1:
|
9
|
-
./spec/ruby_var_dump_spec.rb[1:1:
|
10
|
-
./spec/ruby_var_dump_spec.rb[1:1:3:
|
11
|
-
./spec/ruby_var_dump_spec.rb[1:1:3:
|
12
|
-
./spec/ruby_var_dump_spec.rb[1:1:
|
13
|
-
./spec/ruby_var_dump_spec.rb[1:1:4:
|
14
|
-
./spec/ruby_var_dump_spec.rb[1:1:
|
15
|
-
./spec/ruby_var_dump_spec.rb[1:1:
|
3
|
+
./spec/ruby_var_dump_spec.rb[1:1:1] | passed | 0.00134 seconds |
|
4
|
+
./spec/ruby_var_dump_spec.rb[1:1:2:1] | passed | 0.00169 seconds |
|
5
|
+
./spec/ruby_var_dump_spec.rb[1:1:2:2] | passed | 0.00006 seconds |
|
6
|
+
./spec/ruby_var_dump_spec.rb[1:1:2:3] | passed | 0.0004 seconds |
|
7
|
+
./spec/ruby_var_dump_spec.rb[1:1:3:1:1] | passed | 0.00004 seconds |
|
8
|
+
./spec/ruby_var_dump_spec.rb[1:1:3:1:2] | passed | 0.00003 seconds |
|
9
|
+
./spec/ruby_var_dump_spec.rb[1:1:3:2:1] | passed | 0.00005 seconds |
|
10
|
+
./spec/ruby_var_dump_spec.rb[1:1:3:2:2] | passed | 0.00004 seconds |
|
11
|
+
./spec/ruby_var_dump_spec.rb[1:1:3:3:1] | passed | 0.00012 seconds |
|
12
|
+
./spec/ruby_var_dump_spec.rb[1:1:3:3:2] | passed | 0.00004 seconds |
|
13
|
+
./spec/ruby_var_dump_spec.rb[1:1:4:1] | passed | 0.00014 seconds |
|
14
|
+
./spec/ruby_var_dump_spec.rb[1:1:4:2] | passed | 0.00005 seconds |
|
15
|
+
./spec/ruby_var_dump_spec.rb[1:1:5:1] | passed | 0.00016 seconds |
|
16
|
+
./spec/ruby_var_dump_spec.rb[1:1:5:2] | passed | 0.00004 seconds |
|
17
|
+
./spec/ruby_var_dump_spec.rb[1:1:6:1] | passed | 0.00006 seconds |
|
18
|
+
./spec/ruby_var_dump_spec.rb[1:1:7:1] | passed | 0.0001 seconds |
|
data/lib/ruby_var_dump.rb
CHANGED
@@ -13,9 +13,24 @@ module RubyVarDump
|
|
13
13
|
LIGHT_GREEN_COLOR = "\e[38;5;10m" # 薄緑色
|
14
14
|
# LIGHT_BLUE = "\e[38;5;45m" # 水色
|
15
15
|
ORANGE_COLOR = "\e[38;5;214m" # オレンジ色
|
16
|
+
YELLOW_COLOR = "\e[33m" # 黄色(デバッグ出力開始用)
|
17
|
+
BRIGHT_GREEN_COLOR = "\e[32m" # 明るい緑色(デバッグ出力終了用)
|
16
18
|
RESET_COLOR = "\e[0m" # 色リセット
|
17
19
|
|
18
20
|
def vdump(obj, level = 0, is_value = false, dumped_objects = [], is_first=true)
|
21
|
+
# デバッグ出力の開始(最初の呼び出し時のみ)
|
22
|
+
if level == 0 && is_first
|
23
|
+
title = "Start Output (ruby_var_dump)"
|
24
|
+
timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S") # 現在時刻をフォーマット
|
25
|
+
full_title = " #{title} | #{timestamp} " # タイトルと時刻を結合
|
26
|
+
width = 80
|
27
|
+
padding = (width - full_title.length) # 全体の幅からタイトルと時刻の長さを引く
|
28
|
+
left = padding / 2
|
29
|
+
right = padding - left
|
30
|
+
puts "#{YELLOW_COLOR}#{'=' * width}#{RESET_COLOR}"
|
31
|
+
puts "#{YELLOW_COLOR}#{'=' * left}#{full_title}#{'=' * right}#{RESET_COLOR}"
|
32
|
+
end
|
33
|
+
|
19
34
|
indent = ' ' * level * 2
|
20
35
|
|
21
36
|
if (defined?(ActiveRecord::Base) && obj.is_a?(ActiveRecord::Base)) || (defined?(ActiveRecord::Relation) && obj.is_a?(ActiveRecord::Relation))
|
@@ -69,29 +84,53 @@ module RubyVarDump
|
|
69
84
|
print "\n" unless is_first # 最初のレコード以外の場合に改行を入れる
|
70
85
|
print "#{indent}#{GREEN_COLOR}#{obj.class}:#{obj.object_id}#{RESET_COLOR}\n"
|
71
86
|
print "#{indent}{\n"
|
72
|
-
obj
|
73
|
-
|
87
|
+
# もし obj が attributes メソッドを持っている場合、その属性をダンプ
|
88
|
+
if obj.respond_to?(:attributes)
|
89
|
+
obj.attributes.each do |attr_name, attr_value|
|
90
|
+
print "#{indent} #{attr_name}: #{colorize_by_type(attr_value)},\n"
|
91
|
+
end
|
74
92
|
end
|
75
93
|
# リレーションも再帰的にダンプ
|
76
94
|
obj.class.reflect_on_all_associations.each do |association|
|
77
95
|
next if association.macro.nil? # アソシエーションが存在しない場合はスキップ
|
78
96
|
|
79
97
|
associated_value = obj.send(association.name)
|
80
|
-
|
81
|
-
|
98
|
+
|
99
|
+
# has_many や has_and_belongs_to_many など、コレクションを返すアソシエーション
|
100
|
+
if association.macro == :has_many || association.macro == :has_and_belongs_to_many
|
101
|
+
next if associated_value.nil? || (associated_value.respond_to?(:empty?) && associated_value.empty?)
|
82
102
|
|
83
103
|
associated_value.each do |item|
|
84
104
|
next if dumped_objects.any? { |dumped_obj| dumped_obj.object_id == item.object_id && dumped_obj.class == item.class }
|
85
105
|
|
86
106
|
# CollectionProxy の内容(アソシエーション)をダンプ
|
87
|
-
print("#{indent} #{RED_COLOR}#{association.name} #{ORANGE_COLOR}(association)#{RESET_COLOR}: #{GREEN_COLOR}<< #{item.class}:#{item.object_id} >>#{RESET_COLOR}\n")
|
107
|
+
print("#{indent} #{RED_COLOR}#{association.name} #{ORANGE_COLOR}(#{association.macro})#{RESET_COLOR}: #{GREEN_COLOR}<< #{item.class}:#{item.object_id} >>#{RESET_COLOR}\n")
|
88
108
|
print("#{indent} {\n")
|
89
|
-
item
|
90
|
-
|
109
|
+
# もし item が attributes メソッドを持っていれば、その属性もダンプ
|
110
|
+
if item.respond_to?(:attributes)
|
111
|
+
item.attributes.each do |attr_name, attr_value|
|
112
|
+
print("#{indent} #{attr_name}: #{colorize_by_type(attr_value)}\n")
|
113
|
+
end
|
91
114
|
end
|
92
115
|
|
93
116
|
print("#{indent} }\n") #ここまでアソシエーションの描画
|
94
117
|
end
|
118
|
+
# belongs_to や has_one など、単一オブジェクトを返すアソシエーション
|
119
|
+
elsif association.macro == :belongs_to || association.macro == :has_one
|
120
|
+
next if associated_value.nil?
|
121
|
+
next if dumped_objects.any? { |dumped_obj| dumped_obj.object_id == associated_value.object_id && dumped_obj.class == associated_value.class }
|
122
|
+
|
123
|
+
# 単一オブジェクトのアソシエーションをダンプ
|
124
|
+
print("#{indent} #{RED_COLOR}#{association.name} #{ORANGE_COLOR}(#{association.macro})#{RESET_COLOR}: #{GREEN_COLOR}<< #{associated_value.class}:#{associated_value.object_id} >>#{RESET_COLOR}\n")
|
125
|
+
print("#{indent} {\n")
|
126
|
+
# もし associated_value が attributes メソッドを持っていれば、その属性もダンプ
|
127
|
+
if associated_value.respond_to?(:attributes)
|
128
|
+
associated_value.attributes.each do |attr_name, attr_value|
|
129
|
+
print("#{indent} #{attr_name}: #{colorize_by_type(attr_value)}\n")
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
print("#{indent} }\n") #ここまでアソシエーションの描画
|
95
134
|
end
|
96
135
|
end
|
97
136
|
print "#{indent}}\n"
|
@@ -109,6 +148,20 @@ module RubyVarDump
|
|
109
148
|
print indent + colorize_by_type(obj) # プリミティブな値の場合を出力
|
110
149
|
print "\n" if level == 0 # メソッドの出力の最後に改行を追加
|
111
150
|
end
|
151
|
+
|
152
|
+
# デバッグ出力の終了
|
153
|
+
if level == 0 && is_first
|
154
|
+
# デバッグ出力の終了
|
155
|
+
title = "End Output (ruby_var_dump)"
|
156
|
+
timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S") # 現在時刻をフォーマット
|
157
|
+
full_title = " #{title} | #{timestamp} " # タイトルと時刻を結合
|
158
|
+
width = 80
|
159
|
+
padding = (width - full_title.length) # 全体の幅からタイトルと時刻の長さを引く
|
160
|
+
left = padding / 2
|
161
|
+
right = padding - left
|
162
|
+
puts "#{BRIGHT_GREEN_COLOR}#{'=' * left}#{full_title}#{'=' * right}#{RESET_COLOR}"
|
163
|
+
puts "#{BRIGHT_GREEN_COLOR}#{'=' * width}#{RESET_COLOR}"
|
164
|
+
end
|
112
165
|
end
|
113
166
|
|
114
167
|
# エイリアスを設定。vdump メソッドの別名として vpp を定義
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_var_dump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hirokiyam
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A Ruby gem for detailed debugging and inspection of objects, mimicking
|
14
14
|
PHP's var_dump function.
|
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '0'
|
53
53
|
requirements: []
|
54
|
-
rubygems_version: 3.5.
|
54
|
+
rubygems_version: 3.5.10
|
55
55
|
signing_key:
|
56
56
|
specification_version: 4
|
57
57
|
summary: A Ruby gem for detailed debugging and inspection of objects.
|