ruby_var_dump 0.2.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2500e049b226d5690eaf4d5352d6817b19f331713fa2866f0d7b9750e36a9a65
4
- data.tar.gz: f6593f187ebf2dfffb5fae98c3b906f0fdebbf3014a9e32b960e9f4b7eb5ac05
3
+ metadata.gz: 68bd2adc9a3d1388b40b55dcdcfc8093b719c84341aa05babf48235319ee592d
4
+ data.tar.gz: 47726151d3cdfe8be8d0a1ba21bbbd203336918c5dcd5277752edfb39741fb6c
5
5
  SHA512:
6
- metadata.gz: 71512e0e4cafdd53d9a20c764119d7b7e4fee1703ed2ea84fa4aff823848b6aedda1ea91e19326854bccc5336a37d06b5304f99d7c329621aaaf702635384631
7
- data.tar.gz: 525b53da60b91a9182326e501f7d1f494070cea54f6b4e74868bff8a4809b097038a47ebc800f637f141a1c149cf754a68643c2a5fa072b7c9f26714b1597074
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.00037 seconds |
4
- ./spec/ruby_var_dump_spec.rb[1:1:2:1:1] | passed | 0.00031 seconds |
5
- ./spec/ruby_var_dump_spec.rb[1:1:2:1:2] | passed | 0.001 seconds |
6
- ./spec/ruby_var_dump_spec.rb[1:1:2:2:1] | passed | 0.00004 seconds |
7
- ./spec/ruby_var_dump_spec.rb[1:1:2:2:2] | passed | 0.00003 seconds |
8
- ./spec/ruby_var_dump_spec.rb[1:1:2:3:1] | passed | 0.0001 seconds |
9
- ./spec/ruby_var_dump_spec.rb[1:1:2:3:2] | passed | 0.00004 seconds |
10
- ./spec/ruby_var_dump_spec.rb[1:1:3:1] | passed | 0.00003 seconds |
11
- ./spec/ruby_var_dump_spec.rb[1:1:3:2] | passed | 0.00004 seconds |
12
- ./spec/ruby_var_dump_spec.rb[1:1:4:1] | passed | 0.00003 seconds |
13
- ./spec/ruby_var_dump_spec.rb[1:1:4:2] | passed | 0.00003 seconds |
14
- ./spec/ruby_var_dump_spec.rb[1:1:5:1] | passed | 0.00004 seconds |
15
- ./spec/ruby_var_dump_spec.rb[1:1:6:1] | passed | 0.00009 seconds |
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 |
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyVarDump
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
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,8 +84,11 @@ 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.attributes.each do |attr_name, attr_value|
73
- print "#{indent} #{attr_name}: #{colorize_by_type(attr_value)},\n"
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|
@@ -88,8 +106,11 @@ module RubyVarDump
88
106
  # CollectionProxy の内容(アソシエーション)をダンプ
89
107
  print("#{indent} #{RED_COLOR}#{association.name} #{ORANGE_COLOR}(#{association.macro})#{RESET_COLOR}: #{GREEN_COLOR}<< #{item.class}:#{item.object_id} >>#{RESET_COLOR}\n")
90
108
  print("#{indent} {\n")
91
- item.attributes.each do |attr_name, attr_value|
92
- print("#{indent} #{attr_name}: #{colorize_by_type(attr_value)}\n")
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
93
114
  end
94
115
 
95
116
  print("#{indent} }\n") #ここまでアソシエーションの描画
@@ -102,8 +123,11 @@ module RubyVarDump
102
123
  # 単一オブジェクトのアソシエーションをダンプ
103
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")
104
125
  print("#{indent} {\n")
105
- associated_value.attributes.each do |attr_name, attr_value|
106
- print("#{indent} #{attr_name}: #{colorize_by_type(attr_value)}\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
107
131
  end
108
132
 
109
133
  print("#{indent} }\n") #ここまでアソシエーションの描画
@@ -124,6 +148,20 @@ module RubyVarDump
124
148
  print indent + colorize_by_type(obj) # プリミティブな値の場合を出力
125
149
  print "\n" if level == 0 # メソッドの出力の最後に改行を追加
126
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
127
165
  end
128
166
 
129
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.2.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-05-06 00:00:00.000000000 Z
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.