ruby_var_dump 0.1.4 → 0.1.6

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: 1ca58788ccbccedeae45367f1209c79bd52f151eee3b53ee552b4d8a86558595
4
- data.tar.gz: 3a255a625d7260888079ae633bc931dd9740df025eae4faf8264381172e0a19f
3
+ metadata.gz: a3773e836278afc17fb0e6d2a509390b31914dd25c62fcbcada5c134842451d5
4
+ data.tar.gz: b3cfa233acdb8458a562a2fb5d8646c2608d342ba7eccbd6e4029097fadf7248
5
5
  SHA512:
6
- metadata.gz: 7b0142c9ec6a6130627f993b06810eaeac717cc0666e9af9f2f9d953f08927b619c6df9e582f2f6e4d2f05bb9cd11eeae9aec9800f8b01533432c87053e9f94d
7
- data.tar.gz: 7ce09cea1d956caa410bc775cc137e2897248f7bbea2eac085c9254f8ba32cd99d3ad7ef2896d35306f4a47e693e9497f58d25a11463f6da9dd5f1bdcdf89f14
6
+ metadata.gz: cabbab36793295169ed3b60028e9d03ced46c17e253c4137992b9f44ffa70aa4c93bbdc4be7407551566ed336160e4c70da73a9b69c4b88dbe38a94b13739231
7
+ data.tar.gz: bd1ec0e3e33e779c1f05cbf0a53c5c4e9045678fd2157f9ca397043415c19aefe33a5daebe3e0a61fd50d7061a3768ebba2290d9b2527babd4790cb91851a32a
data/.rspec_status CHANGED
@@ -1,11 +1,15 @@
1
- example_id | status | run_time |
2
- ------------------------------------- | ------ | --------------- |
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
- ./spec/ruby_var_dump_spec.rb[1:1:3:1] | passed | 0.00003 seconds |
7
- ./spec/ruby_var_dump_spec.rb[1:1:3:2] | passed | 0.00004 seconds |
8
- ./spec/ruby_var_dump_spec.rb[1:1:4:1] | passed | 0.00003 seconds |
9
- ./spec/ruby_var_dump_spec.rb[1:1:4:2] | passed | 0.00003 seconds |
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.00009 seconds |
1
+ example_id | status | run_time |
2
+ --------------------------------------- | ------ | --------------- |
3
+ ./spec/ruby_var_dump_spec.rb[1:1:1] | passed | 0.00033 seconds |
4
+ ./spec/ruby_var_dump_spec.rb[1:1:2:1:1] | passed | 0.00027 seconds |
5
+ ./spec/ruby_var_dump_spec.rb[1:1:2:1:2] | passed | 0.00121 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.00013 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.00004 seconds |
14
+ ./spec/ruby_var_dump_spec.rb[1:1:5:1] | passed | 0.00005 seconds |
15
+ ./spec/ruby_var_dump_spec.rb[1:1:6:1] | passed | 0.00009 seconds |
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2024 hirokiyam
3
+ Copyright (c) 2025 hirokiyam
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyVarDump
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.6"
5
5
  end
data/lib/ruby_var_dump.rb CHANGED
@@ -5,7 +5,17 @@ require_relative "ruby_var_dump/version"
5
5
  module RubyVarDump
6
6
  class Error < StandardError; end
7
7
 
8
- def dump(obj, level = 0, is_value = false, dumped_objects = [], is_first=true)
8
+ # カラーコードの定義
9
+ RED_COLOR = "\e[38;5;196m" # 赤色
10
+ LIGHT_RED_COLOR = "\e[38;5;203m" # サーモンピンク
11
+ BLUE_COLOR = "\e[38;5;27m" # 青色
12
+ GREEN_COLOR = "\e[38;5;2m" # 緑色
13
+ LIGHT_GREEN_COLOR = "\e[38;5;10m" # 薄緑色
14
+ # LIGHT_BLUE = "\e[38;5;45m" # 水色
15
+ ORANGE_COLOR = "\e[38;5;214m" # オレンジ色
16
+ RESET_COLOR = "\e[0m" # 色リセット
17
+
18
+ def vdump(obj, level = 0, is_value = false, dumped_objects = [], is_first=true)
9
19
  indent = ' ' * level * 2
10
20
 
11
21
  if (defined?(ActiveRecord::Base) && obj.is_a?(ActiveRecord::Base)) || (defined?(ActiveRecord::Relation) && obj.is_a?(ActiveRecord::Relation))
@@ -25,7 +35,7 @@ module RubyVarDump
25
35
  else
26
36
  print "\n"
27
37
  obj.each_with_index do |item, index|
28
- dump(item, level + 1, false, dumped_objects, false)
38
+ vdump(item, level + 1, false, dumped_objects, false)
29
39
  print "," unless index == obj.size - 1
30
40
  print "\n"
31
41
  end
@@ -43,9 +53,10 @@ module RubyVarDump
43
53
  # キーにインデントを適用し、値にはインデントを適用しない
44
54
  print "#{indent} #{key.inspect.chomp} => "
45
55
  if value.is_a?(Hash) || value.is_a?(Array)
46
- dump(value, level + 1, true, dumped_objects, false) # ハッシュのバリューの場合には is_value を true に設定
56
+ vdump(value, level + 1, true, dumped_objects, false) # ハッシュのバリューの場合には is_value を true に設定
47
57
  else
48
- print value.inspect # プリミティブな値の場合は現在のレベルで出力
58
+ # プリミティブな値の場合は現在のレベルで出力
59
+ print colorize_by_type(value)
49
60
  end
50
61
  print "," unless index == obj.size - 1
51
62
  print "\n"
@@ -56,10 +67,10 @@ module RubyVarDump
56
67
  elsif defined?(ActiveRecord::Base) && obj.is_a?(ActiveRecord::Base)
57
68
  # ActiveRecordオブジェクトの場合
58
69
  print "\n" unless is_first # 最初のレコード以外の場合に改行を入れる
59
- print "#{indent}#{obj.class}:#{obj.object_id}\n"
70
+ print "#{indent}#{GREEN_COLOR}#{obj.class}:#{obj.object_id}#{RESET_COLOR}\n"
60
71
  print "#{indent}{\n"
61
72
  obj.attributes.each do |attr_name, attr_value|
62
- print "#{indent} #{attr_name}: #{attr_value.inspect},\n"
73
+ print "#{indent} #{attr_name}: #{colorize_by_type(attr_value)},\n"
63
74
  end
64
75
  # リレーションも再帰的にダンプ
65
76
  obj.class.reflect_on_all_associations.each do |association|
@@ -72,11 +83,11 @@ module RubyVarDump
72
83
  associated_value.each do |item|
73
84
  next if dumped_objects.any? { |dumped_obj| dumped_obj.object_id == item.object_id && dumped_obj.class == item.class }
74
85
 
75
- # CollectionProxy の内容(アソシエーション)をダンプ
76
- print("#{indent} #{association.name} (association): << #{item.class}:#{item.object_id} >>\n")
86
+ # CollectionProxy の内容(アソシエーション)をダンプ
87
+ print("#{indent} #{RED_COLOR}#{association.name} #{ORANGE_COLOR}(association)#{RESET_COLOR}: #{GREEN_COLOR}<< #{item.class}:#{item.object_id} >>#{RESET_COLOR}\n")
77
88
  print("#{indent} {\n")
78
89
  item.attributes.each do |attr_name, attr_value|
79
- print("#{indent} #{attr_name}: #{attr_value.inspect}\n")
90
+ print("#{indent} #{attr_name}: #{colorize_by_type(attr_value)}\n")
80
91
  end
81
92
 
82
93
  print("#{indent} }\n") #ここまでアソシエーションの描画
@@ -88,16 +99,38 @@ module RubyVarDump
88
99
  print "#{indent}#{obj.class}:#{obj.object_id}\n"
89
100
  print "#{indent}[\n"
90
101
  obj.each_with_index do |item, index|
91
- dump(item, level + 1, false, dumped_objects, index == 0)
102
+ vdump(item, level + 1, false, dumped_objects, index == 0)
92
103
  end
93
104
  print "#{indent}]"
94
105
  print "\n" if level == 0 # メソッドの出力の最後に改行を追加
95
106
  elsif obj.respond_to?(:attributes)
96
- dump(obj.attributes, level, false, dumped_objects, false)
107
+ vdump(obj.attributes, level, false, dumped_objects, false)
97
108
  else
98
- print indent + obj.inspect.chomp
109
+ print indent + colorize_by_type(obj) # プリミティブな値の場合を出力
99
110
  print "\n" if level == 0 # メソッドの出力の最後に改行を追加
100
111
  end
101
112
  end
113
+
114
+ # エイリアスを設定。vdump メソッドの別名として vpp を定義
115
+ alias vpp vdump
116
+
117
+ private
118
+
119
+ def colorize_by_type(obj)
120
+ color = color_for(obj)
121
+ "#{color}#{obj.inspect.chomp}#{RESET_COLOR}"
122
+ end
123
+
124
+ def color_for(obj)
125
+ if obj.is_a?(String)
126
+ LIGHT_RED_COLOR
127
+ elsif obj.is_a?(Numeric)
128
+ BLUE_COLOR
129
+ elsif obj.is_a?(Date) || obj.is_a?(Time) || obj.is_a?(DateTime)
130
+ LIGHT_GREEN_COLOR
131
+ else
132
+ ""
133
+ end
134
+ end
102
135
  end
103
136
  # 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
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - hirokiyam
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-16 00:00:00.000000000 Z
11
+ date: 2025-03-22 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.