yalphabetize 0.2.1 → 0.5.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: 1f090c28c32a6a7248ee2c256ca9d2c166947c113025cf40701471df67de36b0
4
- data.tar.gz: 42c03996392e0d810bbda8e2c2c49df5915d45ddf749d199722edc9d99105cde
3
+ metadata.gz: 9fdf038d72b2c031731160247a71b2b29375360fd23b9099f3ce6cb97f022cbc
4
+ data.tar.gz: 54906536110194ebccaf0d04137b68d65939a43951d7785aa3eb33938ef6e5d6
5
5
  SHA512:
6
- metadata.gz: bd41579935c1d015927274f68bdb525b0b4c9c713fcdc0aa68fa5b23c6c48c26cbf09f7d94d7343969324e78dedc0c2bd3cf8f9a0769a426ec871001f1478fe7
7
- data.tar.gz: ed42eecc90264a3d79ac52e08e15b4f177bda3f1f765bff77a94e965f734c937608bc404f5e9123369ec02335d19cba100d6f109c0661cf79294dfb3e2a2b94e
6
+ metadata.gz: 6d9cbba9a9b4775f275e46f85750517a23ecb552b69a0f53993377bdf1e2a4a6a52ea44b89d3ca9fae276330e909be376cea3e10977fb1c26029352bb2b32ef4
7
+ data.tar.gz: eea1b0ce802afd10154823735d675a1e7427a28bec2611017fec957fbaed28c3eff3a66a62ab6606ee31a398f9d9fbfc23baa09d3d0f217a3578911fb1204abd
data/bin/yalphabetize CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'yalphabetize/cli'
4
+ require_relative '../lib/yalphabetize'
5
5
 
6
6
  exit Yalphabetize::CLI.call(ARGV)
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yalphabetize
4
+ class Aliaser
5
+ def initialize(stream_node)
6
+ @stream_node = stream_node
7
+ @aliases = {}
8
+ end
9
+
10
+ def call
11
+ nodes.each do |node|
12
+ next unless node.respond_to?(:anchor) && node.anchor
13
+
14
+ ensure_anchor_then_alias(node)
15
+ end
16
+ stream_node
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :stream_node, :aliases
22
+
23
+ def ensure_anchor_then_alias(node)
24
+ if node.alias?
25
+ aliases[node.anchor] ||= node
26
+ elsif aliases[node.anchor]
27
+ swap(node, aliases[node.anchor])
28
+ end
29
+ end
30
+
31
+ def swap(anchor_node, alias_node)
32
+ stream_node.each do |node|
33
+ node.children&.map! do |child_node|
34
+ convert_node(child_node, anchor_node, alias_node)
35
+ end
36
+ end
37
+ end
38
+
39
+ def nodes
40
+ stream_node.select do |node|
41
+ node.respond_to?(:anchor) && node.anchor
42
+ end
43
+ end
44
+
45
+ def convert_node(child_node, anchor_node, alias_node)
46
+ if child_node == anchor_node
47
+ alias_node
48
+ elsif child_node == alias_node
49
+ anchor_node
50
+ else
51
+ child_node
52
+ end
53
+ end
54
+ end
55
+ end
@@ -2,38 +2,39 @@
2
2
 
3
3
  module Yalphabetize
4
4
  class Alphabetizer
5
- def initialize(stream_node)
5
+ def initialize(stream_node, order_checker_class:)
6
6
  @stream_node = stream_node
7
+ @order_checker_class = order_checker_class
7
8
  end
8
9
 
9
10
  def call
10
- alphabetize(stream_node)
11
- stream_node
11
+ stream_node.select(&:mapping?).each do |node|
12
+ pair_up_children(node)
13
+ alphabetize_children(node)
14
+ unpair_children(node)
15
+ end
12
16
  end
13
17
 
14
18
  private
15
19
 
16
- attr_reader :stream_node
20
+ attr_reader :stream_node, :order_checker_class
17
21
 
18
- def alphabetize(node)
19
- if node.mapping?
20
- alphabetize_children(node)
21
- unpair_children(node)
22
+ def alphabetize_children(node)
23
+ node.children.sort! do |a, b|
24
+ order_checker_class.compare(a.first.value, b.first.value)
22
25
  end
23
-
24
- node.children&.each { |child_node| alphabetize(child_node) }
25
26
  end
26
27
 
27
- def alphabetize_children(node)
28
- node.children.sort_by! { |key, _value| key.value }
28
+ def unpair_children(node)
29
+ node.children.flatten!
29
30
  end
30
31
 
31
- def unpair_children(node)
32
+ def pair_up_children(node)
32
33
  children_clone = node.children.dup
33
34
 
34
- children_clone.each do |slice|
35
- node.children.push(*slice)
36
- node.children.shift
35
+ children_clone.each_slice(2) do |slice|
36
+ node.children.push(slice)
37
+ 2.times { node.children.shift }
37
38
  end
38
39
  end
39
40
  end
@@ -1,14 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'yalphabetize/alphabetizer'
4
- require 'yalphabetize/file_yalphabetizer'
5
- require 'yalphabetize/logger'
6
- require 'yalphabetize/offence_detector'
7
- require 'yalphabetize/reader'
8
- require 'yalphabetize/writer'
9
- require 'yalphabetize/yaml_finder'
10
- require 'yalphabetizer'
11
-
12
3
  module Yalphabetize
13
4
  class CLI
14
5
  def self.call(argv)
@@ -20,20 +11,15 @@ module Yalphabetize
20
11
  end
21
12
 
22
13
  def call
23
- Yalphabetizer.call(
24
- argv,
25
- reader_class: Yalphabetize::Reader,
26
- finder: Yalphabetize::YamlFinder.new,
27
- alphabetizer_class: Yalphabetize::Alphabetizer,
28
- writer_class: Yalphabetize::Writer,
29
- offence_detector_class: Yalphabetize::OffenceDetector,
30
- logger: Yalphabetize::Logger.new($stdout),
31
- file_yalphabetizer_class: Yalphabetize::FileYalphabetizer
32
- )
14
+ Yalphabetizer.call argv, options
33
15
  end
34
16
 
35
17
  private
36
18
 
37
19
  attr_reader :argv
20
+
21
+ def options
22
+ OptionParser.parse!(argv)
23
+ end
38
24
  end
39
25
  end
@@ -41,7 +41,7 @@ module Yalphabetize
41
41
  end
42
42
 
43
43
  def compile(string)
44
- scanner = Scanner.new(string.b)
44
+ scanner = Scanner.new(string)
45
45
  scanner.scan do |token|
46
46
  next if token.nil?
47
47
  next if token == ''
@@ -10,6 +10,7 @@ module Yalphabetize
10
10
  @autocorrect = options[:autocorrect]
11
11
  @alphabetizer_class = options[:alphabetizer_class]
12
12
  @writer_class = options[:writer_class]
13
+ @order_checker_class = options[:order_checker_class]
13
14
  end
14
15
 
15
16
  def call
@@ -19,41 +20,46 @@ module Yalphabetize
19
20
  else
20
21
  logger.log_no_offence
21
22
  end
22
-
23
- replace_interpolations
24
23
  end
25
24
 
26
25
  private
27
26
 
28
- attr_reader :file_path, :reader_class, :offence_detector_class,
29
- :logger, :autocorrect, :alphabetizer_class, :writer_class
27
+ attr_reader :file_path, :reader_class, :offence_detector_class, :logger, :autocorrect,
28
+ :alphabetizer_class, :writer_class, :order_checker_class
30
29
 
31
30
  def autocorrect_file
32
- sorted_stream_node = alphabetizer_class.new(unsorted_stream_node).call
33
- writer_class.new(sorted_stream_node, file_path).call
34
- logger.log_correction(file_path)
31
+ alphabetize
32
+ handle_aliases
33
+ rewrite_yml_file
34
+ print_to_log
35
35
  end
36
36
 
37
37
  def offences?
38
- offence_detector_class.new(unsorted_stream_node).offences?
38
+ offence_detector_class.new(stream_node, order_checker_class: order_checker_class).offences?
39
39
  end
40
40
 
41
- def replace_interpolations
42
- interpolations_mapping.each do |uuid, interpolation|
43
- file_content = File.read(file_path)
44
- file_content.sub!(uuid, interpolation)
45
- File.open(file_path, 'w') do |file|
46
- file.write file_content
47
- end
48
- end
41
+ def alphabetize
42
+ alphabetizer_class.new(stream_node, order_checker_class: order_checker_class).call
43
+ end
44
+
45
+ def handle_aliases
46
+ Aliaser.new(stream_node).call
47
+ end
48
+
49
+ def rewrite_yml_file
50
+ writer_class.new(stream_node, file_path, interpolations_mapping).call
51
+ end
52
+
53
+ def print_to_log
54
+ logger.log_correction(file_path)
49
55
  end
50
56
 
51
57
  def reader
52
58
  @_reader ||= reader_class.new(file_path)
53
59
  end
54
60
 
55
- def unsorted_stream_node
56
- @_unsorted_stream_node ||= reader.to_ast
61
+ def stream_node
62
+ @_stream_node ||= reader.to_ast
57
63
  end
58
64
 
59
65
  def interpolations_mapping
@@ -2,7 +2,9 @@
2
2
 
3
3
  module Yalphabetize
4
4
  class Logger
5
- def initialize(output)
5
+ DEFAULT_OUTPUT = $stdout
6
+
7
+ def initialize(output = DEFAULT_OUTPUT)
6
8
  @output = output
7
9
  @inspected_count = 0
8
10
  @offences = {}
@@ -40,7 +42,7 @@ module Yalphabetize
40
42
 
41
43
  private
42
44
 
43
- attr_reader :output, :offences, :inspected_count
45
+ attr_reader :offences, :inspected_count, :output
44
46
 
45
47
  def puts_offence(file_path, status)
46
48
  case status
@@ -2,8 +2,9 @@
2
2
 
3
3
  module Yalphabetize
4
4
  class OffenceDetector
5
- def initialize(stream_node)
5
+ def initialize(stream_node, order_checker_class:)
6
6
  @stream_node = stream_node
7
+ @order_checker_class = order_checker_class
7
8
  end
8
9
 
9
10
  def offences?
@@ -12,7 +13,7 @@ module Yalphabetize
12
13
 
13
14
  private
14
15
 
15
- attr_reader :stream_node
16
+ attr_reader :stream_node, :order_checker_class
16
17
 
17
18
  def alphabetized?(node)
18
19
  return false if node.mapping? && !alphabetized_children?(node)
@@ -25,7 +26,9 @@ module Yalphabetize
25
26
  end
26
27
 
27
28
  def alphabetized_children?(node)
28
- node.children.each_cons(2).all? { |a, b| (a.first.value <=> b.first.value) <= 0 }
29
+ node.children.each_slice(2).each_cons(2).all? do |a, b|
30
+ order_checker_class.ordered?(a.first.value, b.first.value)
31
+ end
29
32
  end
30
33
 
31
34
  def each_child_also_alphabetized?(children)
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'optparse'
4
+
5
+ module Yalphabetize
6
+ class OptionParser
7
+ PARSER = ::OptionParser.new do |o|
8
+ o.banner = 'Usage: yalphabetize [options] [file1, file2, ...]'
9
+
10
+ o.on('-a', '--autocorrect', 'Automatically alphabetize inspected yaml files')
11
+ o.on('-h', '--help', 'Prints this help') do
12
+ puts o
13
+ Kernel.exit
14
+ end
15
+ end
16
+
17
+ def self.parse!(argv)
18
+ {}.tap { |options| PARSER.parse!(argv, into: options) }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # AaBb
4
+ module Yalphabetize
5
+ module OrderCheckers
6
+ class AlphabeticalThenCapitalizedFirst < Base
7
+ def self.compare(string, other_string)
8
+ alphabetical_comparison(string, other_string).nonzero? || string <=> other_string
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # aAbB
4
+ module Yalphabetize
5
+ module OrderCheckers
6
+ class AlphabeticalThenCapitalizedLast < Base
7
+ def self.compare(string, other_string)
8
+ alphabetical_comparison(string, other_string).nonzero? || string.swapcase <=> other_string.swapcase
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yalphabetize
4
+ module OrderCheckers
5
+ class Base
6
+ def self.ordered?(string, other_string)
7
+ !compare(string, other_string).positive?
8
+ end
9
+
10
+ private_class_method def self.alphabetical_comparison(string, other_string)
11
+ string.downcase <=> other_string.downcase
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ABab
4
+ module Yalphabetize
5
+ module OrderCheckers
6
+ class CapitalizedFirstThenAlphabetical < Base
7
+ def self.compare(string, other_string)
8
+ string <=> other_string
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # abAB
4
+ module Yalphabetize
5
+ module OrderCheckers
6
+ class CapitalizedLastThenAlphabetical < Base
7
+ def self.compare(string, other_string)
8
+ string.swapcase <=> other_string.swapcase
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yalphabetize
4
+ module OrderCheckers
5
+ TOKEN_MAPPING = {
6
+ 'abAB' => CapitalizedLastThenAlphabetical,
7
+ 'aAbB' => AlphabeticalThenCapitalizedLast,
8
+ 'AaBb' => AlphabeticalThenCapitalizedFirst,
9
+ 'ABab' => CapitalizedFirstThenAlphabetical
10
+ }.freeze
11
+ end
12
+ end
@@ -2,8 +2,6 @@
2
2
 
3
3
  require 'psych'
4
4
  require 'securerandom'
5
- require 'yalphabetize/erb_compiler'
6
- require 'yalphabetize/parsing_error'
7
5
 
8
6
  module Yalphabetize
9
7
  class Reader
@@ -14,7 +12,6 @@ module Yalphabetize
14
12
 
15
13
  def to_ast
16
14
  substitute_interpolations
17
- transform(stream_node)
18
15
  stream_node
19
16
  end
20
17
 
@@ -51,23 +48,5 @@ module Yalphabetize
51
48
  e.context
52
49
  )
53
50
  end
54
-
55
- def transform(node)
56
- node.children&.each(&method(:transform))
57
-
58
- return unless node.mapping?
59
-
60
- pair_up_children(node)
61
- end
62
-
63
- def pair_up_children(node)
64
- children_clone = node.children.dup
65
-
66
- children_clone.each_slice(2) do |slice|
67
- node.children.push(slice)
68
- node.children.shift
69
- node.children.shift
70
- end
71
- end
72
51
  end
73
52
  end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'psych'
4
+
5
+ module Yalphabetize
6
+ class SequenceIndenter
7
+ def self.call(content)
8
+ new(content).call
9
+ end
10
+
11
+ def initialize(content)
12
+ @content = content
13
+ end
14
+
15
+ def call
16
+ return unless Yalphabetize.config['indent_sequences']
17
+
18
+ find_lines_to_indent
19
+ indent!
20
+ file_lines.join
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :content
26
+
27
+ def find_lines_to_indent
28
+ @nodes_to_indent = []
29
+
30
+ stream_node.select(&:mapping?).each do |mapping_node|
31
+ block_sequence_nodes(mapping_node)&.each do |sequence_node|
32
+ @nodes_to_indent.push(*sequence_node.children)
33
+ end
34
+ end
35
+ end
36
+
37
+ def block_sequence_nodes(node)
38
+ node.children&.select { |child_node| child_node.sequence? && child_node.style == 1 }
39
+ end
40
+
41
+ def stream_node
42
+ Psych.parse_stream content
43
+ end
44
+
45
+ def indent!
46
+ @nodes_to_indent.each do |node|
47
+ node_end_line = node.start_line == node.end_line ? node.end_line : node.end_line - 1
48
+
49
+ file_lines[node.start_line..node_end_line].each do |line|
50
+ line.gsub!(line, " #{line}")
51
+ end
52
+ end
53
+ end
54
+
55
+ def file_lines
56
+ @_file_lines ||= content.each_line.to_a
57
+ end
58
+ end
59
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Yalphabetize
4
4
  class Version
5
- STRING = '0.2.1'
5
+ STRING = '0.5.0'
6
6
  end
7
7
  end
@@ -4,12 +4,16 @@ module Yalphabetize
4
4
  class Writer
5
5
  MAX_LINE_WIDTH = -1
6
6
 
7
- def initialize(stream_node, path)
7
+ def initialize(stream_node, path, interpolations_mapping)
8
8
  @stream_node = stream_node
9
9
  @path = path
10
+ @interpolations_mapping = interpolations_mapping
10
11
  end
11
12
 
12
13
  def call
14
+ indent_sequences
15
+ replace_interpolations
16
+
13
17
  File.open(path, 'w') do |file|
14
18
  file.write new_file_content
15
19
  end
@@ -17,10 +21,20 @@ module Yalphabetize
17
21
 
18
22
  private
19
23
 
20
- attr_reader :stream_node, :path
24
+ attr_reader :stream_node, :path, :interpolations_mapping
21
25
 
22
26
  def new_file_content
23
- stream_node.to_yaml nil, line_width: MAX_LINE_WIDTH
27
+ @_new_file_content ||= stream_node.to_yaml(nil, line_width: MAX_LINE_WIDTH)
28
+ end
29
+
30
+ def replace_interpolations
31
+ interpolations_mapping.each do |uuid, interpolation|
32
+ new_file_content.sub!(uuid, interpolation)
33
+ end
34
+ end
35
+
36
+ def indent_sequences
37
+ @_new_file_content = SequenceIndenter.call(new_file_content)
24
38
  end
25
39
  end
26
40
  end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yalphabetize
4
+ class Yalphabetizer
5
+ def self.call(args = [], options = {})
6
+ new(args, options).call
7
+ end
8
+
9
+ def initialize(args, options)
10
+ @args = args
11
+ @options = options
12
+ end
13
+
14
+ def call
15
+ initial_log
16
+ process_files
17
+ final_log
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :args, :options
23
+
24
+ def initial_log
25
+ logger.initial_summary(file_paths)
26
+ end
27
+
28
+ def process_files
29
+ file_paths.each(&method(:process_file))
30
+ end
31
+
32
+ def process_file(file_path)
33
+ file_yalphabetizer_class.new(
34
+ file_path,
35
+ reader_class: reader_class,
36
+ offence_detector_class: offence_detector_class,
37
+ logger: logger,
38
+ autocorrect: options[:autocorrect],
39
+ alphabetizer_class: alphabetizer_class,
40
+ writer_class: writer_class,
41
+ order_checker_class: order_checker_class
42
+ ).call
43
+ end
44
+
45
+ def file_paths
46
+ @_file_paths ||= finder.paths(only: only_paths, exclude: Yalphabetize.config['exclude'])
47
+ end
48
+
49
+ def only_paths
50
+ if args.any?
51
+ args
52
+ else
53
+ Yalphabetize.config['only']
54
+ end
55
+ end
56
+
57
+ def final_log
58
+ logger.final_summary
59
+ logger.offences? ? 1 : 0
60
+ end
61
+
62
+ def reader_class
63
+ Yalphabetize::Reader
64
+ end
65
+
66
+ def finder
67
+ Yalphabetize::YamlFinder
68
+ end
69
+
70
+ def alphabetizer_class
71
+ Yalphabetize::Alphabetizer
72
+ end
73
+
74
+ def writer_class
75
+ Yalphabetize::Writer
76
+ end
77
+
78
+ def offence_detector_class
79
+ Yalphabetize::OffenceDetector
80
+ end
81
+
82
+ def logger
83
+ @_logger ||= Yalphabetize::Logger.new
84
+ end
85
+
86
+ def file_yalphabetizer_class
87
+ Yalphabetize::FileYalphabetizer
88
+ end
89
+
90
+ def order_checker_class
91
+ OrderCheckers::TOKEN_MAPPING[Yalphabetize.config['sort_by']]
92
+ end
93
+ end
94
+ end
@@ -6,6 +6,14 @@ module Yalphabetize
6
6
  class YamlFinder
7
7
  YAML_EXTENSIONS = %w[.yml .yaml].freeze
8
8
 
9
+ def self.paths(only:, exclude:)
10
+ if exclude.any?
11
+ new.paths(only) - new.paths(exclude)
12
+ else
13
+ new.paths(only)
14
+ end
15
+ end
16
+
9
17
  def initialize
10
18
  @files = []
11
19
  end
@@ -37,7 +45,7 @@ module Yalphabetize
37
45
  end
38
46
 
39
47
  def files_in_glob(glob)
40
- files_in_dir([glob, glob.gsub('**', '')].uniq)
48
+ files_in_dir([glob, glob.gsub('**/', '').gsub('**', '')].uniq)
41
49
  end
42
50
 
43
51
  def files_in_dir(dir = Dir.pwd)
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'yalphabetize/aliaser'
4
+ require_relative 'yalphabetize/alphabetizer'
5
+ require_relative 'yalphabetize/cli'
6
+ require_relative 'yalphabetize/erb_compiler'
7
+ require_relative 'yalphabetize/file_yalphabetizer'
8
+ require_relative 'yalphabetize/logger'
9
+ require_relative 'yalphabetize/offence_detector'
10
+ require_relative 'yalphabetize/option_parser'
11
+ require_relative 'yalphabetize/order_checkers/base'
12
+ require_relative 'yalphabetize/order_checkers/alphabetical_then_capitalized_first'
13
+ require_relative 'yalphabetize/order_checkers/alphabetical_then_capitalized_last'
14
+ require_relative 'yalphabetize/order_checkers/capitalized_last_then_alphabetical'
15
+ require_relative 'yalphabetize/order_checkers/capitalized_first_then_alphabetical'
16
+ require_relative 'yalphabetize/order_checkers'
17
+ require_relative 'yalphabetize/parsing_error'
18
+ require_relative 'yalphabetize/reader'
19
+ require_relative 'yalphabetize/sequence_indenter'
20
+ require_relative 'yalphabetize/version'
21
+ require_relative 'yalphabetize/writer'
22
+ require_relative 'yalphabetize/yalphabetizer'
23
+ require_relative 'yalphabetize/yaml_finder'
24
+
25
+ module Yalphabetize
26
+ class << self
27
+ DEFAULT_CONFIG = {
28
+ 'indent_sequences' => true,
29
+ 'exclude' => [],
30
+ 'only' => [],
31
+ 'sort_by' => 'ABab'
32
+ }.freeze
33
+
34
+ def config
35
+ @_config ||= begin
36
+ specified = if File.exist?('.yalphabetize.yml')
37
+ Psych.load_file('.yalphabetize.yml') || {}
38
+ else
39
+ {}
40
+ end
41
+
42
+ DEFAULT_CONFIG.merge(specified)
43
+ end
44
+ end
45
+ end
46
+ end
metadata CHANGED
@@ -1,23 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yalphabetize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.5.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: 2021-07-11 00:00:00.000000000 Z
11
+ date: 2022-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: psych
14
+ name: factory_bot
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
- type: :runtime
20
+ type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: factory_bot
28
+ name: pry
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -66,30 +66,55 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description:
70
- email:
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
71
85
  executables:
72
86
  - yalphabetize
73
87
  extensions: []
74
88
  extra_rdoc_files: []
75
89
  files:
76
90
  - bin/yalphabetize
91
+ - lib/yalphabetize.rb
92
+ - lib/yalphabetize/aliaser.rb
77
93
  - lib/yalphabetize/alphabetizer.rb
78
94
  - lib/yalphabetize/cli.rb
79
95
  - lib/yalphabetize/erb_compiler.rb
80
96
  - lib/yalphabetize/file_yalphabetizer.rb
81
97
  - lib/yalphabetize/logger.rb
82
98
  - lib/yalphabetize/offence_detector.rb
99
+ - lib/yalphabetize/option_parser.rb
100
+ - lib/yalphabetize/order_checkers.rb
101
+ - lib/yalphabetize/order_checkers/alphabetical_then_capitalized_first.rb
102
+ - lib/yalphabetize/order_checkers/alphabetical_then_capitalized_last.rb
103
+ - lib/yalphabetize/order_checkers/base.rb
104
+ - lib/yalphabetize/order_checkers/capitalized_first_then_alphabetical.rb
105
+ - lib/yalphabetize/order_checkers/capitalized_last_then_alphabetical.rb
83
106
  - lib/yalphabetize/parsing_error.rb
84
107
  - lib/yalphabetize/reader.rb
108
+ - lib/yalphabetize/sequence_indenter.rb
85
109
  - lib/yalphabetize/version.rb
86
110
  - lib/yalphabetize/writer.rb
111
+ - lib/yalphabetize/yalphabetizer.rb
87
112
  - lib/yalphabetize/yaml_finder.rb
88
- - lib/yalphabetizer.rb
89
- homepage:
113
+ homepage:
90
114
  licenses: []
91
- metadata: {}
92
- post_install_message:
115
+ metadata:
116
+ rubygems_mfa_required: 'true'
117
+ post_install_message:
93
118
  rdoc_options: []
94
119
  require_paths:
95
120
  - lib
@@ -105,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
130
  version: '0'
106
131
  requirements: []
107
132
  rubygems_version: 3.0.3.1
108
- signing_key:
133
+ signing_key:
109
134
  specification_version: 4
110
135
  summary: Alphabetize your YAML files
111
136
  test_files: []
data/lib/yalphabetizer.rb DELETED
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'open3'
4
-
5
- class Yalphabetizer
6
- def self.call(args = [], **options)
7
- new(args, options).call
8
- end
9
-
10
- def initialize(args, options)
11
- @args = args
12
-
13
- @reader_class = options[:reader_class]
14
- @finder = options[:finder]
15
- @alphabetizer_class = options[:alphabetizer_class]
16
- @writer_class = options[:writer_class]
17
- @offence_detector_class = options[:offence_detector_class]
18
- @logger = options[:logger]
19
- @file_yalphabetizer_class = options[:file_yalphabetizer_class]
20
- end
21
-
22
- def call
23
- initial_log
24
- process_files
25
- final_log
26
- end
27
-
28
- private
29
-
30
- attr_reader :args, :reader_class, :finder, :alphabetizer_class, :writer_class,
31
- :offence_detector_class, :logger, :file_yalphabetizer_class
32
-
33
- def initial_log
34
- logger.initial_summary(file_paths)
35
- end
36
-
37
- def process_files
38
- file_paths.each(&method(:process_file))
39
- end
40
-
41
- def process_file(file_path)
42
- file_yalphabetizer_class.new(
43
- file_path,
44
- reader_class: reader_class,
45
- offence_detector_class: offence_detector_class,
46
- logger: logger,
47
- autocorrect: autocorrect?,
48
- alphabetizer_class: alphabetizer_class,
49
- writer_class: writer_class
50
- ).call
51
- end
52
-
53
- def file_paths
54
- explicit_paths = args.reject { |arg| arg[0] == '-' }
55
- finder.paths(explicit_paths)
56
- end
57
-
58
- def autocorrect?
59
- return true if args.include? '-a'
60
- return true if args.include? '--autocorrect'
61
-
62
- false
63
- end
64
-
65
- def final_log
66
- logger.final_summary
67
- logger.offences? ? 1 : 0
68
- end
69
- end