yalphabetize 0.9.0 → 0.11.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: db5c206b439820c318f76ccbe2d619b5447cc845da80d3dfa19b35fb9a056591
4
- data.tar.gz: 7071afd335644554083b00b0bc5e76391e015642fb8b2070496a0bc8a05d4b60
3
+ metadata.gz: 620d06de0e383ed3e49a6878958f5fceef74ce7ed12d50e179110ebddb5c9fb3
4
+ data.tar.gz: 85e47f431754b89bfe3ac0b67d46f77f4f1467b351607e8289e9a1b142772ad5
5
5
  SHA512:
6
- metadata.gz: 2bc9f38dde46a29af96fd2fe8e1c1411ced5eb56eec823456ab408f3d4e972354606e1493b23d99154a4931a302619d2f7c03c8b3eea2eae9f2aa9ce174c017d
7
- data.tar.gz: 7d3126ce78da54e013f77710f2f0613f13848eb52914ca1b75b02c21665b696c0f615328657a3da85220167fb5b8a2f1e899b4071f964cc5255218780ed03f91
6
+ metadata.gz: c388188a52fec11ef2a15c547845ddc213d3a8a2d7b8db0cd972d5e9aa22b8ac78216e812ade4006b77c1e49de7300c84f767f6f4ed5fb951acd602c73859cca
7
+ data.tar.gz: a8ed2b327a0542514b9bc419b07daa0a7c982fb0ad0f62da9a2292d45243661eb66149b379eb925984ed54bc97b11a2296d1a86f4527781f42ba0707d77984d4
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Key length | File length | No of files | Iterations | Benchmark (s)
4
+ bundle exec bin/performance_test 1 1 1 250 0.06 &&
5
+ bundle exec bin/performance_test 1 1 10000 50 0.41 &&
6
+ bundle exec bin/performance_test 1 100000 1 60 0.41 &&
7
+ bundle exec bin/performance_test 1 1000 1000 12 2.6 &&
8
+ bundle exec bin/performance_test 1024 1 1 250 0.06 &&
9
+ bundle exec bin/performance_test 1024 1 40000 12 1.9 &&
10
+ bundle exec bin/performance_test 1024 100000 1 30 1.1 &&
11
+ bundle exec bin/performance_test 1024 800 340 12 2.3
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'benchmark'
5
+ require 'fileutils'
6
+ require 'securerandom'
7
+ require 'yalphabetize'
8
+
9
+ key_length = ARGV[0].to_i
10
+ file_length = ARGV[1].to_i
11
+ number_of_files = ARGV[2].to_i
12
+ iterations = ARGV[3].to_i
13
+ expected = ARGV[4].to_f
14
+
15
+ def suppress_output
16
+ original_stdout = $stdout.clone
17
+ $stdout.reopen(File.new(File::NULL, 'w'))
18
+ yield
19
+ ensure
20
+ $stdout.reopen(original_stdout)
21
+ end
22
+
23
+ puts "Running performance test:\n\n"
24
+ puts "key_length: #{key_length}"
25
+ puts "file_length: #{file_length}"
26
+ puts "number_of_files: #{number_of_files}"
27
+ puts "iterations: #{iterations}"
28
+ puts "expected: #{expected}\n\n"
29
+
30
+ fixtures_dir = "performance/fixtures/#{key_length}_#{file_length}_#{number_of_files}"
31
+
32
+ if !Dir.exist?(fixtures_dir) && !ENV['CI']
33
+ FileUtils.makedirs(fixtures_dir)
34
+
35
+ number_of_files.times do |i|
36
+ yaml = ''
37
+ file_length.times do
38
+ yaml += "#{SecureRandom.alphanumeric(key_length)}: VALUE\n"
39
+ end
40
+
41
+ puts "#{i.fdiv(number_of_files) * 100}% of files written"
42
+
43
+ File.write("#{fixtures_dir}/#{i + 1}.yml", yaml)
44
+ end
45
+ end
46
+
47
+ if !Dir.exist?(fixtures_dir) && ENV['CI']
48
+ puts "Could not find fixtures directory #{fixtures_dir}"
49
+ exit 1
50
+ end
51
+
52
+ times = []
53
+
54
+ suppress_output do
55
+ iterations.times do
56
+ times << Benchmark.measure do
57
+ Yalphabetize::CLI.call([fixtures_dir])
58
+ end.real
59
+ end
60
+ end
61
+
62
+ sorted_times = times.sort
63
+ duration = times.sum
64
+ p50 = sorted_times[iterations / 2]
65
+
66
+ if p50 > expected
67
+ puts 'FAILED'
68
+ puts "Duration: #{duration}"
69
+ puts "P50: #{p50}"
70
+ exit 1
71
+ else
72
+ puts "Duration: #{duration}"
73
+ puts "p50: #{p50}\n\n\n"
74
+ end
@@ -2,41 +2,40 @@
2
2
 
3
3
  module Yalphabetize
4
4
  class Logger
5
- DEFAULT_OUTPUT = $stdout
5
+ DEFAULT_OUTPUT = Kernel
6
6
 
7
- def initialize(output = DEFAULT_OUTPUT)
8
- @output = output
7
+ def initialize
9
8
  @inspected_count = 0
10
9
  @offences = {}
11
10
  end
12
11
 
13
12
  def initial_summary(file_paths)
14
- output.puts "Inspecting #{file_paths.size} YAML files"
13
+ DEFAULT_OUTPUT.puts "Inspecting #{file_paths.size} YAML files"
15
14
  end
16
15
 
17
16
  def log_offence(file_path)
18
17
  self.inspected_count += 1
19
18
  offences[file_path] = :detected
20
- output.print red 'O'
19
+ DEFAULT_OUTPUT.print red 'O'
21
20
  end
22
21
 
23
22
  def log_no_offence
24
23
  self.inspected_count += 1
25
- output.print green '.'
24
+ DEFAULT_OUTPUT.print green '.'
26
25
  end
27
26
 
28
27
  def final_summary
29
- output.puts "\nInspected: #{inspected_count}"
30
- output.puts send(list_offences_color, "Offences: #{offences.size}")
28
+ DEFAULT_OUTPUT.puts "\nInspected: #{inspected_count}"
29
+ DEFAULT_OUTPUT.puts send(list_offences_color, "Offences: #{offences.size}")
31
30
 
32
31
  offences.each { |file_path, status| puts_offence(file_path, status) }
33
- return unless offences?
32
+ return unless uncorrected_offences?
34
33
 
35
- output.puts 'Offences can be automatically fixed with `-a` or `--autocorrect`'
34
+ DEFAULT_OUTPUT.puts 'Offences can be automatically fixed with `-a` or `--autocorrect`'
36
35
  end
37
36
 
38
- def offences?
39
- @offences.any?
37
+ def uncorrected_offences?
38
+ offences.value?(:detected)
40
39
  end
41
40
 
42
41
  def log_correction(file_path)
@@ -45,20 +44,20 @@ module Yalphabetize
45
44
 
46
45
  private
47
46
 
48
- attr_reader :offences, :output
47
+ attr_reader :offences
49
48
  attr_accessor :inspected_count
50
49
 
51
50
  def puts_offence(file_path, status)
52
51
  case status
53
52
  when :detected
54
- output.puts yellow file_path
53
+ DEFAULT_OUTPUT.puts yellow file_path
55
54
  when :corrected
56
- output.puts("#{yellow(file_path)} #{green('CORRECTED')}")
55
+ DEFAULT_OUTPUT.puts("#{yellow(file_path)} #{green('CORRECTED')}")
57
56
  end
58
57
  end
59
58
 
60
59
  def list_offences_color
61
- offences? ? :red : :green
60
+ offences.any? ? :red : :green
62
61
  end
63
62
 
64
63
  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.11.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
@@ -25,7 +25,7 @@ module Yalphabetize
25
25
  process_paths(paths)
26
26
  end
27
27
 
28
- files.flatten.select { |file| valid?(file) }.map { |f| File.expand_path(f) }.uniq
28
+ files.flatten.select { |file| valid?(file) }.uniq
29
29
  end
30
30
 
31
31
  private
@@ -56,7 +56,7 @@ module Yalphabetize
56
56
  '--exclude-standard', '--others', '--cached', '--modified'
57
57
  )
58
58
 
59
- output.split("\0").uniq.map { |git_file| "#{Dir.pwd}/#{git_file}" } if status.success?
59
+ output.split("\0").uniq if status.success?
60
60
  end
61
61
 
62
62
  def valid?(path)
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,22 +1,38 @@
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.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Jenkins
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-11 00:00:00.000000000 Z
12
- dependencies: []
13
- description:
14
- email:
11
+ date: 2024-12-31 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'
27
+ description:
28
+ email:
15
29
  executables:
16
30
  - yalphabetize
17
31
  extensions: []
18
32
  extra_rdoc_files: []
19
33
  files:
34
+ - bin/performance_local
35
+ - bin/performance_test
20
36
  - bin/yalphabetize
21
37
  - lib/yalphabetize.rb
22
38
  - lib/yalphabetize/aliaser.rb
@@ -40,11 +56,11 @@ files:
40
56
  - lib/yalphabetize/writer.rb
41
57
  - lib/yalphabetize/yalphabetizer.rb
42
58
  - lib/yalphabetize/yaml_finder.rb
43
- homepage:
59
+ homepage:
44
60
  licenses: []
45
61
  metadata:
46
62
  rubygems_mfa_required: 'true'
47
- post_install_message:
63
+ post_install_message:
48
64
  rdoc_options: []
49
65
  require_paths:
50
66
  - lib
@@ -59,8 +75,8 @@ 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
63
- signing_key:
78
+ rubygems_version: 3.3.27
79
+ signing_key:
64
80
  specification_version: 4
65
81
  summary: Alphabetize your YAML files
66
82
  test_files: []