psych-pure 0.1.4 → 0.2.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: f1767eb97091e21f83527221b9ef4f156d9db40998b9008422b3dc017ff4ada6
4
- data.tar.gz: b7e1d3b11886a31fda7fd7aed9937e2c26eaafa6d5e242a65bb89c8a02b00be7
3
+ metadata.gz: 3b495922e35ffc07633da357273f8df93cc949fff0582eb5d6bf6d05c1e3ea19
4
+ data.tar.gz: 4a42f95af624a0712a49ea6dddd3ab5d0e382f65fb48a4d5a6e8fcbdf0195f39
5
5
  SHA512:
6
- metadata.gz: 7103d8ceae77bf15b2f21f9462f65fe495bf6e90206749fded264d192beb1caee6ae1a0585703ce914d7268a1e57f498f4cc1b824c21b3c5fe95edfb1dc1e320
7
- data.tar.gz: 570ba899c74d5873ba243771ae3ff71605b59f81b1567f5f0712314aa2f8efbbdfab659c4e9bde63609ce2ef5ccce46352624c0f458ef6a8ddd31826edcfa9da
6
+ metadata.gz: fd5c511ad9ba206d9d7f012a80cb0924c07f3b9b0b0e860d296404ec7b4a39a5bc5cd1391ae207e213ba4b19d197dc341550bab944a4c384164e30021fdde9d0
7
+ data.tar.gz: 92bbc9e614dbd526792c45dca5cb1e5b38e463f2def07e47bc8b419f97236dce6823ef6b2303036a8db59c755e463e34a47254052b36688a3eb9824062043830
data/CHANGELOG.md CHANGED
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.2.0] - 2025-11-11
10
+
11
+ - Add `sequence_indent` option to `Psych::Pure.dump` to control whether sequence elements contained within mapping elements are indented.
12
+ - Properly handle mutation methods on loaded objects that mutate in place.
13
+
9
14
  ## [0.1.4] - 2025-11-10
10
15
 
11
16
  - Fix up comment handling preceding sequence elements.
@@ -37,7 +42,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
37
42
 
38
43
  - 🎉 Initial release. 🎉
39
44
 
40
- [unreleased]: https://github.com/kddnewton/psych-pure/compare/v0.1.3...HEAD
45
+ [unreleased]: https://github.com/kddnewton/psych-pure/compare/v0.2.0...HEAD
46
+ [0.2.0]: https://github.com/kddnewton/psych-pure/compare/v0.1.4...v0.2.0
47
+ [0.1.4]: https://github.com/kddnewton/psych-pure/compare/v0.1.3...v0.1.4
41
48
  [0.1.3]: https://github.com/kddnewton/psych-pure/compare/v0.1.2...v0.1.3
42
49
  [0.1.2]: https://github.com/kddnewton/psych-pure/compare/v0.1.1...v0.1.2
43
50
  [0.1.1]: https://github.com/kddnewton/psych-pure/compare/v0.1.0...v0.1.1
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Psych
4
4
  module Pure
5
- VERSION = "0.1.4"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
data/lib/psych/pure.rb CHANGED
@@ -201,15 +201,37 @@ module Psych
201
201
  # rely on the source formatting, and need to format it ourselves.
202
202
  attr_reader :dirty
203
203
 
204
- def initialize(object, psych_node, dirty = false)
204
+ def initialize(object, psych_node)
205
205
  super(object)
206
206
  @psych_node = psych_node
207
- @dirty = dirty
207
+ @dirty = false
208
208
  end
209
209
 
210
- def replace(psych_node)
211
- @psych_node = psych_node
212
- @dirty = true
210
+ def initialize_clone(obj, freeze: nil)
211
+ super
212
+ @psych_node = obj.psych_node.dup
213
+ end
214
+
215
+ def initialize_dup(obj)
216
+ super
217
+ @psych_node = obj.psych_node.dup
218
+ end
219
+
220
+ # Effectively implement the same method_missing as SimpleDelegator, but
221
+ # additionally track whether or not the object has been mutated.
222
+ ruby2_keywords def method_missing(name, *args, &block)
223
+ takes_block = false
224
+ target = self.__getobj__ { takes_block = true }
225
+
226
+ if !takes_block && target_respond_to?(target, name, false)
227
+ previous = target.dup
228
+ result = target.__send__(name, *args, &block)
229
+
230
+ @dirty = true unless previous.eql?(target)
231
+ result
232
+ else
233
+ super(name, *args, &block)
234
+ end
213
235
  end
214
236
  end
215
237
 
@@ -3559,8 +3581,9 @@ module Psych
3559
3581
  # The visitor is responsible for walking the tree and generating the YAML
3560
3582
  # output.
3561
3583
  class Visitor
3562
- def initialize(q)
3584
+ def initialize(q, sequence_indent: false)
3563
3585
  @q = q
3586
+ @sequence_indent = sequence_indent
3564
3587
  end
3565
3588
 
3566
3589
  # Visit an AliasNode.
@@ -3777,6 +3800,11 @@ module Psych
3777
3800
  elsif inlined || value.anchor || value.tag || value.value.empty?
3778
3801
  @q.text(" ")
3779
3802
  @q.nest(2) { visit(value) }
3803
+ elsif @sequence_indent
3804
+ @q.nest(2) do
3805
+ @q.breakable
3806
+ visit(value)
3807
+ end
3780
3808
  else
3781
3809
  @q.breakable
3782
3810
  visit(value)
@@ -4006,7 +4034,7 @@ module Psych
4006
4034
  q.text(" ")
4007
4035
  end
4008
4036
 
4009
- node.accept(Visitor.new(q))
4037
+ node.accept(Visitor.new(q, sequence_indent: @options.fetch(:sequence_indent, false)))
4010
4038
  q.breakable
4011
4039
  q.current_group.break
4012
4040
  q.flush
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: psych-pure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Newton
@@ -113,7 +113,7 @@ licenses:
113
113
  - MIT
114
114
  metadata:
115
115
  bug_tracker_uri: https://github.com/kddnewton/psych-pure/issues
116
- changelog_uri: https://github.com/kddnewton/psych-pure/blob/v0.1.4/CHANGELOG.md
116
+ changelog_uri: https://github.com/kddnewton/psych-pure/blob/v0.2.0/CHANGELOG.md
117
117
  source_code_uri: https://github.com/kddnewton/psych-pure
118
118
  rubygems_mfa_required: 'true'
119
119
  post_install_message: