ruby_var_dump 0.1.3 → 0.1.5
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 +4 -4
- data/lib/ruby_var_dump/version.rb +1 -1
- data/lib/ruby_var_dump.rb +52 -13
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32a37618c09c721d7677fa7324b178ab96bcee787792be3f183ace3ceb2902da
|
4
|
+
data.tar.gz: 68d8fb523c3d91e95e2e3b3d7983a3e2262940396b17942acc72c65816b1cf61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83e17077afb7639b4dbc1b11ecda8dcb6c7a94ee411084045b73efec8c73f70c4a4315f1bbcfc7e7ef2835d08a727fb0631ef362cb855ebf6358d56f53db0f62
|
7
|
+
data.tar.gz: efd57f9f7ebceb180080b2288ba7e16ea08412ccc58620da63a4b22ee4064a5008e7656fdc9873effb41a8a12bcf5e5dd70473fba1612ca5167e14df573fcdca
|
data/.rspec_status
CHANGED
@@ -1,11 +1,11 @@
|
|
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] | passed | 0.
|
5
|
-
./spec/ruby_var_dump_spec.rb[1:1:2:2] | passed | 0.
|
3
|
+
./spec/ruby_var_dump_spec.rb[1:1:1] | passed | 0.00034 seconds |
|
4
|
+
./spec/ruby_var_dump_spec.rb[1:1:2:1] | passed | 0.00027 seconds |
|
5
|
+
./spec/ruby_var_dump_spec.rb[1:1:2:2] | passed | 0.00008 seconds |
|
6
6
|
./spec/ruby_var_dump_spec.rb[1:1:3:1] | passed | 0.00003 seconds |
|
7
7
|
./spec/ruby_var_dump_spec.rb[1:1:3:2] | passed | 0.00004 seconds |
|
8
8
|
./spec/ruby_var_dump_spec.rb[1:1:4:1] | passed | 0.00003 seconds |
|
9
9
|
./spec/ruby_var_dump_spec.rb[1:1:4:2] | passed | 0.00003 seconds |
|
10
10
|
./spec/ruby_var_dump_spec.rb[1:1:5:1] | passed | 0.00004 seconds |
|
11
|
-
./spec/ruby_var_dump_spec.rb[1:1:6:1] | passed | 0.
|
11
|
+
./spec/ruby_var_dump_spec.rb[1:1:6:1] | passed | 0.00009 seconds |
|
data/lib/ruby_var_dump.rb
CHANGED
@@ -4,10 +4,19 @@ require_relative "ruby_var_dump/version"
|
|
4
4
|
|
5
5
|
module RubyVarDump
|
6
6
|
class Error < StandardError; end
|
7
|
-
# Your code goes here...
|
8
7
|
|
9
|
-
def
|
8
|
+
def vdump(obj, level = 0, is_value = false, dumped_objects = [], is_first=true)
|
10
9
|
indent = ' ' * level * 2
|
10
|
+
|
11
|
+
if (defined?(ActiveRecord::Base) && obj.is_a?(ActiveRecord::Base)) || (defined?(ActiveRecord::Relation) && obj.is_a?(ActiveRecord::Relation))
|
12
|
+
if dumped_objects.any? { |dumped_obj| dumped_obj.object_id == obj.object_id && dumped_obj.class == obj.class }
|
13
|
+
puts "#{indent}<Recursive reference: #{obj.class}:#{obj.object_id}>"
|
14
|
+
return
|
15
|
+
else
|
16
|
+
dumped_objects << obj
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
11
20
|
if obj.is_a?(Array)
|
12
21
|
print "#{is_value ? '' : indent}" + "["
|
13
22
|
if obj.empty?
|
@@ -16,7 +25,7 @@ module RubyVarDump
|
|
16
25
|
else
|
17
26
|
print "\n"
|
18
27
|
obj.each_with_index do |item, index|
|
19
|
-
|
28
|
+
vdump(item, level + 1, false, dumped_objects, false)
|
20
29
|
print "," unless index == obj.size - 1
|
21
30
|
print "\n"
|
22
31
|
end
|
@@ -34,7 +43,7 @@ module RubyVarDump
|
|
34
43
|
# キーにインデントを適用し、値にはインデントを適用しない
|
35
44
|
print "#{indent} #{key.inspect.chomp} => "
|
36
45
|
if value.is_a?(Hash) || value.is_a?(Array)
|
37
|
-
|
46
|
+
vdump(value, level + 1, true, dumped_objects, false) # ハッシュのバリューの場合には is_value を true に設定
|
38
47
|
else
|
39
48
|
print value.inspect # プリミティブな値の場合は現在のレベルで出力
|
40
49
|
end
|
@@ -44,21 +53,51 @@ module RubyVarDump
|
|
44
53
|
print "#{indent}}"
|
45
54
|
print "\n" if level == 0 # メソッドの出力の最後に改行を追加
|
46
55
|
end
|
47
|
-
elsif defined?(ActiveRecord::
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
56
|
+
elsif defined?(ActiveRecord::Base) && obj.is_a?(ActiveRecord::Base)
|
57
|
+
# ActiveRecordオブジェクトの場合
|
58
|
+
print "\n" unless is_first # 最初のレコード以外の場合に改行を入れる
|
59
|
+
print "#{indent}#{obj.class}:#{obj.object_id}\n"
|
60
|
+
print "#{indent}{\n"
|
61
|
+
obj.attributes.each do |attr_name, attr_value|
|
62
|
+
print "#{indent} #{attr_name}: #{attr_value.inspect},\n"
|
63
|
+
end
|
64
|
+
# リレーションも再帰的にダンプ
|
65
|
+
obj.class.reflect_on_all_associations.each do |association|
|
66
|
+
next if association.macro.nil? # アソシエーションが存在しない場合はスキップ
|
67
|
+
|
68
|
+
associated_value = obj.send(association.name)
|
69
|
+
if associated_value.respond_to?(:each) # アソシエーションがコレクションの場合
|
70
|
+
next if associated_value.empty?
|
71
|
+
|
72
|
+
associated_value.each do |item|
|
73
|
+
next if dumped_objects.any? { |dumped_obj| dumped_obj.object_id == item.object_id && dumped_obj.class == item.class }
|
74
|
+
|
75
|
+
# CollectionProxy の内容(アソシエーション)をダンプ
|
76
|
+
print("#{indent} #{association.name} (association): << #{item.class}:#{item.object_id} >>\n")
|
77
|
+
print("#{indent} {\n")
|
78
|
+
item.attributes.each do |attr_name, attr_value|
|
79
|
+
print("#{indent} #{attr_name}: #{attr_value.inspect}\n")
|
80
|
+
end
|
81
|
+
|
82
|
+
print("#{indent} }\n") #ここまでアソシエーションの描画
|
83
|
+
end
|
55
84
|
end
|
56
85
|
end
|
86
|
+
print "#{indent}}\n"
|
87
|
+
elsif defined?(ActiveRecord::Relation) && obj.is_a?(ActiveRecord::Relation)
|
88
|
+
print "#{indent}#{obj.class}:#{obj.object_id}\n"
|
89
|
+
print "#{indent}[\n"
|
90
|
+
obj.each_with_index do |item, index|
|
91
|
+
vdump(item, level + 1, false, dumped_objects, index == 0)
|
92
|
+
end
|
93
|
+
print "#{indent}]"
|
94
|
+
print "\n" if level == 0 # メソッドの出力の最後に改行を追加
|
57
95
|
elsif obj.respond_to?(:attributes)
|
58
|
-
|
96
|
+
vdump(obj.attributes, level, false, dumped_objects, false)
|
59
97
|
else
|
60
98
|
print indent + obj.inspect.chomp
|
61
99
|
print "\n" if level == 0 # メソッドの出力の最後に改行を追加
|
62
100
|
end
|
63
101
|
end
|
64
102
|
end
|
103
|
+
# gem build ruby_var_dump.gemspec
|
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.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hirokiyam
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-02-27 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.
|
@@ -28,12 +28,12 @@ files:
|
|
28
28
|
- lib/ruby_var_dump.rb
|
29
29
|
- lib/ruby_var_dump/version.rb
|
30
30
|
- sig/ruby_var_dump.rbs
|
31
|
-
homepage: https://github.com/hirokiyam
|
31
|
+
homepage: https://github.com/hirokiyam/ruby_var_dump
|
32
32
|
licenses:
|
33
33
|
- MIT
|
34
34
|
metadata:
|
35
35
|
allowed_push_host: https://rubygems.org
|
36
|
-
homepage_uri: https://github.com/hirokiyam
|
36
|
+
homepage_uri: https://github.com/hirokiyam/ruby_var_dump
|
37
37
|
source_code_uri: https://github.com/hirokiyam/ruby_var_dump
|
38
38
|
changelog_uri: https://github.com/hirokiyam/ruby_var_dump/blob/main/CHANGELOG.md
|
39
39
|
post_install_message:
|