ruby_var_dump 0.3.0 → 0.4.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: 68bd2adc9a3d1388b40b55dcdcfc8093b719c84341aa05babf48235319ee592d
4
- data.tar.gz: 47726151d3cdfe8be8d0a1ba21bbbd203336918c5dcd5277752edfb39741fb6c
3
+ metadata.gz: 799e399b73739ab114d6779761b0cbe83f412846ed01d80222e8e776eaf91179
4
+ data.tar.gz: 98c621772c8f09e46576509d89042ccae209e35caf32437f43568f2f9575ec42
5
5
  SHA512:
6
- metadata.gz: 43e87259f0741c9517d7918c66e6166c92aca62cb3dab44e91b0cf381ad72f556ace05c53a4859a939d014dc7d363e5bf4fdb47be349afca93671acfd6ef4a67
7
- data.tar.gz: d698c17ea7903336b094fbba26ae3355c67517c836a6466280d8ed07caa60f68bdcee356c3d06a836d01b51304aa08c6bb50d64184951b9b722a692397626275
6
+ metadata.gz: b7ea84c346dbd477d62a6dcd3ef3bb7b670d847c9300d48fb08fa2b297f9b28861f9b8ef9d6e231ed45661f9e2402bd3e69ea19b561126ac57383556e91d5ba7
7
+ data.tar.gz: 51c4decf8a2c4df4a20fae7d69a5b02a3fc1057bbaacf8484dfe8eeeb3ad972d3893cbd47c93f80a50c4bc96a7d0d7f986e65ffe9f43d24b62736dfc260cb667
data/CHANGELOG.md CHANGED
@@ -1,5 +1,55 @@
1
- ## [Unreleased]
1
+ # Change Log
2
2
 
3
- ## [0.1.0] - 2024-04-14
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [0.4.0] - 2026-07-12
6
+ ### Changed
7
+ - The gem now automatically includes `RubyVarDump` into `Object` when required. You no longer need to create `config/initializers/setup_ruby_var_dump.rb` or write `Object.include RubyVarDump` manually — just requiring the gem (e.g. adding it to your `Gemfile`) makes `vdump` / `vpp` available on all objects.
8
+
9
+ > **Note:** Requiring the gem now automatically includes `RubyVarDump` into `Object`. If you previously relied on `require` NOT modifying `Object`, be aware of this behavior change.
10
+
11
+ ### Added
12
+ - Added a global setting `RubyVarDump.assoc` to toggle Active Record association output. Defaults to `1` (ON). Set `RubyVarDump.assoc = 0` to hide associations (`belongs_to` / `has_one` / `has_many` / `has_and_belongs_to_many`), and `RubyVarDump.assoc = 1` to show them again.
13
+
14
+ ## [0.3.0] - 2025-05-07
15
+ ### Added
16
+ - Added header at the beginning of output and footer at the end of output
17
+
18
+ ## [0.2.0] - 2025-05-07
19
+ ### Added
20
+ - Modified to pick up belongs_to and has_one
21
+
22
+ ## [0.1.6] - 2025-03-22
23
+ ### Added
24
+ - I introduced `vpp` as an alias for `vdump`, where vpp stands for visual pretty print. It performs the same function as vdump, enhancing the usability and accessibility of the visual debugging features.
4
25
 
5
- - Initial release
26
+ - Enhanced color coding for output to improve readability and debugging experience:
27
+ - Numbers are now displayed in blue, making it easier to distinguish numeric data.
28
+ - Strings are highlighted in salmon pink, helping them stand out in the output.
29
+ - Active Record relations are shown in red and orange, aiding in differentiation of nested structures within database relationships.
30
+ - Class objects are represented in green, clarifying type information at a glance.
31
+
32
+ ## [0.1.5] - 2025-02-27
33
+ ### Added
34
+ - Changed the method name from dump to vdump.
35
+
36
+ ## [0.1.4] - 2024-05-17
37
+ ### Added
38
+ - Added Active Record relation output.
39
+
40
+ ## [0.1.3] - 2024-04-20
41
+ ### Added
42
+ - Fixed the implementation of adding a newline at the end.
43
+
44
+ ## [0.1.2] - 2024-04-14
45
+ ### Added
46
+ - Add a newline at the end.
47
+
48
+ ## [0.1.1] - 2024-04-14
49
+ ### Added
50
+ - `RubyVarDump` module's method added to `Object` class to enhance accessibility.
51
+
52
+ ## [0.1.0] - 2024-04-14
53
+ ### Added
54
+ - Initial release of the `ruby_var_dump` gem.
55
+ - Implemented the core functionality for dumping object details.
data/README.md CHANGED
@@ -1,35 +1,335 @@
1
- # RubyVarDump
1
+ # ruby_var_dump
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ A Ruby gem for detailed debugging and inspection of objects, mimicking PHP's `var_dump` function.
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ruby_var_dump`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ ## Usage
6
6
 
7
- ## Installation
7
+ Just install the gem and require it — `vdump` (and its alias `vpp`) become available on every object automatically. Here's how to get started:
8
8
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
9
+ ### Installation
10
10
 
11
- Install the gem and add to the application's Gemfile by executing:
11
+ First, add the gem to your application's Gemfile:
12
12
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
13
+ ```ruby
14
+ gem 'ruby_var_dump'
15
+ ```
14
16
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
17
+ Then, run the following command to install the gem:
16
18
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
19
+ ```bash
20
+ bundle install
21
+ ```
18
22
 
19
- ## Usage
23
+ Alternatively, you can install it yourself as:
24
+
25
+ ```bash
26
+ gem install ruby_var_dump
27
+ ```
28
+
29
+ ### Example Setup
30
+
31
+ Here's a simple example. Once the gem is required, `vdump` / `vpp` can be called from anywhere — no `include` is needed:
32
+
33
+ ```ruby
34
+ require 'ruby_var_dump'
35
+
36
+ class ExampleClass
37
+ def show_example_usage
38
+ # Define some example data
39
+ my_hash = {key1: "value1", key2: 123}
40
+ my_array = [1, 2, 3, {nested_key: "nested_value"}]
41
+
42
+ # Use the vdump method to output the structure of these objects
43
+ # Or you can use the 'vpp' method as an alias
44
+ vdump my_hash
45
+ vdump my_array
46
+
47
+ # Alternatively, use the 'vpp' method to achieve the same output
48
+ vpp my_hash
49
+ vpp my_array
50
+ end
51
+ end
52
+ ```
53
+
54
+ Output:
55
+
56
+ ```
57
+ {
58
+ :key1 => "value1",
59
+ :key2 => 123
60
+ }
61
+ => nil
62
+
63
+ [
64
+ 1,
65
+ 2,
66
+ 3,
67
+ {
68
+ :nested_key => "nested_value"
69
+ }
70
+ ]
71
+ => nil
72
+ ```
73
+
74
+ ### Usage in Rails
75
+
76
+ Just add it to your `Gemfile`:
77
+
78
+ ```ruby
79
+ gem 'ruby_var_dump'
80
+ ```
81
+
82
+ That's it. When the gem is loaded, it automatically includes the `RubyVarDump` module into the Ruby `Object` class, so the `vdump` method is globally available across all objects. **No initializer file is required.**
83
+
84
+ > In earlier versions you had to create `config/initializers/setup_ruby_var_dump.rb` and write `Object.include RubyVarDump` yourself. This is no longer necessary.
85
+
86
+ > **Note (behavior change in 0.4.0):** Requiring the gem now automatically includes `RubyVarDump` into `Object`.
87
+ > If you previously relied on `require` NOT modifying `Object`, be aware of it.
88
+
89
+ ### Toggling Active Record association output
90
+
91
+ By default, when you dump an Active Record object its associations (`belongs_to` / `has_one` / `has_many` / `has_and_belongs_to_many`) are also printed. You can turn this off globally via `RubyVarDump.assoc`:
92
+
93
+ ```ruby
94
+ RubyVarDump.assoc = 0 # hide associations
95
+ vpp my_record # only the record's own attributes are printed
96
+
97
+ RubyVarDump.assoc = 1 # show associations again (this is the default)
98
+ vpp my_record
99
+ ```
100
+
101
+ The default is `1` (ON).
102
+
103
+ ### method
104
+
105
+ #### vdump ( or 'vpp' as alias )
106
+ You can use `vdump` or `vpp` to print the structure of any Ruby object. Here's how you can use it:
107
+
108
+ vdump or vpp (alias of vdump)
109
+ ```ruby
110
+ vdump "abc"
111
+ or
112
+ vpp "abc"
113
+ ```
114
+
115
+ Output
116
+ ```
117
+ "abc"
118
+ => nil
119
+ ```
120
+
121
+ Example with a more complex structure:
122
+ ```ruby
123
+ item = {key1: "value1", key2: 1024, key3: {key4: {key5: "value5", key6: [11,22]}}}
124
+
125
+ vdump item
126
+ or
127
+ vpp item
128
+ ```
129
+
130
+ Output:
131
+
132
+ ```
133
+ {
134
+ :key1 => "value1",
135
+ :key2 => 1024,
136
+ :key3 => {
137
+ :key4 => {
138
+ :key5 => "value5",
139
+ :key6 => [
140
+ 11,
141
+ 22
142
+ ]
143
+ }
144
+ }
145
+ }
146
+ => nil
147
+ ```
148
+
149
+ ### vpp (alias of vdump)
150
+ `vpp`, an alias for `vdump`, stands for "visual pretty print" and can be used interchangeably to achieve the same functionality.
151
+
152
+
153
+ ### versions
154
+
155
+ In this way, arrays, hashes, and other objects are output graphically.
156
+
157
+ Version 0.1.4: added support for Active Record output.
158
+
159
+ Version 0.1.5: changed the method name from dump to vdump.
160
+
161
+ Version 0.1.6: created the alias vpp, which stands for "visual pretty print".
162
+
163
+ Version 0.2.0: modified to pick up belongs_to and has_one.
164
+
165
+ Version 0.3.0: added header at the beginning of output and footer at the end of output
166
+
167
+ Version 0.4.0: the gem now automatically includes `RubyVarDump` into `Object` on require, so no initializer file (`Object.include RubyVarDump`) is needed anymore. Also added the `RubyVarDump.assoc` setting to toggle Active Record association output (default `1` = ON; set to `0` to hide associations)
168
+
169
+
170
+
171
+ # ruby_var_dump 日本語の説明
172
+
173
+ PHPの `var_dump` 関数を模倣した、オブジェクトの詳細なデバッグ・検査を行うためのRuby用Gemです。
174
+
175
+ ## 使用方法
176
+
177
+ gem をインストールして `require` するだけで、`vdump`(およびそのエイリアス `vpp`)がすべてのオブジェクトで自動的に使えるようになります。以下で始め方を説明します。
178
+
179
+ ### インストール
180
+
181
+ まず、アプリケーションのGemfileに以下を追加してください:
182
+
183
+ ```ruby
184
+ gem 'ruby_var_dump'
185
+ ```
186
+
187
+ その後、以下のコマンドでインストール:
188
+
189
+ ```bash
190
+ bundle install
191
+ ```
192
+
193
+ もしくは、以下のコマンドで手動インストールも可能です:
194
+
195
+ ```bash
196
+ gem install ruby_var_dump
197
+ ```
198
+
199
+ ### 使用例
200
+
201
+ `require` した後は、`vdump` / `vpp` をどこからでも呼び出せます(`include` は不要です):
202
+
203
+ ```ruby
204
+ require 'ruby_var_dump'
205
+
206
+ class ExampleClass
207
+ def show_example_usage
208
+ # 出力例のデータ
209
+ my_hash = {key1: "value1", key2: 123}
210
+ my_array = [1, 2, 3, {nested_key: "nested_value"}]
211
+
212
+ # vdump または vpp メソッドで構造を出力
213
+ vdump my_hash
214
+ vdump my_array
215
+
216
+ # vpp を使用しても同様の出力
217
+ vpp my_hash
218
+ vpp my_array
219
+ end
220
+ end
221
+ ```
222
+
223
+ 出力例:
224
+
225
+ ```
226
+ {
227
+ :key1 => "value1",
228
+ :key2 => 123
229
+ }
230
+ => nil
231
+
232
+ [
233
+ 1,
234
+ 2,
235
+ 3,
236
+ {
237
+ :nested_key => "nested_value"
238
+ }
239
+ ]
240
+ => nil
241
+ ```
242
+
243
+ ### Railsでの利用方法
244
+
245
+ `Gemfile` に追加するだけです:
246
+
247
+ ```ruby
248
+ gem 'ruby_var_dump'
249
+ ```
250
+
251
+ これで完了です。gem が読み込まれると自動的に RubyVarDump モジュールが Rubyの `Object` クラスにインクルードされ、アプリケーション全体で `vdump` メソッドが利用可能になります。
252
+
253
+ > 以前のバージョンでは `config/initializers/setup_ruby_var_dump.rb` を作成し、自分で `Object.include RubyVarDump` を記述する必要がありましたが、現在は不要になりました。
254
+
255
+ > **注意(0.4.0での挙動変化):** gem を require すると自動的に `RubyVarDump` が `Object` にインクルードされます。
256
+ `require` が `Object` を変更しないことを前提にしていた場合はご注意ください。
257
+
258
+ ### アソシエーション表示の切り替え
259
+
260
+ Active Record オブジェクトをダンプすると、デフォルトではアソシエーション(`belongs_to` / `has_one` / `has_many` / `has_and_belongs_to_many`)も一緒に出力されます。これは `RubyVarDump.assoc` でグローバルに切り替えられます:
261
+
262
+ ```ruby
263
+ RubyVarDump.assoc = 0 # アソシエーションを非表示
264
+ vpp my_record # そのレコード自身の属性だけを出力
265
+
266
+ RubyVarDump.assoc = 1 # 再びアソシエーションを表示(デフォルト)
267
+ vpp my_record
268
+ ```
269
+
270
+ デフォルトは `1`(ON)です。
271
+
272
+ ### 提供メソッド
273
+
274
+ #### vdump(およびそのエイリアス `vpp`)
275
+
276
+ `vdump` または `vpp` を使用して、任意のRubyオブジェクトの構造を視覚的に出力できます。
277
+
278
+ ```ruby
279
+ vdump "abc"
280
+ # または
281
+ vpp "abc"
282
+ ```
283
+
284
+ 出力例:
285
+
286
+ ```
287
+ "abc"
288
+ => nil
289
+ ```
290
+
291
+ 複雑な構造の変数の出力例:
292
+
293
+ ```ruby
294
+ item = {key1: "value1", key2: 1024, key3: {key4: {key5: "value5", key6: [11,22]}}}
295
+
296
+ vdump item
297
+ # または
298
+ vpp item
299
+ ```
20
300
 
21
- TODO: Write usage instructions here
301
+ 出力:
22
302
 
23
- ## Development
303
+ ```
304
+ {
305
+ :key1 => "value1",
306
+ :key2 => 1024,
307
+ :key3 => {
308
+ :key4 => {
309
+ :key5 => "value5",
310
+ :key6 => [
311
+ 11,
312
+ 22
313
+ ]
314
+ }
315
+ }
316
+ }
317
+ => nil
318
+ ```
24
319
 
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
320
+ ### `vpp`(`vdump` の別名)
26
321
 
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
322
+ `vpp` `visual pretty print` の略で、`vdump` と同じ機能を持つエイリアスメソッドです。
28
323
 
29
- ## Contributing
324
+ ---
30
325
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ruby_var_dump.
326
+ ## バージョン履歴
32
327
 
33
- ## License
328
+ このGemは、配列、ハッシュ、およびその他のオブジェクトの構造を視覚的に出力することができます。
34
329
 
35
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
330
+ - **v0.1.4**: Active Recordの出力に対応
331
+ - **v0.1.5**: メソッド名を `dump` から `vdump` に変更
332
+ - **v0.1.6**: `vpp`(visual pretty print)という別名を追加
333
+ - **v0.2.0**: `belongs_to` および `has_one` の関連を出力対象に追加
334
+ - **v0.3.0**: 出力の開始と終了時に区切り線を追加
335
+ - **v0.4.0**: require 時に自動的に `RubyVarDump` を `Object` へインクルードするようにし、初期化ファイル(`Object.include RubyVarDump`)を不要にした。あわせて、Active Record のアソシエーション出力を切り替える `RubyVarDump.assoc` 設定を追加(デフォルト `1`=ON、`0` で非表示)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyVarDump
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/ruby_var_dump.rb CHANGED
@@ -5,6 +5,21 @@ require_relative "ruby_var_dump/version"
5
5
  module RubyVarDump
6
6
  class Error < StandardError; end
7
7
 
8
+ # アソシエーション(belongs_to / has_many など)を出力するかどうかのグローバル設定。
9
+ # デフォルトは 1 (ON)。`RubyVarDump.assoc = 0` で OFF にできる。
10
+ class << self
11
+ attr_writer :assoc
12
+
13
+ def assoc
14
+ @assoc.nil? ? 1 : @assoc
15
+ end
16
+
17
+ # 0 / false / nil のときだけ非表示。それ以外(1 など)は表示。
18
+ def show_associations?
19
+ !(assoc == 0 || assoc == false || assoc.nil?)
20
+ end
21
+ end
22
+
8
23
  # カラーコードの定義
9
24
  RED_COLOR = "\e[38;5;196m" # 赤色
10
25
  LIGHT_RED_COLOR = "\e[38;5;203m" # サーモンピンク
@@ -90,8 +105,10 @@ module RubyVarDump
90
105
  print "#{indent} #{attr_name}: #{colorize_by_type(attr_value)},\n"
91
106
  end
92
107
  end
93
- # リレーションも再帰的にダンプ
108
+ # リレーションも再帰的にダンプ(assoc 設定が ON のときのみ)
94
109
  obj.class.reflect_on_all_associations.each do |association|
110
+ break unless RubyVarDump.show_associations?
111
+
95
112
  next if association.macro.nil? # アソシエーションが存在しない場合はスキップ
96
113
 
97
114
  associated_value = obj.send(association.name)
@@ -186,4 +203,8 @@ module RubyVarDump
186
203
  end
187
204
  end
188
205
  end
206
+
207
+ # require するだけで全オブジェクトから vdump / vpp を呼べるように、
208
+ # gem 側で自動的に Object へ include する。
209
+ Object.include(RubyVarDump)
189
210
  # 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.3.0
4
+ version: 0.4.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-09-15 00:00:00.000000000 Z
11
+ date: 2026-07-12 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.
@@ -19,7 +19,6 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - ".rspec"
22
- - ".rspec_status"
23
22
  - ".standard.yml"
24
23
  - CHANGELOG.md
25
24
  - LICENSE.txt
@@ -51,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
50
  - !ruby/object:Gem::Version
52
51
  version: '0'
53
52
  requirements: []
54
- rubygems_version: 3.5.10
53
+ rubygems_version: 3.5.9
55
54
  signing_key:
56
55
  specification_version: 4
57
56
  summary: A Ruby gem for detailed debugging and inspection of objects.
data/.rspec_status DELETED
@@ -1,18 +0,0 @@
1
- example_id | status | run_time |
2
- --------------------------------------- | ------ | --------------- |
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 |