leftovers 0.11.1 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +1 -0
- data/docs/Configuration.md +7 -0
- data/exe/leftovers +3 -1
- data/leftovers.gemspec +3 -4
- data/lib/config/activesupport.yml +1 -1
- data/lib/config/rspec.yml +21 -0
- data/lib/leftovers/ast/array_node.rb +2 -2
- data/lib/leftovers/ast/block_node.rb +1 -1
- data/lib/leftovers/ast/builder.rb +19 -18
- data/lib/leftovers/ast/casgn_node.rb +2 -2
- data/lib/leftovers/ast/const_node.rb +1 -1
- data/lib/leftovers/ast/def_node.rb +1 -1
- data/lib/leftovers/ast/defs_node.rb +1 -1
- data/lib/leftovers/ast/false_node.rb +1 -1
- data/lib/leftovers/ast/hash_node.rb +2 -2
- data/lib/leftovers/ast/module_node.rb +1 -1
- data/lib/leftovers/ast/nil_node.rb +1 -1
- data/lib/leftovers/ast/node.rb +13 -1
- data/lib/leftovers/ast/numeric_node.rb +1 -1
- data/lib/leftovers/ast/send_node.rb +16 -3
- data/lib/leftovers/ast/str_node.rb +1 -1
- data/lib/leftovers/ast/sym_node.rb +1 -1
- data/lib/leftovers/ast/true_node.rb +1 -1
- data/lib/leftovers/ast/var_node.rb +1 -1
- data/lib/leftovers/ast/vasgn_node.rb +2 -2
- data/lib/leftovers/ast.rb +2 -21
- data/lib/leftovers/autoloader.rb +36 -0
- data/lib/leftovers/cli.rb +64 -45
- data/lib/leftovers/collection.rb +66 -0
- data/lib/leftovers/collector.rb +17 -27
- data/lib/leftovers/config.rb +17 -5
- data/lib/leftovers/config_loader/attribute.rb +2 -2
- data/lib/leftovers/config_loader/bool_schema.rb +21 -0
- data/lib/leftovers/config_loader/document_schema.rb +2 -2
- data/lib/leftovers/config_loader/inherit_schema_attributes.rb +1 -1
- data/lib/leftovers/config_loader/node.rb +8 -8
- data/lib/leftovers/config_loader/regexp_schema.rb +1 -1
- data/lib/leftovers/config_loader/rule_pattern_schema.rb +1 -0
- data/lib/leftovers/config_loader/schema.rb +1 -1
- data/lib/leftovers/config_loader/string_enum_schema.rb +1 -1
- data/lib/leftovers/config_loader/value_or_array_schema.rb +1 -1
- data/lib/leftovers/config_loader.rb +8 -48
- data/lib/leftovers/definition.rb +4 -4
- data/lib/leftovers/definition_collection.rb +3 -3
- data/lib/leftovers/definition_node.rb +2 -2
- data/lib/leftovers/definition_node_set.rb +1 -1
- data/lib/leftovers/definition_set.rb +4 -4
- data/lib/leftovers/definition_to_add.rb +2 -2
- data/lib/leftovers/error.rb +6 -0
- data/lib/leftovers/file.rb +4 -4
- data/lib/leftovers/file_collector/comments_processor.rb +23 -18
- data/lib/leftovers/file_collector/node_processor/error.rb +16 -0
- data/lib/leftovers/file_collector/node_processor.rb +19 -2
- data/lib/leftovers/file_collector.rb +28 -20
- data/lib/leftovers/file_list.rb +4 -6
- data/lib/leftovers/matcher_builders/and.rb +5 -5
- data/lib/leftovers/matcher_builders/document.rb +1 -3
- data/lib/leftovers/matcher_builders/name.rb +4 -7
- data/lib/leftovers/matcher_builders/node.rb +21 -35
- data/lib/leftovers/matcher_builders/node_has_argument.rb +17 -29
- data/lib/leftovers/matcher_builders/node_has_block.rb +17 -0
- data/lib/leftovers/matcher_builders/node_has_keyword_argument.rb +7 -9
- data/lib/leftovers/matcher_builders/node_has_positional_argument.rb +10 -10
- data/lib/leftovers/matcher_builders/node_has_receiver.rb +6 -8
- data/lib/leftovers/matcher_builders/node_name.rb +3 -5
- data/lib/leftovers/matcher_builders/node_pair_key.rb +4 -4
- data/lib/leftovers/matcher_builders/node_pair_value.rb +4 -4
- data/lib/leftovers/matcher_builders/node_path.rb +3 -4
- data/lib/leftovers/matcher_builders/node_privacy.rb +3 -3
- data/lib/leftovers/matcher_builders/node_type.rb +18 -13
- data/lib/leftovers/matcher_builders/node_value.rb +18 -31
- data/lib/leftovers/matcher_builders/or.rb +10 -10
- data/lib/leftovers/matcher_builders/path.rb +3 -3
- data/lib/leftovers/matcher_builders/string_pattern.rb +2 -0
- data/lib/leftovers/matcher_builders/unless.rb +1 -3
- data/lib/leftovers/matcher_builders.rb +2 -22
- data/lib/leftovers/matchers/node_has_block.rb +13 -0
- data/lib/leftovers/matchers/node_scalar_value.rb +1 -1
- data/lib/leftovers/matchers.rb +2 -27
- data/lib/leftovers/merged_config.rb +16 -17
- data/lib/leftovers/parser.rb +1 -1
- data/lib/leftovers/precompile_error.rb +31 -0
- data/lib/leftovers/precompilers/haml.rb +23 -3
- data/lib/leftovers/precompilers/json.rb +1 -1
- data/lib/leftovers/precompilers/precompiler.rb +3 -3
- data/lib/leftovers/precompilers/slim.rb +1 -1
- data/lib/leftovers/precompilers/yaml/builder.rb +62 -0
- data/lib/leftovers/precompilers/yaml.rb +3 -56
- data/lib/leftovers/precompilers.rb +11 -16
- data/lib/leftovers/processor_builders/action.rb +15 -19
- data/lib/leftovers/processor_builders/add_prefix.rb +4 -6
- data/lib/leftovers/processor_builders/add_suffix.rb +4 -6
- data/lib/leftovers/processor_builders/argument.rb +10 -15
- data/lib/leftovers/processor_builders/dynamic.rb +12 -30
- data/lib/leftovers/processor_builders/each.rb +63 -76
- data/lib/leftovers/processor_builders/each_for_definition_set.rb +15 -0
- data/lib/leftovers/processor_builders/itself.rb +2 -4
- data/lib/leftovers/processor_builders/keyword.rb +4 -4
- data/lib/leftovers/processor_builders/keyword_argument.rb +4 -4
- data/lib/leftovers/processor_builders/receiver.rb +2 -4
- data/lib/leftovers/processor_builders/transform.rb +26 -49
- data/lib/leftovers/processor_builders/transform_chain.rb +4 -7
- data/lib/leftovers/processor_builders/transform_set.rb +6 -7
- data/lib/leftovers/processor_builders/value.rb +2 -2
- data/lib/leftovers/processor_builders.rb +2 -15
- data/lib/leftovers/processors/add_definition_node.rb +2 -2
- data/lib/leftovers/processors/camelize.rb +3 -3
- data/lib/leftovers/processors/deconstantize.rb +3 -3
- data/lib/leftovers/processors/demodulize.rb +3 -3
- data/lib/leftovers/processors/each_for_definition_set.rb +2 -2
- data/lib/leftovers/processors/eval.rb +1 -1
- data/lib/leftovers/processors/parameterize.rb +3 -3
- data/lib/leftovers/processors/placeholder.rb +1 -1
- data/lib/leftovers/processors/pluralize.rb +3 -3
- data/lib/leftovers/processors/set_default_privacy.rb +1 -1
- data/lib/leftovers/processors/set_privacy.rb +1 -1
- data/lib/leftovers/processors/singularize.rb +3 -3
- data/lib/leftovers/processors/titleize.rb +3 -3
- data/lib/leftovers/processors/underscore.rb +3 -3
- data/lib/leftovers/processors.rb +2 -44
- data/lib/leftovers/rake_task.rb +2 -2
- data/lib/leftovers/reporter.rb +44 -42
- data/lib/leftovers/runner.rb +40 -0
- data/lib/leftovers/todo_reporter.rb +96 -94
- data/lib/leftovers/unexpected_case.rb +8 -0
- data/lib/leftovers/version.rb +1 -1
- data/lib/leftovers.rb +23 -108
- metadata +15 -18
- data/lib/leftovers/matcher_builders/and_not.rb +0 -16
@@ -2,19 +2,14 @@
|
|
2
2
|
|
3
3
|
module Leftovers
|
4
4
|
module Precompilers
|
5
|
-
|
6
|
-
autoload(:Haml, "#{__dir__}/precompilers/haml")
|
7
|
-
autoload(:JSON, "#{__dir__}/precompilers/json")
|
8
|
-
autoload(:Precompiler, "#{__dir__}/precompilers/precompiler")
|
9
|
-
autoload(:Slim, "#{__dir__}/precompilers/slim")
|
10
|
-
autoload(:YAML, "#{__dir__}/precompilers/yaml")
|
5
|
+
include Autoloader
|
11
6
|
|
12
7
|
class << self
|
13
8
|
def build(precompilers)
|
14
9
|
precompilers.group_by { |p| build_precompiler(p[:format]) }.map do |format, precompiler|
|
15
10
|
Precompiler.new(
|
16
11
|
format,
|
17
|
-
|
12
|
+
MatcherBuilders::Path.build(precompiler.flat_map { |p| p[:paths] })
|
18
13
|
)
|
19
14
|
end
|
20
15
|
end
|
@@ -23,14 +18,14 @@ module Leftovers
|
|
23
18
|
|
24
19
|
def build_precompiler(format)
|
25
20
|
case format
|
26
|
-
when :erb then
|
27
|
-
when :haml then
|
28
|
-
when :json then
|
29
|
-
when :slim then
|
30
|
-
when :yaml then
|
31
|
-
when Hash then constantize_precompiler(format[:custom])
|
21
|
+
when :erb then ERB
|
22
|
+
when :haml then Haml
|
23
|
+
when :json then JSON
|
24
|
+
when :slim then Slim
|
25
|
+
when :yaml then YAML
|
26
|
+
when ::Hash then constantize_precompiler(format[:custom])
|
32
27
|
# :nocov:
|
33
|
-
else raise
|
28
|
+
else raise UnexpectedCase, "Unhandled value #{format}"
|
34
29
|
# :nocov:
|
35
30
|
end
|
36
31
|
end
|
@@ -38,9 +33,9 @@ module Leftovers
|
|
38
33
|
def constantize_precompiler(precompiler)
|
39
34
|
precompiler = "::#{precompiler}" unless precompiler.start_with?('::')
|
40
35
|
|
41
|
-
Object.const_get(precompiler, false)
|
36
|
+
::Object.const_get(precompiler, false)
|
42
37
|
rescue ::NameError
|
43
|
-
Leftovers.error <<~MESSAGE
|
38
|
+
::Leftovers.error <<~MESSAGE
|
44
39
|
Tried using #{precompiler}, but it wasn't available.
|
45
40
|
add its path to `requires:` in your .leftovers.yml
|
46
41
|
MESSAGE
|
@@ -5,13 +5,12 @@ module Leftovers
|
|
5
5
|
module Action
|
6
6
|
class << self
|
7
7
|
def build(patterns, final_processor)
|
8
|
-
|
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
|
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 =
|
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
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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 =
|
69
|
-
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 =
|
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
|
-
|
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
|
10
|
+
when ::String then Processors::AddPrefix.new(argument, then_processor)
|
11
11
|
# :nocov:
|
12
|
-
else raise
|
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 =
|
21
|
-
|
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
|
10
|
+
when ::String then Processors::AddSuffix.new(argument, then_processor)
|
11
11
|
# :nocov:
|
12
|
-
else raise
|
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 =
|
21
|
-
|
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
|
-
|
8
|
+
Each.each_or_self(patterns) do |pat|
|
9
9
|
case pat
|
10
|
-
when ::Integer then
|
11
|
-
when '*' then
|
12
|
-
when '**' then
|
13
|
-
when /\A(\d+)\+\z/
|
14
|
-
|
15
|
-
when ::
|
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
|
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
|
-
|
30
|
-
|
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
|
-
#
|
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
|
-
|
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 =
|
20
|
+
matcher = MatcherBuilders::Node.build_from_hash(**matcher_rules)
|
21
21
|
|
22
|
-
processor =
|
23
|
-
|
24
|
-
|
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
|
-
|
27
|
+
Action.build(eval, Processors::Eval)
|
28
28
|
])
|
29
29
|
|
30
|
-
|
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
|
-
|
53
|
-
processor =
|
54
|
-
|
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
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
24
|
-
|
25
|
-
end
|
15
|
+
def build(processors)
|
16
|
+
processors = compact(processors)
|
26
17
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
36
|
-
processors = compact(processors)
|
27
|
+
private
|
37
28
|
|
38
|
-
|
39
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
46
|
+
def flatten_matchers(processor)
|
47
|
+
then_processors = flatten(processor.then_processor)
|
48
|
+
return [processor] if then_processors.length <= 1
|
63
49
|
|
64
|
-
|
65
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
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
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
70
|
+
group.first.class.new(matcher, build(group.map(&:then_processor)))
|
71
|
+
end
|
85
72
|
end
|
86
|
-
end
|
87
73
|
|
88
|
-
|
89
|
-
|
74
|
+
def compact_matchers(matchers)
|
75
|
+
return [] unless matchers
|
90
76
|
|
91
|
-
|
92
|
-
|
93
|
-
|
77
|
+
matchers = compact_matchers_with_same_processor(matchers)
|
78
|
+
compact_matchers_with_same_matcher(matchers)
|
79
|
+
end
|
94
80
|
|
95
|
-
|
96
|
-
|
81
|
+
def compact(processors)
|
82
|
+
processors = flatten(processors).compact
|
97
83
|
|
98
|
-
|
84
|
+
return processors if processors.length <= 1
|
99
85
|
|
100
|
-
|
86
|
+
group = processors.group_by(&:class)
|
101
87
|
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|
@@ -3,10 +3,8 @@
|
|
3
3
|
module Leftovers
|
4
4
|
module ProcessorBuilders
|
5
5
|
module Itself
|
6
|
-
def self.build(
|
7
|
-
|
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
|
-
|
13
|
-
|
12
|
+
Processors::MatchCurrentNode.new(
|
13
|
+
MatcherBuilders::NodeName.build(value), then_processor
|
14
14
|
)
|
15
15
|
# :nocov:
|
16
|
-
else raise
|
16
|
+
else raise UnexpectedCase, "Unhandled value #{value.inspect}"
|
17
17
|
# :nocov:
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
Processors::EachKeyword.new(then_processor)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
#
|
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
|
-
|
8
|
-
|
9
|
-
|
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(
|
7
|
-
|
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
|
-
#
|
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
|
-
|
10
|
-
when :
|
11
|
-
|
12
|
-
when :
|
13
|
-
|
14
|
-
when :
|
15
|
-
|
16
|
-
when :
|
17
|
-
|
18
|
-
when :
|
19
|
-
|
20
|
-
when :
|
21
|
-
|
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
|
-
|
23
|
+
Each.each_or_self(arguments) do |arg|
|
38
24
|
case transform
|
39
|
-
when :split
|
40
|
-
|
41
|
-
when :
|
42
|
-
|
43
|
-
when :
|
44
|
-
|
45
|
-
when :
|
46
|
-
|
47
|
-
when :
|
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
|
35
|
+
else raise UnexpectedCase, "Unhandled value #{transform.to_s.inspect}"
|
59
36
|
# :nocov:
|
60
37
|
end
|
61
38
|
end
|