leftovers 0.2.1 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +42 -0
- data/README.md +35 -49
- data/docs/Configuration.md +627 -0
- data/exe/leftovers +2 -2
- data/leftovers.gemspec +13 -7
- data/lib/config/attr_encrypted.yml +3 -4
- data/lib/config/audited.yml +9 -4
- data/lib/config/datagrid.yml +1 -1
- data/lib/config/flipper.yml +1 -3
- data/lib/config/graphql.yml +15 -13
- data/lib/config/okcomputer.yml +1 -3
- data/lib/config/parser.yml +89 -91
- data/lib/config/rails.yml +160 -97
- data/lib/config/redcarpet.yml +35 -38
- data/lib/config/rollbar.yml +1 -3
- data/lib/config/rspec.yml +18 -10
- data/lib/config/ruby.yml +42 -49
- data/lib/config/selenium-webdriver.yml +19 -0
- data/lib/config/sidekiq.yml +9 -0
- data/lib/config/will_paginate.yml +12 -14
- data/lib/leftovers.rb +61 -43
- data/lib/leftovers/ast.rb +8 -0
- data/lib/leftovers/ast/builder.rb +6 -3
- data/lib/leftovers/ast/node.rb +66 -107
- data/lib/leftovers/backports.rb +24 -40
- data/lib/leftovers/cli.rb +17 -14
- data/lib/leftovers/collector.rb +7 -11
- data/lib/leftovers/config.rb +38 -13
- data/lib/leftovers/config_validator.rb +60 -0
- data/lib/leftovers/config_validator/error_processor.rb +196 -0
- data/lib/leftovers/config_validator/schema_hash.rb +496 -0
- data/lib/leftovers/definition.rb +16 -41
- data/lib/leftovers/definition_node.rb +36 -0
- data/lib/leftovers/definition_set.rb +17 -24
- data/lib/leftovers/dynamic_processors.rb +11 -0
- data/lib/leftovers/dynamic_processors/call.rb +25 -0
- data/lib/leftovers/dynamic_processors/call_definition.rb +31 -0
- data/lib/leftovers/dynamic_processors/definition.rb +26 -0
- data/lib/leftovers/dynamic_processors/each.rb +19 -0
- data/lib/leftovers/dynamic_processors/null.rb +9 -0
- data/lib/leftovers/erb.rb +2 -2
- data/lib/leftovers/file.rb +3 -5
- data/lib/leftovers/file_collector.rb +82 -62
- data/lib/leftovers/file_list.rb +9 -12
- data/lib/leftovers/haml.rb +9 -12
- data/lib/leftovers/matcher_builders.rb +24 -0
- data/lib/leftovers/matcher_builders/and.rb +19 -0
- data/lib/leftovers/matcher_builders/and_not.rb +14 -0
- data/lib/leftovers/matcher_builders/argument_node_value.rb +21 -0
- data/lib/leftovers/matcher_builders/name.rb +29 -0
- data/lib/leftovers/matcher_builders/node.rb +40 -0
- data/lib/leftovers/matcher_builders/node_has_argument.rb +71 -0
- data/lib/leftovers/matcher_builders/node_has_keyword_argument.rb +22 -0
- data/lib/leftovers/matcher_builders/node_has_positional_argument.rb +24 -0
- data/lib/leftovers/matcher_builders/node_name.rb +15 -0
- data/lib/leftovers/matcher_builders/node_pair_name.rb +18 -0
- data/lib/leftovers/matcher_builders/node_pair_value.rb +16 -0
- data/lib/leftovers/matcher_builders/node_path.rb +14 -0
- data/lib/leftovers/matcher_builders/node_type.rb +28 -0
- data/lib/leftovers/matcher_builders/or.rb +73 -0
- data/lib/leftovers/matcher_builders/path.rb +15 -0
- data/lib/leftovers/matcher_builders/string.rb +11 -0
- data/lib/leftovers/matcher_builders/string_pattern.rb +19 -0
- data/lib/leftovers/matcher_builders/unless.rb +13 -0
- data/lib/leftovers/matchers.rb +26 -0
- data/lib/leftovers/matchers/all.rb +25 -0
- data/lib/leftovers/matchers/and.rb +24 -0
- data/lib/leftovers/matchers/any.rb +27 -0
- data/lib/leftovers/matchers/node_has_any_keyword_argument.rb +28 -0
- data/lib/leftovers/matchers/node_has_any_positional_argument_with_value.rb +25 -0
- data/lib/leftovers/matchers/node_has_positional_argument.rb +23 -0
- data/lib/leftovers/matchers/node_has_positional_argument_with_value.rb +25 -0
- data/lib/leftovers/matchers/node_name.rb +23 -0
- data/lib/leftovers/matchers/node_pair_value.rb +23 -0
- data/lib/leftovers/matchers/node_path.rb +23 -0
- data/lib/leftovers/matchers/node_scalar_value.rb +25 -0
- data/lib/leftovers/matchers/node_type.rb +23 -0
- data/lib/leftovers/matchers/not.rb +23 -0
- data/lib/leftovers/matchers/or.rb +26 -0
- data/lib/leftovers/merged_config.rb +24 -14
- data/lib/leftovers/parser.rb +2 -5
- data/lib/leftovers/processor_builders.rb +22 -0
- data/lib/leftovers/processor_builders/action.rb +63 -0
- data/lib/leftovers/processor_builders/add_prefix.rb +20 -0
- data/lib/leftovers/processor_builders/add_suffix.rb +20 -0
- data/lib/leftovers/processor_builders/argument.rb +25 -0
- data/lib/leftovers/processor_builders/dynamic.rb +27 -0
- data/lib/leftovers/processor_builders/each.rb +36 -0
- data/lib/leftovers/processor_builders/each_action.rb +51 -0
- data/lib/leftovers/processor_builders/each_dynamic.rb +54 -0
- data/lib/leftovers/processor_builders/each_for_definition_set.rb +36 -0
- data/lib/leftovers/processor_builders/itself.rb +13 -0
- data/lib/leftovers/processor_builders/keyword.rb +24 -0
- data/lib/leftovers/processor_builders/keyword_argument.rb +14 -0
- data/lib/leftovers/processor_builders/transform.rb +55 -0
- data/lib/leftovers/processor_builders/transform_chain.rb +24 -0
- data/lib/leftovers/processor_builders/transform_set.rb +47 -0
- data/lib/leftovers/processor_builders/value.rb +13 -0
- data/lib/leftovers/rake_task.rb +4 -4
- data/lib/leftovers/reporter.rb +1 -1
- data/lib/leftovers/value_processors.rb +40 -0
- data/lib/leftovers/value_processors/add_dynamic_prefix.rb +31 -0
- data/lib/leftovers/value_processors/add_dynamic_suffix.rb +31 -0
- data/lib/leftovers/value_processors/add_prefix.rb +20 -0
- data/lib/leftovers/value_processors/add_suffix.rb +20 -0
- data/lib/leftovers/value_processors/camelize.rb +24 -0
- data/lib/leftovers/value_processors/capitalize.rb +19 -0
- data/lib/leftovers/value_processors/deconstantize.rb +24 -0
- data/lib/leftovers/value_processors/delete_after.rb +22 -0
- data/lib/leftovers/value_processors/delete_before.rb +22 -0
- data/lib/leftovers/value_processors/delete_prefix.rb +26 -0
- data/lib/leftovers/value_processors/delete_suffix.rb +26 -0
- data/lib/leftovers/value_processors/demodulize.rb +24 -0
- data/lib/leftovers/value_processors/downcase.rb +19 -0
- data/lib/leftovers/value_processors/each.rb +21 -0
- data/lib/leftovers/value_processors/each_for_definition_set.rb +29 -0
- data/lib/leftovers/value_processors/each_keyword.rb +27 -0
- data/lib/leftovers/value_processors/each_keyword_argument.rb +27 -0
- data/lib/leftovers/value_processors/each_positional_argument.rb +24 -0
- data/lib/leftovers/value_processors/itself.rb +17 -0
- data/lib/leftovers/value_processors/keyword.rb +36 -0
- data/lib/leftovers/value_processors/keyword_argument.rb +36 -0
- data/lib/leftovers/value_processors/parameterize.rb +24 -0
- data/lib/leftovers/value_processors/placeholder.rb +18 -0
- data/lib/leftovers/value_processors/pluralize.rb +24 -0
- data/lib/leftovers/value_processors/positional_argument.rb +26 -0
- data/lib/leftovers/value_processors/replace_value.rb +18 -0
- data/lib/leftovers/value_processors/return_definition.rb +26 -0
- data/lib/leftovers/value_processors/return_string.rb +14 -0
- data/lib/leftovers/value_processors/singularize.rb +24 -0
- data/lib/leftovers/value_processors/split.rb +22 -0
- data/lib/leftovers/value_processors/swapcase.rb +19 -0
- data/lib/leftovers/value_processors/titleize.rb +24 -0
- data/lib/leftovers/value_processors/underscore.rb +24 -0
- data/lib/leftovers/value_processors/upcase.rb +19 -0
- data/lib/leftovers/version.rb +1 -1
- metadata +190 -28
- data/lib/config/selenium.yml +0 -21
- data/lib/leftovers/argument_rule.rb +0 -219
- data/lib/leftovers/core_ext.rb +0 -13
- data/lib/leftovers/hash_rule.rb +0 -40
- data/lib/leftovers/name_rule.rb +0 -53
- data/lib/leftovers/rule.rb +0 -74
- data/lib/leftovers/transform_rule.rb +0 -171
- data/lib/leftovers/value_rule.rb +0 -56
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
module ProcessorBuilders
|
5
|
+
module Itself
|
6
|
+
def self.build(value, then_processor)
|
7
|
+
return unless value && then_processor
|
8
|
+
|
9
|
+
::Leftovers::ValueProcessors::Itself.new(then_processor)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
module ProcessorBuilders
|
5
|
+
module Keyword
|
6
|
+
def self.build(value, then_processor) # rubocop:disable Metrics/MethodLength
|
7
|
+
return unless value && then_processor
|
8
|
+
|
9
|
+
case value
|
10
|
+
when true, '**'
|
11
|
+
::Leftovers::ValueProcessors::EachKeyword.new(then_processor)
|
12
|
+
when ::String, ::Hash, ::Array
|
13
|
+
::Leftovers::ValueProcessors::Keyword.new(
|
14
|
+
::Leftovers::MatcherBuilders::NodePairName.build(value),
|
15
|
+
then_processor
|
16
|
+
)
|
17
|
+
# :nocov:
|
18
|
+
else raise
|
19
|
+
# :nocov:
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
module ProcessorBuilders
|
5
|
+
module KeywordArgument
|
6
|
+
def self.build(pattern, then_processor)
|
7
|
+
::Leftovers::ValueProcessors::KeywordArgument.new(
|
8
|
+
::Leftovers::MatcherBuilders::NodePairName.build(pattern),
|
9
|
+
then_processor
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
module ProcessorBuilders
|
5
|
+
module Transform
|
6
|
+
def self.build(transform, argument, then_processor) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/AbcSize
|
7
|
+
case transform.to_s
|
8
|
+
when 'original', nil
|
9
|
+
then_processor
|
10
|
+
when 'downcase'
|
11
|
+
::Leftovers::ValueProcessors::Downcase.new(then_processor)
|
12
|
+
when 'upcase'
|
13
|
+
::Leftovers::ValueProcessors::Upcase.new(then_processor)
|
14
|
+
when 'capitalize'
|
15
|
+
::Leftovers::ValueProcessors::Capitalize.new(then_processor)
|
16
|
+
when 'swapcase'
|
17
|
+
::Leftovers::ValueProcessors::Swapcase.new(then_processor)
|
18
|
+
when 'pluralize'
|
19
|
+
::Leftovers::ValueProcessors::Pluralize.new(then_processor)
|
20
|
+
when 'singularize'
|
21
|
+
::Leftovers::ValueProcessors::Singularize.new(then_processor)
|
22
|
+
when 'camelize', 'camelcase'
|
23
|
+
::Leftovers::ValueProcessors::Camelize.new(then_processor)
|
24
|
+
when 'titleize', 'titlecase'
|
25
|
+
::Leftovers::ValueProcessors::Titleize.new(then_processor)
|
26
|
+
when 'demodulize'
|
27
|
+
::Leftovers::ValueProcessors::Demodulize.new(then_processor)
|
28
|
+
when 'deconstantize'
|
29
|
+
::Leftovers::ValueProcessors::Deconstantize.new(then_processor)
|
30
|
+
when 'parameterize'
|
31
|
+
::Leftovers::ValueProcessors::Parameterize.new(then_processor)
|
32
|
+
when 'underscore'
|
33
|
+
::Leftovers::ValueProcessors::Underscore.new(then_processor)
|
34
|
+
when 'split'
|
35
|
+
::Leftovers::ValueProcessors::Split.new(argument, then_processor)
|
36
|
+
when 'delete_before'
|
37
|
+
::Leftovers::ValueProcessors::DeleteBefore.new(argument, then_processor)
|
38
|
+
when 'delete_after'
|
39
|
+
::Leftovers::ValueProcessors::DeleteAfter.new(argument, then_processor)
|
40
|
+
when 'add_prefix'
|
41
|
+
::Leftovers::ProcessorBuilders::AddPrefix.build(argument, then_processor)
|
42
|
+
when 'add_suffix'
|
43
|
+
::Leftovers::ProcessorBuilders::AddSuffix.build(argument, then_processor)
|
44
|
+
when 'delete_prefix'
|
45
|
+
::Leftovers::ValueProcessors::DeletePrefix.new(argument, then_processor)
|
46
|
+
when 'delete_suffix'
|
47
|
+
::Leftovers::ValueProcessors::DeleteSuffix.new(argument, then_processor)
|
48
|
+
# :nocov:
|
49
|
+
else raise
|
50
|
+
# :nocov:
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
module ProcessorBuilders
|
5
|
+
module TransformChain
|
6
|
+
def self.build(transforms, next_transform) # rubocop:disable Metrics/MethodLength
|
7
|
+
case transforms
|
8
|
+
when ::Hash
|
9
|
+
transforms.reverse_each do |(transform, transform_arg)|
|
10
|
+
next_transform = ::Leftovers::ProcessorBuilders::Transform.build(
|
11
|
+
transform, transform_arg, next_transform
|
12
|
+
)
|
13
|
+
end
|
14
|
+
next_transform
|
15
|
+
when ::String
|
16
|
+
::Leftovers::ProcessorBuilders::Transform.build(transforms, true, next_transform)
|
17
|
+
# :nocov:
|
18
|
+
else raise
|
19
|
+
# :nocov:
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
module ProcessorBuilders
|
5
|
+
module TransformSet
|
6
|
+
def self.build(transforms, action)
|
7
|
+
each_builder(action).each_or_self(transforms) do |transform|
|
8
|
+
case transform
|
9
|
+
when ::Hash
|
10
|
+
next build(transform[:transforms], action) if transform[:transforms]
|
11
|
+
|
12
|
+
::Leftovers::ProcessorBuilders::TransformChain.build(transform, build_final(action))
|
13
|
+
when ::String
|
14
|
+
::Leftovers::ProcessorBuilders::TransformChain.build(transform, build_final(action))
|
15
|
+
# :nocov:
|
16
|
+
else raise
|
17
|
+
# :nocov:
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.each_builder(action)
|
23
|
+
case action
|
24
|
+
when :call
|
25
|
+
::Leftovers::ProcessorBuilders::Each
|
26
|
+
when :define
|
27
|
+
::Leftovers::ProcessorBuilders::EachForDefinitionSet
|
28
|
+
# :nocov:
|
29
|
+
else raise
|
30
|
+
# :nocov:
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.build_final(action)
|
35
|
+
case action
|
36
|
+
when :call
|
37
|
+
::Leftovers::ValueProcessors::ReturnString
|
38
|
+
when :define
|
39
|
+
::Leftovers::ValueProcessors::ReturnDefinition
|
40
|
+
# :nocov:
|
41
|
+
else raise
|
42
|
+
# :nocov:
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
module ProcessorBuilders
|
5
|
+
module Value
|
6
|
+
def self.build(value, then_processor)
|
7
|
+
return unless value && then_processor
|
8
|
+
|
9
|
+
::Leftovers::ValueProcessors::ReplaceValue.new(value, then_processor)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/leftovers/rake_task.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'rake'
|
4
4
|
require 'shellwords'
|
5
|
-
require_relative '
|
5
|
+
require_relative '../leftovers'
|
6
6
|
|
7
7
|
module Leftovers
|
8
8
|
class RakeTask
|
@@ -49,9 +49,9 @@ module Leftovers
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def run(argv)
|
52
|
-
Leftovers::CLI.new(argv: argv
|
53
|
-
|
54
|
-
|
52
|
+
exitstatus = Leftovers::CLI.new(argv: argv).run
|
53
|
+
|
54
|
+
exit exitstatus unless exitstatus == 0
|
55
55
|
end
|
56
56
|
|
57
57
|
def argv_or_default(task_argv)
|
data/lib/leftovers/reporter.rb
CHANGED
@@ -4,7 +4,7 @@ module Leftovers
|
|
4
4
|
class Reporter
|
5
5
|
def call(definition)
|
6
6
|
Leftovers.puts(
|
7
|
-
"\e[36m#{definition.
|
7
|
+
"\e[36m#{definition.location_s}\e[0m #{definition} \e[2m#{definition.highlighted_source("\e[33m", "\e[0;2m")}\e[0m" # rubocop:disable Layout/LineLength
|
8
8
|
)
|
9
9
|
end
|
10
10
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
module ValueProcessors
|
5
|
+
autoload(:AddDynamicPrefix, "#{__dir__}/value_processors/add_dynamic_prefix")
|
6
|
+
autoload(:AddDynamicSuffix, "#{__dir__}/value_processors/add_dynamic_suffix")
|
7
|
+
autoload(:AddPrefix, "#{__dir__}/value_processors/add_prefix")
|
8
|
+
autoload(:AddSuffix, "#{__dir__}/value_processors/add_suffix")
|
9
|
+
autoload(:Camelize, "#{__dir__}/value_processors/camelize")
|
10
|
+
autoload(:Capitalize, "#{__dir__}/value_processors/capitalize")
|
11
|
+
autoload(:Deconstantize, "#{__dir__}/value_processors/deconstantize")
|
12
|
+
autoload(:DeleteAfter, "#{__dir__}/value_processors/delete_after")
|
13
|
+
autoload(:DeleteBefore, "#{__dir__}/value_processors/delete_before")
|
14
|
+
autoload(:DeletePrefix, "#{__dir__}/value_processors/delete_prefix")
|
15
|
+
autoload(:DeleteSuffix, "#{__dir__}/value_processors/delete_suffix")
|
16
|
+
autoload(:Demodulize, "#{__dir__}/value_processors/demodulize")
|
17
|
+
autoload(:Downcase, "#{__dir__}/value_processors/downcase")
|
18
|
+
autoload(:EachForDefinitionSet, "#{__dir__}/value_processors/each_for_definition_set")
|
19
|
+
autoload(:EachKeyword, "#{__dir__}/value_processors/each_keyword")
|
20
|
+
autoload(:EachKeywordArgument, "#{__dir__}/value_processors/each_keyword_argument")
|
21
|
+
autoload(:EachPositionalArgument, "#{__dir__}/value_processors/each_positional_argument")
|
22
|
+
autoload(:Each, "#{__dir__}/value_processors/each")
|
23
|
+
autoload(:Itself, "#{__dir__}/value_processors/itself")
|
24
|
+
autoload(:Keyword, "#{__dir__}/value_processors/keyword")
|
25
|
+
autoload(:KeywordArgument, "#{__dir__}/value_processors/keyword_argument")
|
26
|
+
autoload(:Parameterize, "#{__dir__}/value_processors/parameterize")
|
27
|
+
autoload(:Placeholder, "#{__dir__}/value_processors/placeholder")
|
28
|
+
autoload(:Pluralize, "#{__dir__}/value_processors/pluralize")
|
29
|
+
autoload(:PositionalArgument, "#{__dir__}/value_processors/positional_argument")
|
30
|
+
autoload(:ReplaceValue, "#{__dir__}/value_processors/replace_value")
|
31
|
+
autoload(:ReturnDefinition, "#{__dir__}/value_processors/return_definition")
|
32
|
+
autoload(:ReturnString, "#{__dir__}/value_processors/return_string")
|
33
|
+
autoload(:Singularize, "#{__dir__}/value_processors/singularize")
|
34
|
+
autoload(:Split, "#{__dir__}/value_processors/split")
|
35
|
+
autoload(:Swapcase, "#{__dir__}/value_processors/swapcase")
|
36
|
+
autoload(:Titleize, "#{__dir__}/value_processors/titleize")
|
37
|
+
autoload(:Underscore, "#{__dir__}/value_processors/underscore")
|
38
|
+
autoload(:Upcase, "#{__dir__}/value_processors/upcase")
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
module ValueProcessors
|
5
|
+
class AddDynamicPrefix
|
6
|
+
def initialize(prefix_processor, then_processor)
|
7
|
+
@prefix_processor = prefix_processor
|
8
|
+
@then_processor = then_processor
|
9
|
+
|
10
|
+
freeze
|
11
|
+
end
|
12
|
+
|
13
|
+
def process(str, node, method_node) # rubocop:disable Metrics/MethodLength
|
14
|
+
return unless str
|
15
|
+
|
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
|
+
|
22
|
+
prefixes.map do |prefix|
|
23
|
+
@then_processor.process("#{prefix}#{str}", node, method_node)
|
24
|
+
end
|
25
|
+
else
|
26
|
+
@then_processor.process("#{prefixes}#{str}", node, method_node)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
module ValueProcessors
|
5
|
+
class AddDynamicSuffix
|
6
|
+
def initialize(suffix_processor, then_processor)
|
7
|
+
@suffix_processor = suffix_processor
|
8
|
+
@then_processor = then_processor
|
9
|
+
|
10
|
+
freeze
|
11
|
+
end
|
12
|
+
|
13
|
+
def process(str, node, method_node) # rubocop:disable Metrics/MethodLength
|
14
|
+
return unless str
|
15
|
+
|
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
|
+
|
22
|
+
suffixes.map do |suffix|
|
23
|
+
@then_processor.process("#{str}#{suffix}", node, method_node)
|
24
|
+
end
|
25
|
+
else
|
26
|
+
@then_processor.process("#{str}#{suffixes}", node, method_node)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
module ValueProcessors
|
5
|
+
class AddPrefix
|
6
|
+
def initialize(prefix, then_processor)
|
7
|
+
@prefix = prefix
|
8
|
+
@then_processor = then_processor
|
9
|
+
|
10
|
+
freeze
|
11
|
+
end
|
12
|
+
|
13
|
+
def process(str, node, method_node)
|
14
|
+
return unless str
|
15
|
+
|
16
|
+
@then_processor.process("#{@prefix}#{str}", node, method_node)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
module ValueProcessors
|
5
|
+
class AddSuffix
|
6
|
+
def initialize(suffix, then_processor)
|
7
|
+
@suffix = suffix
|
8
|
+
@then_processor = then_processor
|
9
|
+
|
10
|
+
freeze
|
11
|
+
end
|
12
|
+
|
13
|
+
def process(str, node, method_node)
|
14
|
+
return unless str
|
15
|
+
|
16
|
+
@then_processor.process("#{str}#{@suffix}", node, method_node)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
module ValueProcessors
|
5
|
+
class Camelize
|
6
|
+
def initialize(then_processor)
|
7
|
+
@then_processor = then_processor
|
8
|
+
|
9
|
+
freeze
|
10
|
+
end
|
11
|
+
|
12
|
+
def process(str, node, method_node)
|
13
|
+
return unless str
|
14
|
+
|
15
|
+
@then_processor.process(str.camelize, node, method_node)
|
16
|
+
rescue NoMethodError
|
17
|
+
Leftovers.error <<~MESSAGE
|
18
|
+
Tried using the String#camelize method, but the activesupport gem was not available and/or not required
|
19
|
+
`gem install activesupport`, and/or add `requires: 'active_support/core_ext/string'` to your .leftovers.yml
|
20
|
+
MESSAGE
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
module ValueProcessors
|
5
|
+
class Capitalize
|
6
|
+
def initialize(then_processor)
|
7
|
+
@then_processor = then_processor
|
8
|
+
|
9
|
+
freeze
|
10
|
+
end
|
11
|
+
|
12
|
+
def process(str, node, method_node)
|
13
|
+
return unless str
|
14
|
+
|
15
|
+
@then_processor.process(str.capitalize, node, method_node)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
module ValueProcessors
|
5
|
+
class Deconstantize
|
6
|
+
def initialize(then_processor)
|
7
|
+
@then_processor = then_processor
|
8
|
+
|
9
|
+
freeze
|
10
|
+
end
|
11
|
+
|
12
|
+
def process(str, node, method_node)
|
13
|
+
return unless str
|
14
|
+
|
15
|
+
@then_processor.process(str.deconstantize, node, method_node)
|
16
|
+
rescue NoMethodError
|
17
|
+
Leftovers.error <<~MESSAGE
|
18
|
+
Tried using the String#deconstantize method, but the activesupport gem was not available and/or not required
|
19
|
+
`gem install activesupport`, and/or add `requires: 'active_support/core_ext/string'` to your .leftovers.yml
|
20
|
+
MESSAGE
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|