leftovers 0.7.0 → 0.8.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 +13 -0
- data/README.md +1 -0
- data/docs/Configuration.md +20 -57
- data/docs/Custom-Precompilers.md +38 -0
- data/lib/config/actionpack.yml +5 -3
- data/lib/config/haml.yml +4 -2
- data/lib/config/ruby.yml +4 -15
- data/lib/config/slim.yml +4 -2
- data/lib/leftovers/cli.rb +5 -0
- data/lib/leftovers/collector.rb +2 -1
- data/lib/leftovers/config.rb +2 -18
- data/lib/leftovers/config_loader/argument_position_schema.rb +2 -2
- data/lib/leftovers/config_loader/attribute.rb +36 -10
- data/lib/leftovers/config_loader/built_in_precompiler_schema.rb +13 -0
- data/lib/leftovers/config_loader/document_schema.rb +32 -5
- data/lib/leftovers/config_loader/has_argument_schema.rb +2 -2
- data/lib/leftovers/config_loader/has_value_schema.rb +2 -2
- data/lib/leftovers/config_loader/inherit_schema_attributes.rb +22 -0
- data/lib/leftovers/config_loader/keep_test_only_schema.rb +2 -2
- data/lib/leftovers/config_loader/object_schema.rb +33 -105
- data/lib/leftovers/config_loader/precompile_schema.rb +12 -0
- data/lib/leftovers/config_loader/precompiler_schema.rb +11 -0
- data/lib/leftovers/config_loader/privacy_processor_schema.rb +0 -2
- data/lib/leftovers/config_loader/require_schema.rb +3 -3
- data/lib/leftovers/config_loader/schema.rb +2 -0
- data/lib/leftovers/config_loader/string_pattern_schema.rb +2 -2
- data/lib/leftovers/config_loader/string_value_processor_schema.rb +2 -2
- data/lib/leftovers/config_loader/transform_schema.rb +4 -6
- data/lib/leftovers/config_loader/value_matcher_schema.rb +2 -2
- data/lib/leftovers/config_loader/value_or_array_schema.rb +5 -3
- data/lib/leftovers/config_loader/value_or_object_schema.rb +40 -0
- data/lib/leftovers/config_loader/value_processor_schema.rb +2 -2
- data/lib/leftovers/config_loader.rb +5 -1
- data/lib/leftovers/file.rb +7 -53
- data/lib/leftovers/file_collector/comments_processor.rb +57 -0
- data/lib/leftovers/file_collector/node_processor.rb +131 -0
- data/lib/leftovers/file_collector.rb +42 -203
- data/lib/leftovers/matcher_builders/and_not.rb +7 -5
- data/lib/leftovers/matcher_builders/name.rb +18 -17
- data/lib/leftovers/matcher_builders/node.rb +48 -34
- data/lib/leftovers/matcher_builders/node_has_argument.rb +48 -52
- data/lib/leftovers/matcher_builders/node_has_keyword_argument.rb +13 -10
- data/lib/leftovers/matcher_builders/node_has_positional_argument.rb +29 -15
- data/lib/leftovers/matcher_builders/node_type.rb +1 -1
- data/lib/leftovers/matcher_builders/node_value.rb +27 -22
- data/lib/leftovers/matcher_builders/or.rb +50 -50
- data/lib/leftovers/matcher_builders/string_pattern.rb +1 -1
- data/lib/leftovers/merged_config.rb +3 -23
- data/lib/leftovers/precompilers/erb.rb +22 -0
- data/lib/leftovers/precompilers/haml.rb +15 -0
- data/lib/leftovers/precompilers/json.rb +27 -0
- data/lib/leftovers/precompilers/precompiler.rb +28 -0
- data/lib/leftovers/precompilers/slim.rb +15 -0
- data/lib/leftovers/precompilers/yaml.rb +75 -0
- data/lib/leftovers/precompilers.rb +50 -0
- data/lib/leftovers/processor_builders/action.rb +48 -39
- data/lib/leftovers/processor_builders/add_prefix.rb +1 -1
- data/lib/leftovers/processor_builders/add_suffix.rb +1 -1
- data/lib/leftovers/processor_builders/argument.rb +8 -11
- data/lib/leftovers/processor_builders/dynamic.rb +5 -5
- data/lib/leftovers/processor_builders/each.rb +2 -2
- data/lib/leftovers/processor_builders/each_action.rb +33 -33
- data/lib/leftovers/processor_builders/each_dynamic.rb +4 -8
- data/lib/leftovers/processor_builders/each_for_definition_set.rb +25 -21
- data/lib/leftovers/processor_builders/keyword.rb +3 -4
- data/lib/leftovers/processor_builders/transform.rb +2 -2
- data/lib/leftovers/processor_builders/transform_chain.rb +16 -8
- data/lib/leftovers/processor_builders/transform_set.rb +32 -28
- data/lib/leftovers/rake_task.rb +1 -1
- data/lib/leftovers/value_processors/add_dynamic_prefix.rb +3 -10
- data/lib/leftovers/value_processors/add_dynamic_suffix.rb +3 -10
- data/lib/leftovers/value_processors/each.rb +1 -1
- data/lib/leftovers/value_processors/each_for_definition_set.rb +2 -5
- data/lib/leftovers/value_processors/each_keyword.rb +1 -1
- data/lib/leftovers/value_processors/each_keyword_argument.rb +1 -1
- data/lib/leftovers/value_processors/each_positional_argument.rb +2 -1
- data/lib/leftovers/value_processors/keyword.rb +3 -7
- data/lib/leftovers/value_processors/keyword_argument.rb +2 -6
- data/lib/leftovers/value_processors/split.rb +2 -2
- data/lib/leftovers/version.rb +1 -1
- data/lib/leftovers.rb +41 -6
- metadata +17 -7
- data/lib/leftovers/erb.rb +0 -20
- data/lib/leftovers/haml.rb +0 -21
- data/lib/leftovers/json.rb +0 -28
- data/lib/leftovers/slim.rb +0 -21
- data/lib/leftovers/yaml.rb +0 -73
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
module Precompilers
|
5
|
+
autoload(:ERB, "#{__dir__}/precompilers/erb")
|
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")
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def build(precompilers)
|
14
|
+
precompilers.group_by { |p| build_precompiler(p[:format]) }.map do |format, precompiler|
|
15
|
+
Precompiler.new(
|
16
|
+
format,
|
17
|
+
Leftovers::MatcherBuilders::Path.build(precompiler.flat_map { |p| p[:paths] })
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def build_precompiler(format)
|
25
|
+
case format
|
26
|
+
when 'erb' then ::Leftovers::Precompilers::ERB
|
27
|
+
when 'haml' then ::Leftovers::Precompilers::Haml
|
28
|
+
when 'json' then ::Leftovers::Precompilers::JSON
|
29
|
+
when 'slim' then ::Leftovers::Precompilers::Slim
|
30
|
+
when 'yaml' then ::Leftovers::Precompilers::YAML
|
31
|
+
when Hash then constantize_precompiler(format[:custom])
|
32
|
+
# :nocov:
|
33
|
+
else raise Leftovers::UnexpectedCase, "Unhandled value #{format}"
|
34
|
+
# :nocov:
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def constantize_precompiler(precompiler)
|
39
|
+
precompiler = "::#{precompiler}" unless precompiler.start_with?('::')
|
40
|
+
|
41
|
+
Object.const_get(precompiler, false)
|
42
|
+
rescue ::NameError
|
43
|
+
Leftovers.error <<~MESSAGE
|
44
|
+
Tried using #{precompiler}, but it wasn't available.
|
45
|
+
add its path to `requires:` in your .leftovers.yml
|
46
|
+
MESSAGE
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -3,60 +3,69 @@
|
|
3
3
|
module Leftovers
|
4
4
|
module ProcessorBuilders
|
5
5
|
module Action
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
::
|
11
|
-
|
12
|
-
build_from_hash_value(action, **pattern)
|
13
|
-
# :nocov:
|
14
|
-
else raise
|
6
|
+
class << self
|
7
|
+
def build(patterns, action)
|
8
|
+
::Leftovers::ProcessorBuilders::EachAction.each_or_self(patterns) do |pattern|
|
9
|
+
case pattern
|
10
|
+
when ::String, ::Integer
|
11
|
+
::Leftovers::ProcessorBuilders::Argument.build(pattern, final_transformer(action))
|
12
|
+
when ::Hash then build_from_hash_value(action, **pattern)
|
15
13
|
# :nocov:
|
14
|
+
else raise Leftovers::UnexpectedCase, "Unhandled value #{pattern.inspect}"
|
15
|
+
# :nocov:
|
16
|
+
end
|
16
17
|
end
|
17
18
|
end
|
18
|
-
end
|
19
19
|
|
20
|
-
|
21
|
-
::Leftovers::ProcessorBuilders::TransformSet.build_final(action)
|
22
|
-
end
|
20
|
+
private
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
nested: nil,
|
31
|
-
recursive: nil,
|
32
|
-
**transform_args
|
33
|
-
)
|
34
|
-
transformer = ::Leftovers::ProcessorBuilders::TransformSet.build(transform_args, action)
|
35
|
-
if nested
|
36
|
-
transformer = ::Leftovers::ProcessorBuilders::Each.build([
|
22
|
+
def final_transformer(action)
|
23
|
+
::Leftovers::ProcessorBuilders::TransformSet.build_final(action)
|
24
|
+
end
|
25
|
+
|
26
|
+
def build_nested(nested, transformer, action)
|
27
|
+
::Leftovers::ProcessorBuilders::Each.build([
|
37
28
|
::Leftovers::ProcessorBuilders::Action.build(nested, action),
|
38
29
|
transformer
|
39
30
|
])
|
40
31
|
end
|
41
32
|
|
42
|
-
|
33
|
+
def build_processor(arguments, keywords, itself, value, transformer)
|
34
|
+
::Leftovers::ProcessorBuilders::EachAction.build([
|
35
|
+
::Leftovers::ProcessorBuilders::Argument.build(arguments, transformer),
|
36
|
+
::Leftovers::ProcessorBuilders::Keyword.build(keywords, transformer),
|
37
|
+
::Leftovers::ProcessorBuilders::Itself.build(itself, transformer),
|
38
|
+
::Leftovers::ProcessorBuilders::Value.build(value, transformer)
|
39
|
+
])
|
40
|
+
end
|
41
|
+
|
42
|
+
def build_recursive(transformer)
|
43
43
|
placeholder = ::Leftovers::ValueProcessors::Placeholder.new
|
44
|
-
transformer = ::Leftovers::ProcessorBuilders::Each.build(
|
45
|
-
|
46
|
-
|
44
|
+
transformer = ::Leftovers::ProcessorBuilders::Each.build([placeholder, transformer])
|
45
|
+
|
46
|
+
[placeholder, transformer]
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
def build_from_hash_value( # rubocop:disable Metrics/ParameterLists
|
50
|
+
action,
|
51
|
+
arguments: nil,
|
52
|
+
keywords: nil,
|
53
|
+
itself: nil,
|
54
|
+
value: nil,
|
55
|
+
nested: nil,
|
56
|
+
recursive: nil,
|
57
|
+
**transform_args
|
58
|
+
)
|
59
|
+
transformer = ::Leftovers::ProcessorBuilders::TransformSet.build(transform_args, action)
|
60
|
+
transformer = build_nested(nested, transformer, action) if nested
|
61
|
+
placeholder, transformer = build_recursive(transformer) if recursive
|
62
|
+
processor = build_processor(arguments, keywords, itself, value, transformer)
|
55
63
|
|
56
|
-
|
64
|
+
return processor unless recursive
|
57
65
|
|
58
|
-
|
59
|
-
|
66
|
+
placeholder.processor = processor
|
67
|
+
placeholder
|
68
|
+
end
|
60
69
|
end
|
61
70
|
end
|
62
71
|
end
|
@@ -3,19 +3,16 @@
|
|
3
3
|
module Leftovers
|
4
4
|
module ProcessorBuilders
|
5
5
|
module Argument
|
6
|
-
def self.build(patterns,
|
7
|
-
::Leftovers::ProcessorBuilders::EachAction.each_or_self(patterns) do |
|
8
|
-
case
|
9
|
-
when ::Integer
|
10
|
-
|
11
|
-
when '
|
12
|
-
::Leftovers::ValueProcessors::EachPositionalArgument.new(then_processor)
|
13
|
-
when '**'
|
14
|
-
::Leftovers::ValueProcessors::EachKeywordArgument.new(then_processor)
|
6
|
+
def self.build(patterns, processor)
|
7
|
+
::Leftovers::ProcessorBuilders::EachAction.each_or_self(patterns) do |pat|
|
8
|
+
case pat
|
9
|
+
when ::Integer then ::Leftovers::ValueProcessors::PositionalArgument.new(pat, processor)
|
10
|
+
when '*' then ::Leftovers::ValueProcessors::EachPositionalArgument.new(processor)
|
11
|
+
when '**' then ::Leftovers::ValueProcessors::EachKeywordArgument.new(processor)
|
15
12
|
when ::String, ::Hash
|
16
|
-
::Leftovers::ProcessorBuilders::KeywordArgument.build(
|
13
|
+
::Leftovers::ProcessorBuilders::KeywordArgument.build(pat, processor)
|
17
14
|
# :nocov:
|
18
|
-
else raise
|
15
|
+
else raise Leftovers::UnexpectedCase, "Unhandled value #{pat.inspect}"
|
19
16
|
# :nocov:
|
20
17
|
end
|
21
18
|
end
|
@@ -17,8 +17,11 @@ module Leftovers
|
|
17
17
|
)
|
18
18
|
matcher = ::Leftovers::MatcherBuilders::Node.build(**matcher_rules)
|
19
19
|
|
20
|
+
call_action = build_action(call, return_type: :sym)
|
21
|
+
define_action = build_action(define, return_type: :definition_node)
|
22
|
+
|
20
23
|
::Leftovers::ProcessorBuilders::EachDynamic.build([
|
21
|
-
build_call_define_processor(matcher,
|
24
|
+
build_call_define_processor(matcher, call_action, define_action),
|
22
25
|
build_set_privacy_processor(matcher, set_privacy),
|
23
26
|
build_set_default_privacy_processor(matcher, set_default_privacy)
|
24
27
|
])
|
@@ -41,10 +44,7 @@ module Leftovers
|
|
41
44
|
::Leftovers::DynamicProcessors::SetDefaultPrivacy.new(matcher, set_default_privacy)
|
42
45
|
end
|
43
46
|
|
44
|
-
def build_call_define_processor(matcher,
|
45
|
-
call_action = build_action(call, return_type: :sym)
|
46
|
-
define_action = build_action(define, return_type: :definition_node)
|
47
|
-
|
47
|
+
def build_call_define_processor(matcher, call_action, define_action)
|
48
48
|
if call_action && define_action
|
49
49
|
# this nonsense saves a method call and array instantiation per method
|
50
50
|
::Leftovers::DynamicProcessors::CallDefinition.new(matcher, call_action, define_action)
|
@@ -6,7 +6,7 @@ module Leftovers
|
|
6
6
|
def self.each_or_self(value, &block)
|
7
7
|
case value
|
8
8
|
# :nocov:
|
9
|
-
when nil then raise
|
9
|
+
when nil then raise Leftovers::UnexpectedCase, "Unhandled value #{value.inspect}"
|
10
10
|
# :nocov:
|
11
11
|
when Array then build(value.map(&block))
|
12
12
|
else build([yield(value)])
|
@@ -18,7 +18,7 @@ module Leftovers
|
|
18
18
|
|
19
19
|
case processors.length
|
20
20
|
# :nocov:
|
21
|
-
when 0 then raise
|
21
|
+
when 0 then raise Leftovers::UnexpectedCase, "Unhandled value #{processors.inspect}"
|
22
22
|
# :nocov:
|
23
23
|
when 1 then processors.first
|
24
24
|
else ::Leftovers::ValueProcessors::Each.new(processors)
|
@@ -3,48 +3,48 @@
|
|
3
3
|
module Leftovers
|
4
4
|
module ProcessorBuilders
|
5
5
|
module EachAction
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
11
13
|
end
|
12
|
-
end
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
def build(processors)
|
16
|
+
processors = compact(processors)
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
case processors.length
|
19
|
+
# :nocov:
|
20
|
+
when 0 then raise Leftovers::UnexpectedCase, "Unhandled value #{processors.inspect}"
|
21
|
+
# :nocov:
|
22
|
+
when 1 then processors.first
|
23
|
+
else ::Leftovers::ValueProcessors::Each.new(processors)
|
24
|
+
end
|
23
25
|
end
|
24
|
-
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
value
|
27
|
+
private
|
28
|
+
|
29
|
+
def flatten(value)
|
30
|
+
case value
|
31
|
+
when ::Leftovers::ValueProcessors::Each
|
32
|
+
value.processors.flat_map { |v| flatten(v) }
|
33
|
+
when Array
|
34
|
+
value.flat_map { |v| flatten(v) }
|
35
|
+
else
|
36
|
+
value
|
37
|
+
end
|
38
38
|
end
|
39
|
-
end
|
40
39
|
|
41
|
-
|
42
|
-
|
40
|
+
def compact(processors)
|
41
|
+
return processors if processors.length <= 1
|
43
42
|
|
44
|
-
|
45
|
-
|
43
|
+
processors = flatten(processors)
|
44
|
+
processors.compact!
|
46
45
|
|
47
|
-
|
46
|
+
processors
|
47
|
+
end
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -16,23 +16,19 @@ module Leftovers
|
|
16
16
|
|
17
17
|
case processors.length
|
18
18
|
# :nocov:
|
19
|
-
when 0 then raise
|
19
|
+
when 0 then raise Leftovers::UnexpectedCase, "Unhandled value #{processors.inspect}"
|
20
20
|
# :nocov:
|
21
21
|
when 1 then processors.first
|
22
22
|
else ::Leftovers::DynamicProcessors::Each.new(processors)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
def self.flatten(value)
|
26
|
+
def self.flatten(value)
|
27
27
|
case value
|
28
28
|
when ::Leftovers::DynamicProcessors::Each
|
29
|
-
|
30
|
-
ret.flatten!(1)
|
31
|
-
ret
|
29
|
+
value.processors.flat_map { |v| flatten(v) }
|
32
30
|
when Array
|
33
|
-
|
34
|
-
ret.flatten!(1)
|
35
|
-
ret
|
31
|
+
value.flat_map { |v| flatten(v) }
|
36
32
|
else
|
37
33
|
value
|
38
34
|
end
|
@@ -3,33 +3,37 @@
|
|
3
3
|
module Leftovers
|
4
4
|
module ProcessorBuilders
|
5
5
|
module EachForDefinitionSet
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
class << self
|
7
|
+
def each_or_self(value, &block)
|
8
|
+
case value
|
9
|
+
# :nocov:
|
10
|
+
when nil then raise Leftovers::UnexpectedCase, "Unhandled value #{value.inspect}"
|
11
|
+
# :nocov:
|
12
|
+
when Array then build(value.map(&block))
|
13
|
+
else build([yield(value)])
|
14
|
+
end
|
13
15
|
end
|
14
|
-
end
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
def build(processors)
|
18
|
+
processors = compact(processors)
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
case processors.length
|
21
|
+
# :nocov:
|
22
|
+
when 0 then raise Leftovers::UnexpectedCase, "Unhandled value #{processors.inspect}"
|
23
|
+
# :nocov:
|
24
|
+
when 1 then processors.first
|
25
|
+
else ::Leftovers::ValueProcessors::EachForDefinitionSet.new(processors)
|
26
|
+
end
|
25
27
|
end
|
26
|
-
end
|
27
28
|
|
28
|
-
|
29
|
-
processors.flatten!
|
30
|
-
processors.compact!
|
29
|
+
private
|
31
30
|
|
32
|
-
processors
|
31
|
+
def compact(processors)
|
32
|
+
processors.flatten!
|
33
|
+
processors.compact!
|
34
|
+
|
35
|
+
processors
|
36
|
+
end
|
33
37
|
end
|
34
38
|
end
|
35
39
|
end
|
@@ -3,19 +3,18 @@
|
|
3
3
|
module Leftovers
|
4
4
|
module ProcessorBuilders
|
5
5
|
module Keyword
|
6
|
-
def self.build(value, then_processor)
|
6
|
+
def self.build(value, then_processor)
|
7
7
|
return unless value && then_processor
|
8
8
|
|
9
9
|
case value
|
10
|
-
when true, '**'
|
11
|
-
::Leftovers::ValueProcessors::EachKeyword.new(then_processor)
|
10
|
+
when true, '**' then ::Leftovers::ValueProcessors::EachKeyword.new(then_processor)
|
12
11
|
when ::String, ::Hash, ::Array
|
13
12
|
::Leftovers::ValueProcessors::Keyword.new(
|
14
13
|
::Leftovers::MatcherBuilders::NodePairName.build(value),
|
15
14
|
then_processor
|
16
15
|
)
|
17
16
|
# :nocov:
|
18
|
-
else raise
|
17
|
+
else raise Leftovers::UnexpectedCase, "Unhandled value #{value.inspect}"
|
19
18
|
# :nocov:
|
20
19
|
end
|
21
20
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Leftovers
|
4
4
|
module ProcessorBuilders
|
5
5
|
module Transform
|
6
|
-
def self.build(transform, argument, then_processor) # rubocop:disable Metrics
|
6
|
+
def self.build(transform, argument, then_processor) # rubocop:disable Metrics
|
7
7
|
case transform.to_s
|
8
8
|
when 'original', nil
|
9
9
|
then_processor
|
@@ -46,7 +46,7 @@ module Leftovers
|
|
46
46
|
when 'delete_suffix'
|
47
47
|
::Leftovers::ValueProcessors::DeleteSuffix.new(argument, then_processor)
|
48
48
|
# :nocov:
|
49
|
-
else raise
|
49
|
+
else raise Leftovers::UnexpectedCase, "Unhandled value #{transform.to_s.inspect}"
|
50
50
|
# :nocov:
|
51
51
|
end
|
52
52
|
end
|
@@ -3,20 +3,28 @@
|
|
3
3
|
module Leftovers
|
4
4
|
module ProcessorBuilders
|
5
5
|
module TransformChain
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
class << self
|
7
|
+
def build(transforms, next_transform)
|
8
|
+
case transforms
|
9
|
+
when ::Hash then build_from_hash(transforms, next_transform)
|
10
|
+
when ::String
|
11
|
+
::Leftovers::ProcessorBuilders::Transform.build(transforms, true, next_transform)
|
12
|
+
# :nocov:
|
13
|
+
else raise Leftovers::UnexpectedCase, "Unhandled value #{transforms.inspect}"
|
14
|
+
# :nocov:
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def build_from_hash(transforms, next_transform)
|
9
21
|
transforms.reverse_each do |(transform, transform_arg)|
|
10
22
|
next_transform = ::Leftovers::ProcessorBuilders::Transform.build(
|
11
23
|
transform, transform_arg, next_transform
|
12
24
|
)
|
13
25
|
end
|
26
|
+
|
14
27
|
next_transform
|
15
|
-
when ::String
|
16
|
-
::Leftovers::ProcessorBuilders::Transform.build(transforms, true, next_transform)
|
17
|
-
# :nocov:
|
18
|
-
else raise
|
19
|
-
# :nocov:
|
20
28
|
end
|
21
29
|
end
|
22
30
|
end
|
@@ -3,43 +3,47 @@
|
|
3
3
|
module Leftovers
|
4
4
|
module ProcessorBuilders
|
5
5
|
module TransformSet
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
class << self
|
7
|
+
def build(transforms, action)
|
8
|
+
each_builder(action).each_or_self(transforms) do |transform|
|
9
|
+
case transform
|
10
|
+
when ::Hash
|
11
|
+
next build(transform[:transforms], action) if transform[:transforms]
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
# :nocov:
|
16
|
-
else raise
|
13
|
+
::Leftovers::ProcessorBuilders::TransformChain.build(transform, build_final(action))
|
14
|
+
when ::String
|
15
|
+
::Leftovers::ProcessorBuilders::TransformChain.build(transform, build_final(action))
|
17
16
|
# :nocov:
|
17
|
+
else raise Leftovers::UnexpectedCase, "Unhandled value #{transform.inspect}"
|
18
|
+
# :nocov:
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
20
|
-
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
# :nocov:
|
29
|
-
else raise "Unknown action #{action}"
|
23
|
+
def build_final(action)
|
24
|
+
case action
|
25
|
+
when :sym
|
26
|
+
::Leftovers::ValueProcessors::ReturnSym
|
27
|
+
when :definition_node
|
28
|
+
::Leftovers::ValueProcessors::ReturnDefinitionNode
|
30
29
|
# :nocov:
|
30
|
+
else raise Leftovers::UnexpectedCase, "Unhandled value #{action.inspect}"
|
31
|
+
# :nocov:
|
32
|
+
end
|
31
33
|
end
|
32
|
-
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
35
|
+
private
|
36
|
+
|
37
|
+
def each_builder(action)
|
38
|
+
case action
|
39
|
+
when :sym
|
40
|
+
::Leftovers::ProcessorBuilders::Each
|
41
|
+
when :definition_node
|
42
|
+
::Leftovers::ProcessorBuilders::EachForDefinitionSet
|
42
43
|
# :nocov:
|
44
|
+
else raise Leftovers::UnexpectedCase, "Unhandled value #{action.inspect}"
|
45
|
+
# :nocov:
|
46
|
+
end
|
43
47
|
end
|
44
48
|
end
|
45
49
|
end
|
data/lib/leftovers/rake_task.rb
CHANGED
@@ -10,20 +10,13 @@ module Leftovers
|
|
10
10
|
freeze
|
11
11
|
end
|
12
12
|
|
13
|
-
def process(str, node, method_node)
|
13
|
+
def process(str, node, method_node)
|
14
14
|
return unless str
|
15
15
|
|
16
16
|
prefixes = @prefix_processor.process(nil, method_node, method_node)
|
17
|
-
if prefixes.is_a?(Array)
|
18
|
-
prefixes.flatten!
|
19
|
-
prefixes.compact!
|
20
|
-
prefixes.uniq!
|
21
17
|
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
else
|
26
|
-
@then_processor.process("#{prefixes}#{str}", node, method_node)
|
18
|
+
Leftovers.map_or_self(prefixes) do |prefix|
|
19
|
+
@then_processor.process("#{prefix}#{str}", node, method_node)
|
27
20
|
end
|
28
21
|
end
|
29
22
|
end
|
@@ -10,20 +10,13 @@ module Leftovers
|
|
10
10
|
freeze
|
11
11
|
end
|
12
12
|
|
13
|
-
def process(str, node, method_node)
|
13
|
+
def process(str, node, method_node)
|
14
14
|
return unless str
|
15
15
|
|
16
16
|
suffixes = @suffix_processor.process(nil, method_node, method_node)
|
17
|
-
if suffixes.is_a?(Array)
|
18
|
-
suffixes.flatten!
|
19
|
-
suffixes.compact!
|
20
|
-
suffixes.uniq!
|
21
17
|
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
else
|
26
|
-
@then_processor.process("#{str}#{suffixes}", node, method_node)
|
18
|
+
Leftovers.map_or_self(suffixes) do |suffix|
|
19
|
+
@then_processor.process("#{str}#{suffix}", node, method_node)
|
27
20
|
end
|
28
21
|
end
|
29
22
|
end
|