leftovers 0.5.5 → 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 +40 -2
- data/README.md +22 -1
- data/docs/Configuration.md +173 -42
- data/docs/Custom-Precompilers.md +38 -0
- data/leftovers.gemspec +8 -5
- data/lib/config/actionmailer.yml +11 -11
- data/lib/config/actionpack.yml +5 -3
- data/lib/config/activesupport.yml +1 -1
- data/lib/config/haml.yml +4 -2
- data/lib/config/rails.yml +1 -1
- data/lib/config/railties.yml +11 -0
- data/lib/config/ruby.yml +76 -8
- data/lib/config/slim.yml +4 -2
- data/lib/leftovers/ast/node.rb +16 -11
- data/lib/leftovers/cli.rb +5 -0
- data/lib/leftovers/collector.rb +5 -2
- data/lib/leftovers/config.rb +3 -38
- data/lib/leftovers/config_loader/argument_position_schema.rb +11 -0
- data/lib/leftovers/config_loader/argumentless_transform_schema.rb +21 -0
- data/lib/leftovers/config_loader/attribute.rb +56 -0
- data/lib/leftovers/config_loader/built_in_precompiler_schema.rb +13 -0
- data/lib/leftovers/config_loader/document_schema.rb +48 -0
- data/lib/leftovers/config_loader/dynamic_schema.rb +17 -0
- data/lib/leftovers/config_loader/has_argument_schema.rb +13 -0
- data/lib/leftovers/config_loader/has_value_schema.rb +18 -0
- data/lib/leftovers/config_loader/inherit_schema_attributes.rb +22 -0
- data/lib/leftovers/config_loader/keep_test_only_schema.rb +13 -0
- data/lib/leftovers/config_loader/node.rb +106 -0
- data/lib/leftovers/config_loader/object_schema.rb +117 -0
- 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 +10 -0
- data/lib/leftovers/config_loader/privacy_schema.rb +15 -0
- data/lib/leftovers/config_loader/require_schema.rb +11 -0
- data/lib/leftovers/config_loader/rule_pattern_schema.rb +18 -0
- data/lib/leftovers/config_loader/scalar_argument_schema.rb +14 -0
- data/lib/leftovers/config_loader/scalar_value_schema.rb +14 -0
- data/lib/leftovers/config_loader/schema.rb +23 -0
- data/lib/leftovers/config_loader/string_enum_schema.rb +62 -0
- data/lib/leftovers/config_loader/string_pattern_schema.rb +14 -0
- data/lib/leftovers/config_loader/string_schema.rb +14 -0
- data/lib/leftovers/config_loader/string_value_processor_schema.rb +11 -0
- data/lib/leftovers/config_loader/suggester.rb +22 -0
- data/lib/leftovers/config_loader/transform_schema.rb +26 -0
- data/lib/leftovers/config_loader/true_schema.rb +18 -0
- data/lib/leftovers/config_loader/value_matcher_schema.rb +18 -0
- data/lib/leftovers/config_loader/value_or_array_schema.rb +66 -0
- data/lib/leftovers/config_loader/value_or_object_schema.rb +40 -0
- data/lib/leftovers/config_loader/value_processor_schema.rb +14 -0
- data/lib/leftovers/config_loader/value_type_schema.rb +17 -0
- data/lib/leftovers/config_loader.rb +86 -0
- data/lib/leftovers/definition.rb +1 -1
- data/lib/leftovers/definition_node.rb +6 -17
- data/lib/leftovers/definition_node_set.rb +11 -0
- data/lib/leftovers/definition_to_add.rb +31 -0
- data/lib/leftovers/dynamic_processors/call.rb +4 -7
- data/lib/leftovers/dynamic_processors/call_definition.rb +14 -11
- data/lib/leftovers/dynamic_processors/definition.rb +8 -7
- data/lib/leftovers/dynamic_processors/set_default_privacy.rb +18 -0
- data/lib/leftovers/dynamic_processors/set_privacy.rb +23 -0
- data/lib/leftovers/dynamic_processors.rb +2 -0
- data/lib/leftovers/file.rb +12 -12
- 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 +66 -169
- data/lib/leftovers/matcher_builders/and_not.rb +7 -5
- data/lib/leftovers/matcher_builders/document.rb +13 -0
- data/lib/leftovers/matcher_builders/name.rb +18 -17
- data/lib/leftovers/matcher_builders/node.rb +48 -28
- data/lib/leftovers/matcher_builders/node_has_argument.rb +48 -53
- 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_privacy.rb +13 -0
- data/lib/leftovers/matcher_builders/node_type.rb +4 -4
- data/lib/leftovers/matcher_builders/node_value.rb +28 -23
- data/lib/leftovers/matcher_builders/or.rb +50 -50
- data/lib/leftovers/matcher_builders/string_pattern.rb +14 -5
- data/lib/leftovers/matcher_builders.rb +2 -0
- data/lib/leftovers/matchers/all.rb +0 -4
- data/lib/leftovers/matchers/and.rb +0 -4
- data/lib/leftovers/matchers/any.rb +0 -4
- data/lib/leftovers/matchers/node_has_any_keyword_argument.rb +1 -7
- data/lib/leftovers/matchers/node_has_any_positional_argument_with_value.rb +1 -7
- data/lib/leftovers/matchers/node_has_positional_argument_with_value.rb +0 -4
- data/lib/leftovers/matchers/node_name.rb +0 -4
- data/lib/leftovers/matchers/node_pair_value.rb +0 -4
- data/lib/leftovers/matchers/node_path.rb +0 -4
- data/lib/leftovers/matchers/node_privacy.rb +19 -0
- data/lib/leftovers/matchers/node_scalar_value.rb +0 -4
- data/lib/leftovers/matchers/node_type.rb +0 -4
- data/lib/leftovers/matchers/not.rb +0 -4
- data/lib/leftovers/matchers/or.rb +0 -4
- data/lib/leftovers/matchers.rb +1 -0
- data/lib/leftovers/merged_config.rb +15 -33
- 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 +2 -2
- data/lib/leftovers/processor_builders/add_suffix.rb +2 -2
- data/lib/leftovers/processor_builders/argument.rb +8 -11
- data/lib/leftovers/processor_builders/dynamic.rb +51 -16
- 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 +4 -4
- 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/todo_reporter.rb +10 -35
- 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/delete_prefix.rb +0 -6
- data/lib/leftovers/value_processors/delete_suffix.rb +0 -6
- data/lib/leftovers/value_processors/each.rb +1 -1
- data/lib/leftovers/value_processors/each_for_definition_set.rb +4 -10
- 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 +3 -2
- data/lib/leftovers/value_processors/keyword.rb +3 -11
- data/lib/leftovers/value_processors/keyword_argument.rb +2 -10
- data/lib/leftovers/value_processors/return_definition_node.rb +14 -0
- data/lib/leftovers/value_processors/{return_string.rb → return_sym.rb} +1 -1
- data/lib/leftovers/value_processors/split.rb +2 -2
- data/lib/leftovers/value_processors.rb +2 -2
- data/lib/leftovers/version.rb +1 -1
- data/lib/leftovers.rb +66 -23
- metadata +98 -39
- data/lib/config/actioncable.yml +0 -4
- data/lib/leftovers/backports.rb +0 -40
- data/lib/leftovers/config_validator/error_processor.rb +0 -196
- data/lib/leftovers/config_validator/schema_hash.rb +0 -530
- data/lib/leftovers/config_validator.rb +0 -60
- data/lib/leftovers/erb.rb +0 -20
- data/lib/leftovers/haml.rb +0 -21
- data/lib/leftovers/slim.rb +0 -21
- data/lib/leftovers/value_processors/return_definition.rb +0 -26
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module Leftovers
|
6
|
+
module Precompilers
|
7
|
+
module YAML
|
8
|
+
class Builder < ::Psych::TreeBuilder
|
9
|
+
def initialize
|
10
|
+
@constants = []
|
11
|
+
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_constant_for_tag(tag, value = nil)
|
16
|
+
match = %r{\A!ruby/[^:]*(?::(.*))?\z}.match(tag)
|
17
|
+
return unless match
|
18
|
+
|
19
|
+
@constants << (match[1] || value)
|
20
|
+
end
|
21
|
+
|
22
|
+
def start_mapping(_anchor, tag, *rest) # leftovers:keep
|
23
|
+
add_constant_for_tag(tag)
|
24
|
+
tag = nil
|
25
|
+
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
def start_sequence(_anchor, tag, *rest) # leftovers:keep
|
30
|
+
add_constant_for_tag(tag)
|
31
|
+
tag = nil
|
32
|
+
|
33
|
+
super
|
34
|
+
end
|
35
|
+
|
36
|
+
def scalar(value, _anchor, tag, *rest) # leftovers:keep
|
37
|
+
add_constant_for_tag(tag, value)
|
38
|
+
tag = nil
|
39
|
+
|
40
|
+
super
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_ruby_file
|
44
|
+
<<~FILE
|
45
|
+
__leftovers_document(#{to_ruby_argument(root.to_ruby.first)})
|
46
|
+
#{@constants.join("\n")}
|
47
|
+
FILE
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def to_ruby_argument(value)
|
53
|
+
ruby = value.inspect
|
54
|
+
return ruby unless value.is_a?(Array)
|
55
|
+
|
56
|
+
ruby.delete_prefix!('[')
|
57
|
+
ruby.delete_suffix!(']')
|
58
|
+
|
59
|
+
ruby
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.precompile(yaml)
|
64
|
+
builder = ::Leftovers::Precompilers::YAML::Builder.new
|
65
|
+
parser = ::Psych::Parser.new(builder)
|
66
|
+
parser.parse(yaml)
|
67
|
+
|
68
|
+
builder.to_ruby_file
|
69
|
+
rescue ::Psych::SyntaxError => e
|
70
|
+
message = [e.problem, e.context].compact.join(' ')
|
71
|
+
raise ::Leftovers::PrecompileError.new(message, line: e.line, column: e.column)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -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
|
@@ -6,12 +6,12 @@ module Leftovers
|
|
6
6
|
def self.build(argument, then_processor)
|
7
7
|
case argument
|
8
8
|
when ::Hash
|
9
|
-
dynamic_prefix = ::Leftovers::ProcessorBuilders::Action.build(argument, :
|
9
|
+
dynamic_prefix = ::Leftovers::ProcessorBuilders::Action.build(argument, :sym)
|
10
10
|
::Leftovers::ValueProcessors::AddDynamicPrefix.new(dynamic_prefix, then_processor)
|
11
11
|
when ::String
|
12
12
|
::Leftovers::ValueProcessors::AddPrefix.new(argument, then_processor)
|
13
13
|
# :nocov:
|
14
|
-
else raise
|
14
|
+
else raise Leftovers::UnexpectedCase, "Unhandled value #{argument.inspect}"
|
15
15
|
# :nocov:
|
16
16
|
end
|
17
17
|
end
|
@@ -6,12 +6,12 @@ module Leftovers
|
|
6
6
|
def self.build(argument, then_processor)
|
7
7
|
case argument
|
8
8
|
when ::Hash
|
9
|
-
dynamic_suffix = ::Leftovers::ProcessorBuilders::Action.build(argument, :
|
9
|
+
dynamic_suffix = ::Leftovers::ProcessorBuilders::Action.build(argument, :sym)
|
10
10
|
::Leftovers::ValueProcessors::AddDynamicSuffix.new(dynamic_suffix, then_processor)
|
11
11
|
when ::String
|
12
12
|
::Leftovers::ValueProcessors::AddSuffix.new(argument, then_processor)
|
13
13
|
# :nocov:
|
14
|
-
else raise
|
14
|
+
else raise Leftovers::UnexpectedCase, "Unhandled value #{argument.inspect}"
|
15
15
|
# :nocov:
|
16
16
|
end
|
17
17
|
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
|
@@ -3,22 +3,57 @@
|
|
3
3
|
module Leftovers
|
4
4
|
module ProcessorBuilders
|
5
5
|
module Dynamic
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
6
|
+
class << self
|
7
|
+
def build(dynamic_rules)
|
8
|
+
::Leftovers::ProcessorBuilders::EachDynamic.each_or_self(dynamic_rules) do |dynamic|
|
9
|
+
build_processors(**dynamic)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def build_processors(
|
16
|
+
call: nil, define: nil, set_privacy: nil, set_default_privacy: nil, **matcher_rules
|
17
|
+
)
|
18
|
+
matcher = ::Leftovers::MatcherBuilders::Node.build(**matcher_rules)
|
19
|
+
|
20
|
+
call_action = build_action(call, return_type: :sym)
|
21
|
+
define_action = build_action(define, return_type: :definition_node)
|
22
|
+
|
23
|
+
::Leftovers::ProcessorBuilders::EachDynamic.build([
|
24
|
+
build_call_define_processor(matcher, call_action, define_action),
|
25
|
+
build_set_privacy_processor(matcher, set_privacy),
|
26
|
+
build_set_default_privacy_processor(matcher, set_default_privacy)
|
27
|
+
])
|
28
|
+
end
|
29
|
+
|
30
|
+
def build_action(processor_rules, return_type:)
|
31
|
+
::Leftovers::ProcessorBuilders::Action.build(processor_rules, return_type)
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_set_privacy_processor(matcher, set_privacy)
|
35
|
+
::Leftovers::ProcessorBuilders::EachDynamic.each_or_self(set_privacy) do |action_values|
|
36
|
+
to = action_values.delete(:to)
|
37
|
+
action = build_action(action_values, return_type: :sym)
|
38
|
+
|
39
|
+
::Leftovers::DynamicProcessors::SetPrivacy.new(matcher, action, to)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def build_set_default_privacy_processor(matcher, set_default_privacy)
|
44
|
+
::Leftovers::DynamicProcessors::SetDefaultPrivacy.new(matcher, set_default_privacy)
|
45
|
+
end
|
46
|
+
|
47
|
+
def build_call_define_processor(matcher, call_action, define_action)
|
48
|
+
if call_action && define_action
|
49
|
+
# this nonsense saves a method call and array instantiation per method
|
50
|
+
::Leftovers::DynamicProcessors::CallDefinition.new(matcher, call_action, define_action)
|
51
|
+
elsif define_action
|
52
|
+
::Leftovers::DynamicProcessors::Definition.new(matcher, define_action)
|
53
|
+
elsif call_action
|
54
|
+
::Leftovers::DynamicProcessors::Call.new(matcher, call_action)
|
55
|
+
else
|
56
|
+
::Leftovers::DynamicProcessors::Null
|
22
57
|
end
|
23
58
|
end
|
24
59
|
end
|
@@ -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
|
@@ -19,9 +19,9 @@ module Leftovers
|
|
19
19
|
::Leftovers::ValueProcessors::Pluralize.new(then_processor)
|
20
20
|
when 'singularize'
|
21
21
|
::Leftovers::ValueProcessors::Singularize.new(then_processor)
|
22
|
-
when 'camelize'
|
22
|
+
when 'camelize'
|
23
23
|
::Leftovers::ValueProcessors::Camelize.new(then_processor)
|
24
|
-
when 'titleize'
|
24
|
+
when 'titleize'
|
25
25
|
::Leftovers::ValueProcessors::Titleize.new(then_processor)
|
26
26
|
when 'demodulize'
|
27
27
|
::Leftovers::ValueProcessors::Demodulize.new(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
|