leftovers 0.11.1 → 0.11.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +1 -0
  4. data/docs/Configuration.md +7 -0
  5. data/exe/leftovers +3 -1
  6. data/leftovers.gemspec +3 -4
  7. data/lib/config/activesupport.yml +1 -1
  8. data/lib/config/rspec.yml +21 -0
  9. data/lib/leftovers/ast/array_node.rb +2 -2
  10. data/lib/leftovers/ast/block_node.rb +1 -1
  11. data/lib/leftovers/ast/builder.rb +19 -18
  12. data/lib/leftovers/ast/casgn_node.rb +2 -2
  13. data/lib/leftovers/ast/const_node.rb +1 -1
  14. data/lib/leftovers/ast/def_node.rb +1 -1
  15. data/lib/leftovers/ast/defs_node.rb +1 -1
  16. data/lib/leftovers/ast/false_node.rb +1 -1
  17. data/lib/leftovers/ast/hash_node.rb +2 -2
  18. data/lib/leftovers/ast/module_node.rb +1 -1
  19. data/lib/leftovers/ast/nil_node.rb +1 -1
  20. data/lib/leftovers/ast/node.rb +13 -1
  21. data/lib/leftovers/ast/numeric_node.rb +1 -1
  22. data/lib/leftovers/ast/send_node.rb +16 -3
  23. data/lib/leftovers/ast/str_node.rb +1 -1
  24. data/lib/leftovers/ast/sym_node.rb +1 -1
  25. data/lib/leftovers/ast/true_node.rb +1 -1
  26. data/lib/leftovers/ast/var_node.rb +1 -1
  27. data/lib/leftovers/ast/vasgn_node.rb +2 -2
  28. data/lib/leftovers/ast.rb +2 -21
  29. data/lib/leftovers/autoloader.rb +36 -0
  30. data/lib/leftovers/cli.rb +58 -42
  31. data/lib/leftovers/collection.rb +66 -0
  32. data/lib/leftovers/collector.rb +17 -27
  33. data/lib/leftovers/config.rb +17 -5
  34. data/lib/leftovers/config_loader/attribute.rb +2 -2
  35. data/lib/leftovers/config_loader/bool_schema.rb +21 -0
  36. data/lib/leftovers/config_loader/document_schema.rb +2 -2
  37. data/lib/leftovers/config_loader/inherit_schema_attributes.rb +1 -1
  38. data/lib/leftovers/config_loader/node.rb +8 -8
  39. data/lib/leftovers/config_loader/regexp_schema.rb +1 -1
  40. data/lib/leftovers/config_loader/rule_pattern_schema.rb +1 -0
  41. data/lib/leftovers/config_loader/schema.rb +1 -1
  42. data/lib/leftovers/config_loader/string_enum_schema.rb +1 -1
  43. data/lib/leftovers/config_loader/value_or_array_schema.rb +1 -1
  44. data/lib/leftovers/config_loader.rb +8 -48
  45. data/lib/leftovers/definition.rb +4 -4
  46. data/lib/leftovers/definition_collection.rb +3 -3
  47. data/lib/leftovers/definition_node.rb +2 -2
  48. data/lib/leftovers/definition_node_set.rb +1 -1
  49. data/lib/leftovers/definition_set.rb +4 -4
  50. data/lib/leftovers/definition_to_add.rb +2 -2
  51. data/lib/leftovers/error.rb +6 -0
  52. data/lib/leftovers/file.rb +4 -4
  53. data/lib/leftovers/file_collector/comments_processor.rb +23 -18
  54. data/lib/leftovers/file_collector/node_processor.rb +8 -1
  55. data/lib/leftovers/file_collector.rb +12 -15
  56. data/lib/leftovers/file_list.rb +4 -6
  57. data/lib/leftovers/matcher_builders/and.rb +5 -5
  58. data/lib/leftovers/matcher_builders/document.rb +1 -3
  59. data/lib/leftovers/matcher_builders/name.rb +4 -7
  60. data/lib/leftovers/matcher_builders/node.rb +21 -35
  61. data/lib/leftovers/matcher_builders/node_has_argument.rb +17 -29
  62. data/lib/leftovers/matcher_builders/node_has_block.rb +17 -0
  63. data/lib/leftovers/matcher_builders/node_has_keyword_argument.rb +7 -9
  64. data/lib/leftovers/matcher_builders/node_has_positional_argument.rb +10 -10
  65. data/lib/leftovers/matcher_builders/node_has_receiver.rb +6 -8
  66. data/lib/leftovers/matcher_builders/node_name.rb +3 -5
  67. data/lib/leftovers/matcher_builders/node_pair_key.rb +4 -4
  68. data/lib/leftovers/matcher_builders/node_pair_value.rb +4 -4
  69. data/lib/leftovers/matcher_builders/node_path.rb +3 -4
  70. data/lib/leftovers/matcher_builders/node_privacy.rb +3 -3
  71. data/lib/leftovers/matcher_builders/node_type.rb +13 -14
  72. data/lib/leftovers/matcher_builders/node_value.rb +18 -31
  73. data/lib/leftovers/matcher_builders/or.rb +10 -10
  74. data/lib/leftovers/matcher_builders/path.rb +3 -3
  75. data/lib/leftovers/matcher_builders/string_pattern.rb +2 -0
  76. data/lib/leftovers/matcher_builders/unless.rb +1 -3
  77. data/lib/leftovers/matcher_builders.rb +2 -22
  78. data/lib/leftovers/matchers/node_has_block.rb +13 -0
  79. data/lib/leftovers/matchers/node_scalar_value.rb +1 -1
  80. data/lib/leftovers/matchers.rb +2 -27
  81. data/lib/leftovers/merged_config.rb +16 -17
  82. data/lib/leftovers/parser.rb +1 -1
  83. data/lib/leftovers/precompile_error.rb +31 -0
  84. data/lib/leftovers/precompilers/haml.rb +23 -3
  85. data/lib/leftovers/precompilers/json.rb +1 -1
  86. data/lib/leftovers/precompilers/precompiler.rb +3 -3
  87. data/lib/leftovers/precompilers/slim.rb +1 -1
  88. data/lib/leftovers/precompilers/yaml/builder.rb +62 -0
  89. data/lib/leftovers/precompilers/yaml.rb +3 -56
  90. data/lib/leftovers/precompilers.rb +11 -16
  91. data/lib/leftovers/processor_builders/action.rb +15 -19
  92. data/lib/leftovers/processor_builders/add_prefix.rb +4 -6
  93. data/lib/leftovers/processor_builders/add_suffix.rb +4 -6
  94. data/lib/leftovers/processor_builders/argument.rb +10 -15
  95. data/lib/leftovers/processor_builders/dynamic.rb +12 -30
  96. data/lib/leftovers/processor_builders/each.rb +63 -76
  97. data/lib/leftovers/processor_builders/each_for_definition_set.rb +15 -0
  98. data/lib/leftovers/processor_builders/itself.rb +2 -4
  99. data/lib/leftovers/processor_builders/keyword.rb +4 -4
  100. data/lib/leftovers/processor_builders/keyword_argument.rb +4 -4
  101. data/lib/leftovers/processor_builders/receiver.rb +2 -4
  102. data/lib/leftovers/processor_builders/transform.rb +26 -49
  103. data/lib/leftovers/processor_builders/transform_chain.rb +4 -7
  104. data/lib/leftovers/processor_builders/transform_set.rb +6 -7
  105. data/lib/leftovers/processor_builders/value.rb +2 -2
  106. data/lib/leftovers/processor_builders.rb +2 -15
  107. data/lib/leftovers/processors/add_definition_node.rb +2 -2
  108. data/lib/leftovers/processors/camelize.rb +3 -3
  109. data/lib/leftovers/processors/deconstantize.rb +3 -3
  110. data/lib/leftovers/processors/demodulize.rb +3 -3
  111. data/lib/leftovers/processors/each_for_definition_set.rb +2 -2
  112. data/lib/leftovers/processors/eval.rb +1 -1
  113. data/lib/leftovers/processors/parameterize.rb +3 -3
  114. data/lib/leftovers/processors/placeholder.rb +1 -1
  115. data/lib/leftovers/processors/pluralize.rb +3 -3
  116. data/lib/leftovers/processors/set_default_privacy.rb +1 -1
  117. data/lib/leftovers/processors/set_privacy.rb +1 -1
  118. data/lib/leftovers/processors/singularize.rb +3 -3
  119. data/lib/leftovers/processors/titleize.rb +3 -3
  120. data/lib/leftovers/processors/underscore.rb +3 -3
  121. data/lib/leftovers/processors.rb +2 -44
  122. data/lib/leftovers/rake_task.rb +2 -2
  123. data/lib/leftovers/reporter.rb +44 -42
  124. data/lib/leftovers/runner.rb +40 -0
  125. data/lib/leftovers/todo_reporter.rb +96 -94
  126. data/lib/leftovers/unexpected_case.rb +8 -0
  127. data/lib/leftovers/version.rb +1 -1
  128. data/lib/leftovers.rb +17 -110
  129. metadata +13 -17
  130. data/lib/leftovers/matcher_builders/and_not.rb +0 -16
@@ -5,13 +5,12 @@ module Leftovers
5
5
  module Action
6
6
  class << self
7
7
  def build(patterns, final_processor)
8
- ::Leftovers::ProcessorBuilders::Each.each_or_self(patterns) do |pattern|
8
+ Each.each_or_self(patterns) do |pattern|
9
9
  case pattern
10
- when ::String, ::Integer
11
- ::Leftovers::ProcessorBuilders::Argument.build(pattern, final_processor)
10
+ when ::String, ::Integer then Argument.build(pattern, final_processor)
12
11
  when ::Hash then build_from_hash_value(**pattern, final_processor: final_processor)
13
12
  # :nocov:
14
- else raise Leftovers::UnexpectedCase, "Unhandled value #{pattern.inspect}"
13
+ else raise UnexpectedCase, "Unhandled value #{pattern.inspect}"
15
14
  # :nocov:
16
15
  end
17
16
  end
@@ -32,7 +31,7 @@ module Leftovers
32
31
  unless_arg: nil, all: nil, any: nil,
33
32
  **transform_args
34
33
  )
35
- processor = ::Leftovers::ProcessorBuilders::TransformSet.build(
34
+ processor = TransformSet.build(
36
35
  transform_args, final_processor
37
36
  )
38
37
  processor = build_nested(nested, processor) if nested
@@ -48,31 +47,28 @@ module Leftovers
48
47
  private
49
48
 
50
49
  def build_nested(nested, processor)
51
- ::Leftovers::ProcessorBuilders::Each.build([
52
- ::Leftovers::ProcessorBuilders::Action.build(nested, processor),
53
- processor
54
- ])
50
+ Each.build([Action.build(nested, processor), processor])
55
51
  end
56
52
 
57
53
  def build_sources(arguments, keywords, itself, receiver, value, processor) # rubocop:disable Metrics/ParameterLists
58
- ::Leftovers::ProcessorBuilders::Each.build([
59
- ::Leftovers::ProcessorBuilders::Argument.build(arguments, processor),
60
- ::Leftovers::ProcessorBuilders::Keyword.build(keywords, processor),
61
- ::Leftovers::ProcessorBuilders::Itself.build(itself, processor),
62
- ::Leftovers::ProcessorBuilders::Receiver.build(receiver, processor),
63
- ::Leftovers::ProcessorBuilders::Value.build(value, processor)
54
+ Each.build([
55
+ Argument.build(arguments, processor),
56
+ Keyword.build(keywords, processor),
57
+ Itself.build(itself, processor),
58
+ Receiver.build(receiver, processor),
59
+ Value.build(value, processor)
64
60
  ])
65
61
  end
66
62
 
67
63
  def build_recursive(processor)
68
- recursive_placeholder = ::Leftovers::Processors::Placeholder.new
69
- processor = ::Leftovers::ProcessorBuilders::Each.build([recursive_placeholder, processor])
64
+ recursive_placeholder = Processors::Placeholder.new
65
+ processor = Each.build([recursive_placeholder, processor])
70
66
 
71
67
  [recursive_placeholder, processor]
72
68
  end
73
69
 
74
70
  def build_matcher(has_arguments, has_receiver, unless_arg, all, any, processor) # rubocop:disable Metrics/ParameterLists
75
- matcher = Leftovers::MatcherBuilders::Node.build_from_hash(
71
+ matcher = MatcherBuilders::Node.build_from_hash(
76
72
  has_arguments: has_arguments,
77
73
  has_receiver: has_receiver,
78
74
  unless_arg: unless_arg,
@@ -82,7 +78,7 @@ module Leftovers
82
78
 
83
79
  return processor unless matcher
84
80
 
85
- ::Leftovers::Processors::MatchMatchedNode.new(matcher, processor)
81
+ Processors::MatchMatchedNode.new(matcher, processor)
86
82
  end
87
83
  end
88
84
  end
@@ -7,9 +7,9 @@ module Leftovers
7
7
  def build(argument, then_processor)
8
8
  case argument
9
9
  when ::Hash then build_hash(argument, then_processor)
10
- when ::String then ::Leftovers::Processors::AddPrefix.new(argument, then_processor)
10
+ when ::String then Processors::AddPrefix.new(argument, then_processor)
11
11
  # :nocov:
12
- else raise Leftovers::UnexpectedCase, "Unhandled value #{argument.inspect}"
12
+ else raise UnexpectedCase, "Unhandled value #{argument.inspect}"
13
13
  # :nocov:
14
14
  end
15
15
  end
@@ -17,10 +17,8 @@ module Leftovers
17
17
  private
18
18
 
19
19
  def build_hash(argument, then_processor)
20
- dynamic_prefix = ::Leftovers::ProcessorBuilders::Action.build(
21
- argument, ::Leftovers::Processors::AppendSym
22
- )
23
- ::Leftovers::Processors::AddDynamicPrefix.new(dynamic_prefix, then_processor)
20
+ dynamic_prefix = Action.build(argument, Processors::AppendSym)
21
+ Processors::AddDynamicPrefix.new(dynamic_prefix, then_processor)
24
22
  end
25
23
  end
26
24
  end
@@ -7,9 +7,9 @@ module Leftovers
7
7
  def build(argument, then_processor)
8
8
  case argument
9
9
  when ::Hash then build_hash(argument, then_processor)
10
- when ::String then ::Leftovers::Processors::AddSuffix.new(argument, then_processor)
10
+ when ::String then Processors::AddSuffix.new(argument, then_processor)
11
11
  # :nocov:
12
- else raise Leftovers::UnexpectedCase, "Unhandled value #{argument.inspect}"
12
+ else raise UnexpectedCase, "Unhandled value #{argument.inspect}"
13
13
  # :nocov:
14
14
  end
15
15
  end
@@ -17,10 +17,8 @@ module Leftovers
17
17
  private
18
18
 
19
19
  def build_hash(argument, then_processor)
20
- dynamic_suffix = ::Leftovers::ProcessorBuilders::Action.build(
21
- argument, ::Leftovers::Processors::AppendSym
22
- )
23
- ::Leftovers::Processors::AddDynamicSuffix.new(dynamic_suffix, then_processor)
20
+ dynamic_suffix = Action.build(argument, Processors::AppendSym)
21
+ Processors::AddDynamicSuffix.new(dynamic_suffix, then_processor)
24
22
  end
25
23
  end
26
24
  end
@@ -5,19 +5,16 @@ module Leftovers
5
5
  module Argument
6
6
  class << self
7
7
  def build(patterns, processor) # rubocop:disable Metrics/MethodLength
8
- ::Leftovers::ProcessorBuilders::Each.each_or_self(patterns) do |pat|
8
+ Each.each_or_self(patterns) do |pat|
9
9
  case pat
10
- when ::Integer then ::Leftovers::Processors::PositionalArgument.new(pat, processor)
11
- when '*' then ::Leftovers::Processors::EachPositionalArgument.new(processor)
12
- when '**' then ::Leftovers::Processors::EachKeywordArgument.new(processor)
13
- when /\A(\d+)\+\z/
14
- ::Leftovers::Processors::EachPositionalArgumentFrom.new(pat.to_i, processor)
15
- when ::String
16
- ::Leftovers::ProcessorBuilders::KeywordArgument.build(pat, processor)
17
- when ::Hash
18
- build_hash(processor, pat)
10
+ when ::Integer then Processors::PositionalArgument.new(pat, processor)
11
+ when '*' then Processors::EachPositionalArgument.new(processor)
12
+ when '**' then Processors::EachKeywordArgument.new(processor)
13
+ when /\A(\d+)\+\z/ then Processors::EachPositionalArgumentFrom.new(pat.to_i, processor)
14
+ when ::String then KeywordArgument.build(pat, processor)
15
+ when ::Hash then build_hash(processor, pat)
19
16
  # :nocov:
20
- else raise Leftovers::UnexpectedCase, "Unhandled value #{pat.inspect}"
17
+ else raise UnexpectedCase, "Unhandled value #{pat.inspect}"
21
18
  # :nocov:
22
19
  end
23
20
  end
@@ -26,10 +23,8 @@ module Leftovers
26
23
  private
27
24
 
28
25
  def build_hash(then_processor, pat)
29
- ::Leftovers::Processors::KeywordArgument.new(
30
- ::Leftovers::MatcherBuilders::NodePairKey.build(
31
- ::Leftovers::MatcherBuilders::Node.build_from_hash(**pat)
32
- ),
26
+ Processors::KeywordArgument.new(
27
+ MatcherBuilders::NodePairKey.build(MatcherBuilders::Node.build_from_hash(**pat)),
33
28
  then_processor
34
29
  )
35
30
  end
@@ -1,11 +1,11 @@
1
- # frozen-string-literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Leftovers
4
4
  module ProcessorBuilders
5
5
  module Dynamic
6
6
  class << self
7
7
  def build(dynamic_rules)
8
- ::Leftovers::ProcessorBuilders::Each.each_or_self(dynamic_rules) do |dynamic|
8
+ Each.each_or_self(dynamic_rules) do |dynamic|
9
9
  build_processors(**dynamic)
10
10
  end
11
11
  end
@@ -17,41 +17,23 @@ module Leftovers
17
17
  set_privacy: nil, set_default_privacy: nil,
18
18
  eval: nil, **matcher_rules
19
19
  )
20
- matcher = ::Leftovers::MatcherBuilders::Node.build(**matcher_rules)
20
+ matcher = MatcherBuilders::Node.build_from_hash(**matcher_rules)
21
21
 
22
- processor = ::Leftovers::ProcessorBuilders::Each.build([
23
- build_call_action(call),
24
- build_define_action(define),
22
+ processor = Each.build([
23
+ Action.build(call, Processors::AddCall),
24
+ Action.build(define, Processors::AddDefinitionNode),
25
25
  build_set_privacy_action(set_privacy),
26
26
  build_set_default_privacy_action(set_default_privacy),
27
- build_eval_action(eval)
27
+ Action.build(eval, Processors::Eval)
28
28
  ])
29
29
 
30
- ::Leftovers::Processors::MatchMatchedNode.new(matcher, processor)
31
- end
32
-
33
- def build_call_action(call)
34
- ::Leftovers::ProcessorBuilders::Action.build(
35
- call, ::Leftovers::Processors::AddCall
36
- )
37
- end
38
-
39
- def build_define_action(define)
40
- ::Leftovers::ProcessorBuilders::Action.build(
41
- define, ::Leftovers::Processors::AddDefinitionNode
42
- )
43
- end
44
-
45
- def build_eval_action(eval)
46
- ::Leftovers::ProcessorBuilders::Action.build(
47
- eval, ::Leftovers::Processors::Eval
48
- )
30
+ Processors::MatchMatchedNode.new(matcher, processor)
49
31
  end
50
32
 
51
33
  def build_set_privacy_action(set_privacies)
52
- ::Leftovers::ProcessorBuilders::Each.each_or_self(set_privacies) do |set_privacy|
53
- processor = ::Leftovers::Processors::SetPrivacy.new(set_privacy.delete(:to))
54
- ::Leftovers::ProcessorBuilders::Action.build_from_hash_value(
34
+ Each.each_or_self(set_privacies) do |set_privacy|
35
+ processor = Processors::SetPrivacy.new(set_privacy.delete(:to))
36
+ Action.build_from_hash_value(
55
37
  **set_privacy, final_processor: processor
56
38
  )
57
39
  end
@@ -60,7 +42,7 @@ module Leftovers
60
42
  def build_set_default_privacy_action(set_default_privacy)
61
43
  return unless set_default_privacy
62
44
 
63
- ::Leftovers::Processors::SetDefaultPrivacy.new(set_default_privacy)
45
+ Processors::SetDefaultPrivacy.new(set_default_privacy)
64
46
  end
65
47
  end
66
48
  end
@@ -3,105 +3,92 @@
3
3
  module Leftovers
4
4
  module ProcessorBuilders
5
5
  class Each
6
- def self.build(processors)
7
- self[:each].build(processors)
8
- end
9
-
10
- def self.each_or_self(value, &block)
11
- self[:each].each_or_self(value, &block)
12
- end
13
-
14
- def self.[](processor_name)
15
- @each ||= {
16
- each: new(::Leftovers::Processors::Each),
17
- each_for_definition_set: new(::Leftovers::Processors::EachForDefinitionSet)
18
- }
19
-
20
- @each.fetch(processor_name)
21
- end
6
+ class << self
7
+ def each_or_self(value, &block)
8
+ case value
9
+ when nil then nil
10
+ when ::Array then build(value.map(&block))
11
+ else build([yield(value)])
12
+ end
13
+ end
22
14
 
23
- def initialize(processor_class = ::Leftovers::Processors::Each)
24
- @processor_class = processor_class
25
- end
15
+ def build(processors)
16
+ processors = compact(processors)
26
17
 
27
- def each_or_self(value, &block)
28
- case value
29
- when nil then nil
30
- when Array then build(value.map(&block))
31
- else build([yield(value)])
18
+ case processors.length
19
+ # :nocov:
20
+ when 0 then raise UnexpectedCase, "Unhandled value #{processors.inspect}"
21
+ # :nocov:
22
+ when 1 then processors.first
23
+ else processor_class.new(processors)
24
+ end
32
25
  end
33
- end
34
26
 
35
- def build(processors)
36
- processors = compact(processors)
27
+ private
37
28
 
38
- case processors.length
39
- # :nocov:
40
- when 0 then raise Leftovers::UnexpectedCase, "Unhandled value #{processors.inspect}"
41
- # :nocov:
42
- when 1 then processors.first
43
- else @processor_class.new(processors)
29
+ def processor_class
30
+ Processors::Each
44
31
  end
45
- end
46
32
 
47
- def flatten(processors)
48
- case processors
49
- when ::Leftovers::Processors::Each, @processor_class
50
- flatten(processors.processors)
51
- when Array
52
- processors.flat_map { |v| flatten(v) }
53
- when ::Leftovers::Processors::MatchCurrentNode, ::Leftovers::Processors::MatchMatchedNode
54
- flatten_matchers(processors)
55
- else
56
- [processors]
33
+ def flatten(processors)
34
+ case processors
35
+ when Processors::Each, processor_class
36
+ flatten(processors.processors)
37
+ when ::Array
38
+ processors.flat_map { |v| flatten(v) }
39
+ when Processors::MatchCurrentNode, Processors::MatchMatchedNode
40
+ flatten_matchers(processors)
41
+ else
42
+ [processors]
43
+ end
57
44
  end
58
- end
59
45
 
60
- def flatten_matchers(processor)
61
- then_processors = flatten(processor.then_processor)
62
- return [processor] if then_processors.length <= 1
46
+ def flatten_matchers(processor)
47
+ then_processors = flatten(processor.then_processor)
48
+ return [processor] if then_processors.length <= 1
63
49
 
64
- then_processors.map do |then_processor|
65
- processor.class.new(processor.matcher, then_processor)
50
+ then_processors.map do |then_processor|
51
+ processor.class.new(processor.matcher, then_processor)
52
+ end
66
53
  end
67
- end
68
54
 
69
- def compact_matchers_with_same_processor(matchers)
70
- matchers.group_by(&:then_processor).map do |then_processor, group|
71
- next group.first unless group.length > 1
55
+ def compact_matchers_with_same_processor(matchers)
56
+ matchers.group_by(&:then_processor).map do |then_processor, group|
57
+ next group.first unless group.length > 1
72
58
 
73
- group.first.class.new(
74
- ::Leftovers::MatcherBuilders::Or.build(group.map(&:matcher)),
75
- then_processor
76
- )
59
+ group.first.class.new(
60
+ MatcherBuilders::Or.build(group.map(&:matcher)),
61
+ then_processor
62
+ )
63
+ end
77
64
  end
78
- end
79
65
 
80
- def compact_matchers_with_same_matcher(matchers)
81
- matchers.group_by(&:matcher).map do |matcher, group|
82
- next group.first unless group.length > 1
66
+ def compact_matchers_with_same_matcher(matchers)
67
+ matchers.group_by(&:matcher).map do |matcher, group|
68
+ next group.first unless group.length > 1
83
69
 
84
- group.first.class.new(matcher, build(group.map(&:then_processor)))
70
+ group.first.class.new(matcher, build(group.map(&:then_processor)))
71
+ end
85
72
  end
86
- end
87
73
 
88
- def compact_matchers(matchers)
89
- return [] unless matchers
74
+ def compact_matchers(matchers)
75
+ return [] unless matchers
90
76
 
91
- matchers = compact_matchers_with_same_processor(matchers)
92
- compact_matchers_with_same_matcher(matchers)
93
- end
77
+ matchers = compact_matchers_with_same_processor(matchers)
78
+ compact_matchers_with_same_matcher(matchers)
79
+ end
94
80
 
95
- def compact(processors)
96
- processors = flatten(processors).compact
81
+ def compact(processors)
82
+ processors = flatten(processors).compact
97
83
 
98
- return processors if processors.length <= 1
84
+ return processors if processors.length <= 1
99
85
 
100
- group = processors.group_by(&:class)
86
+ group = processors.group_by(&:class)
101
87
 
102
- compact_matchers(group.delete(::Leftovers::Processors::MatchCurrentNode)) +
103
- compact_matchers(group.delete(::Leftovers::Processors::MatchMatchedNode)) +
104
- group.values.flatten(1)
88
+ compact_matchers(group.delete(Processors::MatchCurrentNode)) +
89
+ compact_matchers(group.delete(Processors::MatchMatchedNode)) +
90
+ group.values.flatten(1)
91
+ end
105
92
  end
106
93
  end
107
94
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leftovers
4
+ module ProcessorBuilders
5
+ class EachForDefinitionSet < Each
6
+ class << self
7
+ private
8
+
9
+ def processor_class
10
+ Processors::EachForDefinitionSet
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -3,10 +3,8 @@
3
3
  module Leftovers
4
4
  module ProcessorBuilders
5
5
  module Itself
6
- def self.build(value, then_processor)
7
- return unless value
8
-
9
- ::Leftovers::Processors::Itself.new(then_processor)
6
+ def self.build(true_arg, then_processor)
7
+ Processors::Itself.new(then_processor) if true_arg
10
8
  end
11
9
  end
12
10
  end
@@ -9,15 +9,15 @@ module Leftovers
9
9
  then_processor = case value
10
10
  when true, '**' then then_processor
11
11
  when ::String, ::Hash, ::Array
12
- ::Leftovers::Processors::MatchCurrentNode.new(
13
- ::Leftovers::MatcherBuilders::NodeName.build(value), then_processor
12
+ Processors::MatchCurrentNode.new(
13
+ MatcherBuilders::NodeName.build(value), then_processor
14
14
  )
15
15
  # :nocov:
16
- else raise Leftovers::UnexpectedCase, "Unhandled value #{value.inspect}"
16
+ else raise UnexpectedCase, "Unhandled value #{value.inspect}"
17
17
  # :nocov:
18
18
  end
19
19
 
20
- ::Leftovers::Processors::EachKeyword.new(then_processor)
20
+ Processors::EachKeyword.new(then_processor)
21
21
  end
22
22
  end
23
23
  end
@@ -1,12 +1,12 @@
1
- # frozen-string-literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Leftovers
4
4
  module ProcessorBuilders
5
5
  module KeywordArgument
6
6
  def self.build(pattern, then_processor)
7
- ::Leftovers::Processors::KeywordArgument.new(
8
- ::Leftovers::MatcherBuilders::NodePairKey.build(
9
- ::Leftovers::MatcherBuilders::NodeName.build(pattern)
7
+ Processors::KeywordArgument.new(
8
+ MatcherBuilders::NodePairKey.build(
9
+ MatcherBuilders::NodeName.build(pattern)
10
10
  ),
11
11
  then_processor
12
12
  )
@@ -3,10 +3,8 @@
3
3
  module Leftovers
4
4
  module ProcessorBuilders
5
5
  module Receiver
6
- def self.build(value, then_processor)
7
- return unless value
8
-
9
- ::Leftovers::Processors::Receiver.new(then_processor)
6
+ def self.build(true_arg, then_processor)
7
+ Processors::Receiver.new(then_processor) if true_arg
10
8
  end
11
9
  end
12
10
  end
@@ -1,61 +1,38 @@
1
- # frozen-string-literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Leftovers
4
4
  module ProcessorBuilders
5
5
  module Transform
6
6
  def self.build(transform, arguments, then_processor) # rubocop:disable Metrics
7
7
  case transform
8
- when :original, nil
9
- then_processor
10
- when :downcase
11
- ::Leftovers::Processors::Downcase.new(then_processor)
12
- when :upcase
13
- ::Leftovers::Processors::Upcase.new(then_processor)
14
- when :capitalize
15
- ::Leftovers::Processors::Capitalize.new(then_processor)
16
- when :swapcase
17
- ::Leftovers::Processors::Swapcase.new(then_processor)
18
- when :pluralize
19
- ::Leftovers::Processors::Pluralize.new(then_processor)
20
- when :singularize
21
- ::Leftovers::Processors::Singularize.new(then_processor)
22
- when :camelize
23
- ::Leftovers::Processors::Camelize.new(then_processor)
24
- when :titleize
25
- ::Leftovers::Processors::Titleize.new(then_processor)
26
- when :demodulize
27
- ::Leftovers::Processors::Demodulize.new(then_processor)
28
- when :deconstantize
29
- ::Leftovers::Processors::Deconstantize.new(then_processor)
30
- when :parameterize
31
- ::Leftovers::Processors::Parameterize.new(then_processor)
32
- when :underscore
33
- ::Leftovers::Processors::Underscore.new(then_processor)
34
- when :transforms
35
- ::Leftovers::ProcessorBuilders::TransformSet.build(arguments, then_processor)
8
+ when :original, nil then then_processor
9
+ when :downcase then Processors::Downcase.new(then_processor)
10
+ when :upcase then Processors::Upcase.new(then_processor)
11
+ when :capitalize then Processors::Capitalize.new(then_processor)
12
+ when :swapcase then Processors::Swapcase.new(then_processor)
13
+ when :pluralize then Processors::Pluralize.new(then_processor)
14
+ when :singularize then Processors::Singularize.new(then_processor)
15
+ when :camelize then Processors::Camelize.new(then_processor)
16
+ when :titleize then Processors::Titleize.new(then_processor)
17
+ when :demodulize then Processors::Demodulize.new(then_processor)
18
+ when :deconstantize then Processors::Deconstantize.new(then_processor)
19
+ when :parameterize then Processors::Parameterize.new(then_processor)
20
+ when :underscore then Processors::Underscore.new(then_processor)
21
+ when :transforms then TransformSet.build(arguments, then_processor)
36
22
  else
37
- ::Leftovers::ProcessorBuilders::Each.each_or_self(arguments) do |argument|
23
+ Each.each_or_self(arguments) do |arg|
38
24
  case transform
39
- when :split
40
- ::Leftovers::Processors::Split.new(argument, then_processor)
41
- when :delete_before
42
- ::Leftovers::Processors::DeleteBefore.new(argument, then_processor)
43
- when :delete_before_last
44
- ::Leftovers::Processors::DeleteBeforeLast.new(argument, then_processor)
45
- when :delete_after
46
- ::Leftovers::Processors::DeleteAfter.new(argument, then_processor)
47
- when :delete_after_last
48
- ::Leftovers::Processors::DeleteAfterLast.new(argument, then_processor)
49
- when :add_prefix
50
- ::Leftovers::ProcessorBuilders::AddPrefix.build(argument, then_processor)
51
- when :add_suffix
52
- ::Leftovers::ProcessorBuilders::AddSuffix.build(argument, then_processor)
53
- when :delete_prefix
54
- ::Leftovers::Processors::DeletePrefix.new(argument, then_processor)
55
- when :delete_suffix
56
- ::Leftovers::Processors::DeleteSuffix.new(argument, then_processor)
25
+ when :split then Processors::Split.new(arg, then_processor)
26
+ when :delete_before then Processors::DeleteBefore.new(arg, then_processor)
27
+ when :delete_before_last then Processors::DeleteBeforeLast.new(arg, then_processor)
28
+ when :delete_after then Processors::DeleteAfter.new(arg, then_processor)
29
+ when :delete_after_last then Processors::DeleteAfterLast.new(arg, then_processor)
30
+ when :add_prefix then AddPrefix.build(arg, then_processor)
31
+ when :add_suffix then AddSuffix.build(arg, then_processor)
32
+ when :delete_prefix then Processors::DeletePrefix.new(arg, then_processor)
33
+ when :delete_suffix then Processors::DeleteSuffix.new(arg, then_processor)
57
34
  # :nocov:
58
- else raise Leftovers::UnexpectedCase, "Unhandled value #{transform.to_s.inspect}"
35
+ else raise UnexpectedCase, "Unhandled value #{transform.to_s.inspect}"
59
36
  # :nocov:
60
37
  end
61
38
  end
@@ -1,4 +1,4 @@
1
- # frozen-string-literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Leftovers
4
4
  module ProcessorBuilders
@@ -7,10 +7,9 @@ module Leftovers
7
7
  def build(transforms, next_transform)
8
8
  case transforms
9
9
  when ::Hash then build_from_hash(transforms, next_transform)
10
- when ::Symbol
11
- ::Leftovers::ProcessorBuilders::Transform.build(transforms, true, next_transform)
10
+ when ::Symbol then Transform.build(transforms, true, next_transform)
12
11
  # :nocov:
13
- else raise Leftovers::UnexpectedCase, "Unhandled value #{transforms.inspect}"
12
+ else raise UnexpectedCase, "Unhandled value #{transforms.inspect}"
14
13
  # :nocov:
15
14
  end
16
15
  end
@@ -19,9 +18,7 @@ module Leftovers
19
18
 
20
19
  def build_from_hash(transforms, next_transform)
21
20
  transforms.reverse_each do |(transform, transform_arg)|
22
- next_transform = ::Leftovers::ProcessorBuilders::Transform.build(
23
- transform, transform_arg, next_transform
24
- )
21
+ next_transform = Transform.build(transform, transform_arg, next_transform)
25
22
  end
26
23
 
27
24
  next_transform
@@ -1,4 +1,4 @@
1
- # frozen-string-literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Leftovers
4
4
  module ProcessorBuilders
@@ -7,10 +7,9 @@ module Leftovers
7
7
  def build(transforms, final_processor)
8
8
  each_builder(final_processor).each_or_self(transforms) do |transform|
9
9
  case transform
10
- when ::Hash, ::Symbol
11
- ::Leftovers::ProcessorBuilders::TransformChain.build(transform, final_processor)
10
+ when ::Hash, ::Symbol then TransformChain.build(transform, final_processor)
12
11
  # :nocov:
13
- else raise Leftovers::UnexpectedCase, "Unhandled value #{transform.inspect}"
12
+ else raise UnexpectedCase, "Unhandled value #{transform.inspect}"
14
13
  # :nocov:
15
14
  end
16
15
  end
@@ -19,10 +18,10 @@ module Leftovers
19
18
  private
20
19
 
21
20
  def each_builder(final_processor)
22
- if final_processor == ::Leftovers::Processors::AddDefinitionNode
23
- ::Leftovers::ProcessorBuilders::Each[:each_for_definition_set]
21
+ if final_processor == Processors::AddDefinitionNode
22
+ EachForDefinitionSet
24
23
  else
25
- ::Leftovers::ProcessorBuilders::Each[:each]
24
+ Each
26
25
  end
27
26
  end
28
27
  end
@@ -4,8 +4,8 @@ module Leftovers
4
4
  module ProcessorBuilders
5
5
  module Value
6
6
  def self.build(values, then_processor)
7
- ::Leftovers::ProcessorBuilders::Each.each_or_self(values) do |value|
8
- ::Leftovers::Processors::ReplaceValue.new(value, then_processor)
7
+ Each.each_or_self(values) do |value|
8
+ Processors::ReplaceValue.new(value, then_processor)
9
9
  end
10
10
  end
11
11
  end