yalphabetize 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db5c206b439820c318f76ccbe2d619b5447cc845da80d3dfa19b35fb9a056591
4
- data.tar.gz: 7071afd335644554083b00b0bc5e76391e015642fb8b2070496a0bc8a05d4b60
3
+ metadata.gz: b2b58ea00743bea3a0a4ca4ef92caa428ced099cdf28bf4caa37bf7214333ade
4
+ data.tar.gz: b8c5d394eaf0aef402e4cab38dd1018560950e36488fb60537f9fa48c201985b
5
5
  SHA512:
6
- metadata.gz: 2bc9f38dde46a29af96fd2fe8e1c1411ced5eb56eec823456ab408f3d4e972354606e1493b23d99154a4931a302619d2f7c03c8b3eea2eae9f2aa9ce174c017d
7
- data.tar.gz: 7d3126ce78da54e013f77710f2f0613f13848eb52914ca1b75b02c21665b696c0f615328657a3da85220167fb5b8a2f1e899b4071f964cc5255218780ed03f91
6
+ metadata.gz: 54d23c05ae16c9eaa72b1f14a817618dbee8e116a0b24d46f08bbfc7ea009ad449e784f8ad07d24f159446deed6382bb7f403393ca45287d16ce740f3ec157b4
7
+ data.tar.gz: 731ca71c870831cd1d5b848f46a7d9e93c924d4e76304624762f7ff28c03e1d4eb4144e647ce059d3ce3315c3a48b29553d6e349f150be9777e6f2e4d41471af
@@ -30,13 +30,13 @@ module Yalphabetize
30
30
  output.puts send(list_offences_color, "Offences: #{offences.size}")
31
31
 
32
32
  offences.each { |file_path, status| puts_offence(file_path, status) }
33
- return unless offences?
33
+ return unless uncorrected_offences?
34
34
 
35
35
  output.puts 'Offences can be automatically fixed with `-a` or `--autocorrect`'
36
36
  end
37
37
 
38
- def offences?
39
- @offences.any?
38
+ def uncorrected_offences?
39
+ offences.value?(:detected)
40
40
  end
41
41
 
42
42
  def log_correction(file_path)
@@ -58,7 +58,7 @@ module Yalphabetize
58
58
  end
59
59
 
60
60
  def list_offences_color
61
- offences? ? :red : :green
61
+ offences.any? ? :red : :green
62
62
  end
63
63
 
64
64
  def red(string)
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'psych'
4
+ require 'psych/comments'
4
5
 
5
6
  module Yalphabetize
6
7
  class Reader
@@ -21,7 +22,7 @@ module Yalphabetize
21
22
  end
22
23
 
23
24
  def stream_node
24
- @_stream_node ||= Psych.parse_stream file
25
+ @_stream_node ||= parser_class.parse_stream file
25
26
  rescue Psych::SyntaxError => e
26
27
  raise Yalphabetize::ParsingError.new(
27
28
  path,
@@ -32,5 +33,13 @@ module Yalphabetize
32
33
  e.context
33
34
  )
34
35
  end
36
+
37
+ def parser_class
38
+ if Yalphabetize.config['preserve_comments']
39
+ Psych::Comments
40
+ else
41
+ Psych
42
+ end
43
+ end
35
44
  end
36
45
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Yalphabetize
4
4
  class Version
5
- STRING = '0.9.0'
5
+ STRING = '0.10.0'
6
6
  end
7
7
  end
@@ -20,7 +20,11 @@ module Yalphabetize
20
20
  attr_reader :stream_node, :path
21
21
 
22
22
  def new_file_content
23
- @_new_file_content ||= stream_node.to_yaml(nil, line_width: MAX_LINE_WIDTH)
23
+ @_new_file_content ||= if Yalphabetize.config['preserve_comments']
24
+ Psych::Comments.emit_yaml stream_node
25
+ else
26
+ stream_node.to_yaml(nil, line_width: MAX_LINE_WIDTH)
27
+ end
24
28
  end
25
29
 
26
30
  def indent_sequences
@@ -56,7 +56,7 @@ module Yalphabetize
56
56
 
57
57
  def final_log
58
58
  logger.final_summary
59
- logger.offences? ? 1 : 0
59
+ logger.uncorrected_offences? ? 1 : 0
60
60
  end
61
61
 
62
62
  def reader_class
data/lib/yalphabetize.rb CHANGED
@@ -28,7 +28,8 @@ module Yalphabetize
28
28
  'indent_sequences' => true,
29
29
  'exclude' => [],
30
30
  'only' => [],
31
- 'sort_by' => 'ABab'
31
+ 'sort_by' => 'ABab',
32
+ 'preserve_comments' => true
32
33
  }.freeze
33
34
 
34
35
  def config
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yalphabetize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Jenkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-11 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-11-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: psych-comments
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description:
14
28
  email:
15
29
  executables:
@@ -44,7 +58,9 @@ homepage:
44
58
  licenses: []
45
59
  metadata:
46
60
  rubygems_mfa_required: 'true'
47
- post_install_message:
61
+ post_install_message: |
62
+ yalphabetize 0.10.0 now supports YAML comments!
63
+ For more info: https://github.com/samrjenkins/yalphabetize?tab=readme-ov-file#preserve_comments
48
64
  rdoc_options: []
49
65
  require_paths:
50
66
  - lib
@@ -59,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
75
  - !ruby/object:Gem::Version
60
76
  version: '0'
61
77
  requirements: []
62
- rubygems_version: 3.3.26
78
+ rubygems_version: 3.3.27
63
79
  signing_key:
64
80
  specification_version: 4
65
81
  summary: Alphabetize your YAML files