leftovers 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +49 -0
  3. data/README.md +28 -45
  4. data/docs/Configuration.md +598 -0
  5. data/exe/leftovers +2 -2
  6. data/leftovers.gemspec +13 -7
  7. data/lib/config/attr_encrypted.yml +3 -4
  8. data/lib/config/audited.yml +9 -0
  9. data/lib/config/datagrid.yml +1 -1
  10. data/lib/config/flipper.yml +1 -3
  11. data/lib/config/graphql.yml +15 -13
  12. data/lib/config/okcomputer.yml +1 -3
  13. data/lib/config/parser.yml +89 -91
  14. data/lib/config/rails.yml +162 -92
  15. data/lib/config/redcarpet.yml +35 -38
  16. data/lib/config/rollbar.yml +1 -3
  17. data/lib/config/rspec.yml +18 -10
  18. data/lib/config/ruby.yml +42 -39
  19. data/lib/config/selenium-webdriver.yml +19 -0
  20. data/lib/config/sidekiq.yml +9 -0
  21. data/lib/config/will_paginate.yml +12 -14
  22. data/lib/leftovers.rb +60 -43
  23. data/lib/leftovers/ast.rb +8 -0
  24. data/lib/leftovers/ast/builder.rb +6 -3
  25. data/lib/leftovers/ast/node.rb +63 -104
  26. data/lib/leftovers/backports.rb +24 -40
  27. data/lib/leftovers/cli.rb +17 -14
  28. data/lib/leftovers/collector.rb +7 -11
  29. data/lib/leftovers/config.rb +34 -13
  30. data/lib/leftovers/config_validator.rb +60 -0
  31. data/lib/leftovers/config_validator/error_processor.rb +196 -0
  32. data/lib/leftovers/config_validator/schema_hash.rb +495 -0
  33. data/lib/leftovers/definition.rb +14 -39
  34. data/lib/leftovers/definition_set.rb +7 -17
  35. data/lib/leftovers/dynamic_processors.rb +11 -0
  36. data/lib/leftovers/dynamic_processors/call.rb +25 -0
  37. data/lib/leftovers/dynamic_processors/call_definition.rb +31 -0
  38. data/lib/leftovers/dynamic_processors/definition.rb +26 -0
  39. data/lib/leftovers/dynamic_processors/each.rb +19 -0
  40. data/lib/leftovers/dynamic_processors/null.rb +9 -0
  41. data/lib/leftovers/erb.rb +2 -2
  42. data/lib/leftovers/file.rb +3 -5
  43. data/lib/leftovers/file_collector.rb +72 -85
  44. data/lib/leftovers/file_list.rb +9 -12
  45. data/lib/leftovers/haml.rb +9 -12
  46. data/lib/leftovers/matcher_builders.rb +24 -0
  47. data/lib/leftovers/matcher_builders/and.rb +19 -0
  48. data/lib/leftovers/matcher_builders/and_not.rb +14 -0
  49. data/lib/leftovers/matcher_builders/argument_node_value.rb +21 -0
  50. data/lib/leftovers/matcher_builders/name.rb +29 -0
  51. data/lib/leftovers/matcher_builders/node.rb +40 -0
  52. data/lib/leftovers/matcher_builders/node_has_argument.rb +71 -0
  53. data/lib/leftovers/matcher_builders/node_has_keyword_argument.rb +22 -0
  54. data/lib/leftovers/matcher_builders/node_has_positional_argument.rb +24 -0
  55. data/lib/leftovers/matcher_builders/node_name.rb +15 -0
  56. data/lib/leftovers/matcher_builders/node_pair_name.rb +18 -0
  57. data/lib/leftovers/matcher_builders/node_pair_value.rb +16 -0
  58. data/lib/leftovers/matcher_builders/node_path.rb +14 -0
  59. data/lib/leftovers/matcher_builders/node_type.rb +28 -0
  60. data/lib/leftovers/matcher_builders/or.rb +73 -0
  61. data/lib/leftovers/matcher_builders/path.rb +15 -0
  62. data/lib/leftovers/matcher_builders/string.rb +11 -0
  63. data/lib/leftovers/matcher_builders/string_pattern.rb +19 -0
  64. data/lib/leftovers/matcher_builders/unless.rb +13 -0
  65. data/lib/leftovers/matchers.rb +26 -0
  66. data/lib/leftovers/matchers/all.rb +25 -0
  67. data/lib/leftovers/matchers/and.rb +24 -0
  68. data/lib/leftovers/matchers/any.rb +27 -0
  69. data/lib/leftovers/matchers/node_has_any_keyword_argument.rb +28 -0
  70. data/lib/leftovers/matchers/node_has_any_positional_argument_with_value.rb +25 -0
  71. data/lib/leftovers/matchers/node_has_positional_argument.rb +23 -0
  72. data/lib/leftovers/matchers/node_has_positional_argument_with_value.rb +25 -0
  73. data/lib/leftovers/matchers/node_name.rb +23 -0
  74. data/lib/leftovers/matchers/node_pair_value.rb +23 -0
  75. data/lib/leftovers/matchers/node_path.rb +23 -0
  76. data/lib/leftovers/matchers/node_scalar_value.rb +25 -0
  77. data/lib/leftovers/matchers/node_type.rb +23 -0
  78. data/lib/leftovers/matchers/not.rb +23 -0
  79. data/lib/leftovers/matchers/or.rb +26 -0
  80. data/lib/leftovers/merged_config.rb +20 -14
  81. data/lib/leftovers/parser.rb +37 -0
  82. data/lib/leftovers/processor_builders.rb +22 -0
  83. data/lib/leftovers/processor_builders/action.rb +63 -0
  84. data/lib/leftovers/processor_builders/add_prefix.rb +20 -0
  85. data/lib/leftovers/processor_builders/add_suffix.rb +20 -0
  86. data/lib/leftovers/processor_builders/argument.rb +25 -0
  87. data/lib/leftovers/processor_builders/dynamic.rb +27 -0
  88. data/lib/leftovers/processor_builders/each.rb +36 -0
  89. data/lib/leftovers/processor_builders/each_action.rb +51 -0
  90. data/lib/leftovers/processor_builders/each_dynamic.rb +54 -0
  91. data/lib/leftovers/processor_builders/each_for_definition_set.rb +36 -0
  92. data/lib/leftovers/processor_builders/itself.rb +13 -0
  93. data/lib/leftovers/processor_builders/keyword.rb +24 -0
  94. data/lib/leftovers/processor_builders/keyword_argument.rb +14 -0
  95. data/lib/leftovers/processor_builders/transform.rb +55 -0
  96. data/lib/leftovers/processor_builders/transform_chain.rb +24 -0
  97. data/lib/leftovers/processor_builders/transform_set.rb +47 -0
  98. data/lib/leftovers/processor_builders/value.rb +13 -0
  99. data/lib/leftovers/rake_task.rb +4 -4
  100. data/lib/leftovers/reporter.rb +1 -1
  101. data/lib/leftovers/value_processors.rb +40 -0
  102. data/lib/leftovers/value_processors/add_dynamic_prefix.rb +31 -0
  103. data/lib/leftovers/value_processors/add_dynamic_suffix.rb +31 -0
  104. data/lib/leftovers/value_processors/add_prefix.rb +20 -0
  105. data/lib/leftovers/value_processors/add_suffix.rb +20 -0
  106. data/lib/leftovers/value_processors/camelize.rb +24 -0
  107. data/lib/leftovers/value_processors/capitalize.rb +19 -0
  108. data/lib/leftovers/value_processors/deconstantize.rb +24 -0
  109. data/lib/leftovers/value_processors/delete_after.rb +22 -0
  110. data/lib/leftovers/value_processors/delete_before.rb +22 -0
  111. data/lib/leftovers/value_processors/delete_prefix.rb +26 -0
  112. data/lib/leftovers/value_processors/delete_suffix.rb +26 -0
  113. data/lib/leftovers/value_processors/demodulize.rb +24 -0
  114. data/lib/leftovers/value_processors/downcase.rb +19 -0
  115. data/lib/leftovers/value_processors/each.rb +21 -0
  116. data/lib/leftovers/value_processors/each_for_definition_set.rb +33 -0
  117. data/lib/leftovers/value_processors/each_keyword.rb +27 -0
  118. data/lib/leftovers/value_processors/each_keyword_argument.rb +27 -0
  119. data/lib/leftovers/value_processors/each_positional_argument.rb +24 -0
  120. data/lib/leftovers/value_processors/itself.rb +17 -0
  121. data/lib/leftovers/value_processors/keyword.rb +36 -0
  122. data/lib/leftovers/value_processors/keyword_argument.rb +36 -0
  123. data/lib/leftovers/value_processors/parameterize.rb +24 -0
  124. data/lib/leftovers/value_processors/placeholder.rb +18 -0
  125. data/lib/leftovers/value_processors/pluralize.rb +24 -0
  126. data/lib/leftovers/value_processors/positional_argument.rb +26 -0
  127. data/lib/leftovers/value_processors/replace_value.rb +18 -0
  128. data/lib/leftovers/value_processors/return_definition.rb +24 -0
  129. data/lib/leftovers/value_processors/return_string.rb +14 -0
  130. data/lib/leftovers/value_processors/singularize.rb +24 -0
  131. data/lib/leftovers/value_processors/split.rb +22 -0
  132. data/lib/leftovers/value_processors/swapcase.rb +19 -0
  133. data/lib/leftovers/value_processors/titleize.rb +24 -0
  134. data/lib/leftovers/value_processors/underscore.rb +24 -0
  135. data/lib/leftovers/value_processors/upcase.rb +19 -0
  136. data/lib/leftovers/version.rb +1 -1
  137. metadata +193 -29
  138. data/lib/config/selenium.yml +0 -21
  139. data/lib/leftovers/argument_rule.rb +0 -218
  140. data/lib/leftovers/core_ext.rb +0 -13
  141. data/lib/leftovers/hash_rule.rb +0 -40
  142. data/lib/leftovers/name_rule.rb +0 -53
  143. data/lib/leftovers/rule.rb +0 -74
  144. data/lib/leftovers/transform_rule.rb +0 -171
  145. data/lib/leftovers/value_rule.rb +0 -56
@@ -1,38 +1,35 @@
1
- ---
2
- rules:
3
- skip: true
4
- names:
5
- - block_code
6
- - block_quote
7
- - block_html
8
- - footnotes
9
- - footnote_def
10
- - header
11
- - hrule
12
- - list
13
- - list_item
14
- - paragraph
15
- - table
16
- - table_row
17
- - table_cell
18
- - autolink
19
- - codespan
20
- - double_emphasis
21
- - emphasis
22
- - image
23
- - linebreak
24
- - link
25
- - raw_html
26
- - triple_emphasis
27
- - strikethrough
28
- - superscript
29
- - underline
30
- - highlight
31
- - quote
32
- - footnote_ref
33
- - entity
34
- - normal_text
35
- - doc_header
36
- - doc_footer
37
- - preprocess
38
- - postprocess
1
+ keep:
2
+ - autolink
3
+ - block_code
4
+ - block_html
5
+ - block_quote
6
+ - codespan
7
+ - doc_footer
8
+ - doc_header
9
+ - double_emphasis
10
+ - emphasis
11
+ - entity
12
+ - footnote_def
13
+ - footnote_ref
14
+ - footnotes
15
+ - header
16
+ - highlight
17
+ - hrule
18
+ - image
19
+ - linebreak
20
+ - link
21
+ - list
22
+ - list_item
23
+ - normal_text
24
+ - paragraph
25
+ - postprocess
26
+ - preprocess
27
+ - quote
28
+ - raw_html
29
+ - strikethrough
30
+ - superscript
31
+ - table
32
+ - table_cell
33
+ - table_row
34
+ - triple_emphasis
35
+ - underline
@@ -1,3 +1 @@
1
- rules:
2
- skip: true
3
- name: current_user_for_rollbar
1
+ keep: current_user_for_rollbar
@@ -1,8 +1,10 @@
1
1
  test_paths:
2
2
  - /spec/
3
3
 
4
- rules:
5
- - skip: true
4
+ # split into gems too
5
+
6
+ keep:
7
+ - path: /spec/
6
8
  name:
7
9
  # matchers
8
10
  - diffable?
@@ -22,28 +24,31 @@ rules:
22
24
  - dump_summary
23
25
  - seed
24
26
  - close
27
+ dynamic:
25
28
  - name:
26
29
  - have_attributes
27
30
  - has_attributes?
28
31
  - receive_messages
29
32
  calls:
30
- - keys: '*'
33
+ keywords: '**'
34
+ path: /spec/
31
35
  - name:
32
36
  - receive
33
37
  - respond_to
34
38
  calls:
35
- argument: 1
39
+ argument: 0
40
+ path: /spec/
36
41
  - name: define_negated_matcher
37
- defines:
38
- argument: 1
39
- calls:
40
- argument: 2
42
+ defines: 0
43
+ calls: 1
44
+ path: /spec/
41
45
  - name:
42
46
  has_prefix: be_
43
47
  calls:
44
48
  itself: true
45
49
  delete_prefix: be_
46
50
  add_suffix: '?'
51
+ path: /spec/
47
52
  - name:
48
53
  has_prefix: have_
49
54
  calls:
@@ -51,6 +56,9 @@ rules:
51
56
  add_suffix: '?'
52
57
  delete_prefix: have_
53
58
  add_prefix: has_
59
+ path: /spec/
54
60
  - name: let
55
- defines:
56
- argument: 1
61
+ unless:
62
+ has_argument: 1
63
+ defines: 0
64
+ path: /spec/
@@ -1,38 +1,48 @@
1
1
  ---
2
2
  include_paths:
3
- - '*.rb'
4
- - Gemfile
5
- - '*.erb'
3
+ - '#!:ruby'
6
4
  - '*.gemspec'
7
5
  - .irbrc
8
6
  - irb.rc
9
7
  - _irbrc
10
8
  - $irbrc
9
+ - Gemfile
10
+ - '*.erb'
11
+ - '*.rb'
11
12
 
12
13
  test_paths:
13
14
  - /tests/
14
15
  - /test/
15
16
 
16
- rules:
17
- - skip: true
18
- name:
19
- - initialize # called by new
20
- - inspect # called by repl
21
- - respond_to_missing? # called by respond_to?
22
- - method_missing # called by method dispatch
23
- - to_s # called by #{}
24
- - to_ary
25
- - to_str
26
- - <=> # called by Comparable
27
- - each # called by Enumerable
28
- - marshal_dump # called by Marshal.dump
29
- - marshal_load # called by Marshal.load
30
- - _dump # called by Marshal.dump
31
- - _load # called by Marshal.load
32
- - inherited # called by Subclass < Klass or Class.new(Klass)
33
- - extended # called by extend Module
34
- - included # called by include Module
35
- - $VERBOSE # called by whatever is outputting warnings i guess
17
+ keep:
18
+ - initialize # called by new
19
+ - inspect # called by repl, to_s
20
+ - respond_to_missing? # called by respond_to?
21
+ - method_missing # called by method dispatch
22
+ - coerce # called by Numeric
23
+ - to_s # called by "#{}"
24
+ - to_ary # called by Array(), []+
25
+ - to_a # called by Array(), *splat
26
+ - to_str # called by String(), ""+
27
+ - to_hash # called by Hash(), **splat, {}.merge
28
+ - to_int # called by Integer()
29
+ - to_i # called by Integer()
30
+ - to_f # called by Float()
31
+ - <=> # called by Comparable
32
+ - each # called by Enumerable
33
+ - marshal_dump # called by Marshal.dump
34
+ - marshal_load # called by Marshal.load
35
+ - _dump # called by Marshal.dump
36
+ - _load # called by Marshal.load
37
+ - inherited # called by Subclass < Klass or Class.new(Klass)
38
+ - extended # called by extend Module
39
+ - included # called by include Module
40
+ - $VERBOSE # called by whatever is outputting warnings i guess
41
+ - === # called by when
42
+ - == # called by Array value, Hash value equality, ===
43
+ - hash # called by Hash key equality
44
+ - eql? # called by Hash key equality
45
+ dynamic:
36
46
  - name:
37
47
  - send
38
48
  - public_send
@@ -40,8 +50,7 @@ rules:
40
50
  - method
41
51
  - respond_to?
42
52
  - instance_method
43
- calls:
44
- argument: 1
53
+ calls: 0
45
54
  - name: attr_reader
46
55
  defines:
47
56
  argument: '*'
@@ -55,27 +64,21 @@ rules:
55
64
  - name: attr_accessor
56
65
  defines:
57
66
  - argument: '*'
58
- transforms:
59
- - original
60
- - add_suffix: '='
67
+ add_suffix: '='
68
+ - argument: '*'
61
69
  calls:
62
70
  argument: '*'
63
71
  add_prefix: '@'
64
72
  - name: define_method
65
- defines:
66
- argument: 1
73
+ defines: 0
67
74
  - name: alias_method
68
- defines:
69
- argument: 1
70
- calls:
71
- argument: 2
75
+ defines: 0
76
+ calls: 1
72
77
  - name:
73
78
  - instance_variable_get
74
- - class_variable_set
75
- calls:
76
- argument: 1
79
+ - class_variable_get
80
+ calls: 0
77
81
  - name:
78
82
  - instance_variable_set
79
83
  - class_variable_set
80
- defines:
81
- argument: 1
84
+ defines: 0
@@ -0,0 +1,19 @@
1
+ keep:
2
+ - before_navigate_to
3
+ - before_navigate_back
4
+ - after_navigate_back
5
+ - before_navigate_forward
6
+ - after_navigate_forward
7
+ - before_find
8
+ - after_find
9
+ - before_click
10
+ - before_change_value_of
11
+ - after_change_value_of
12
+ - before_execute_script
13
+ - after_execute_script
14
+ - before_quit
15
+ - before_close
16
+ - after_navigate_to
17
+ - after_click
18
+ - after_quit
19
+ - after_close
@@ -0,0 +1,9 @@
1
+ keep: on_complete
2
+ dynamic:
3
+ - names:
4
+ - perform_async
5
+ calls:
6
+ value: perform
7
+ - name: register
8
+ calls:
9
+ argument: 1
@@ -1,14 +1,12 @@
1
- rules:
2
- skip: true
3
- name:
4
- # WillPaginate::ViewHelpers::LinkRenderer
5
- - page_number
6
- - gap
7
- - previous_page
8
- - next_page
9
- - previous_or_next_page
10
- - html_container
11
- - url
12
- - prepare
13
- - to_html
14
- - container_attributes
1
+ keep:
2
+ # WillPaginate::ViewHelpers::LinkRenderer
3
+ - page_number
4
+ - gap
5
+ - previous_page
6
+ - next_page
7
+ - previous_or_next_page
8
+ - html_container
9
+ - url
10
+ - prepare
11
+ - to_html
12
+ - container_attributes
@@ -1,35 +1,51 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './leftovers/core_ext'
4
- require_relative './leftovers/backports'
5
- require_relative './leftovers/collector'
6
- require_relative './leftovers/merged_config'
7
- require_relative './leftovers/reporter'
8
-
9
3
  module Leftovers # rubocop:disable Metrics/ModuleLength
4
+ class Error < ::StandardError; end
5
+
10
6
  module_function
11
7
 
8
+ autoload(:AST, "#{__dir__}/leftovers/ast")
9
+ autoload(:Backports, "#{__dir__}/leftovers/backports")
10
+ autoload(:CLI, "#{__dir__}/leftovers/cli")
11
+ autoload(:Collector, "#{__dir__}/leftovers/collector")
12
+ autoload(:ConfigValidator, "#{__dir__}/leftovers/config_validator")
13
+ autoload(:Config, "#{__dir__}/leftovers/config")
14
+ autoload(:DefinitionSet, "#{__dir__}/leftovers/definition_set")
15
+ autoload(:Definition, "#{__dir__}/leftovers/definition")
16
+ autoload(:ERB, "#{__dir__}/leftovers/erb")
17
+ autoload(:FileCollector, "#{__dir__}/leftovers/file_collector")
18
+ autoload(:FileList, "#{__dir__}/leftovers/file_list")
19
+ autoload(:File, "#{__dir__}/leftovers/file")
20
+ autoload(:Haml, "#{__dir__}/leftovers/haml")
21
+ autoload(:MatcherBuilders, "#{__dir__}/leftovers/matcher_builders")
22
+ autoload(:Matchers, "#{__dir__}/leftovers/matchers")
23
+ autoload(:MergedConfig, "#{__dir__}/leftovers/merged_config")
24
+ autoload(:Parser, "#{__dir__}/leftovers/parser")
25
+ autoload(:ProcessorBuilders, "#{__dir__}/leftovers/processor_builders")
26
+ autoload(:RakeTask, "#{__dir__}/leftovers/rake_task")
27
+ autoload(:Reporter, "#{__dir__}/leftovers/reporter")
28
+ autoload(:DynamicProcessors, "#{__dir__}/leftovers/dynamic_processors")
29
+ autoload(:ValueProcessors, "#{__dir__}/leftovers/value_processors")
30
+ autoload(:VERSION, "#{__dir__}/leftovers/version")
31
+
12
32
  class << self
13
- attr_accessor :parallel
33
+ attr_accessor :parallel, :progress
14
34
  alias_method :parallel?, :parallel
15
35
 
16
- attr_accessor :quiet
17
- alias_method :quiet?, :quiet
18
-
19
- attr_accessor :progress
20
36
  alias_method :progress?, :progress
21
37
  end
22
38
 
23
39
  def stdout
24
- @stdout ||= StringIO.new
40
+ @stdout ||= $stdout
25
41
  end
26
42
 
27
43
  def stderr
28
- @stderr ||= StringIO.new
44
+ @stderr ||= $stderr
29
45
  end
30
46
 
31
47
  def config
32
- @config ||= Leftovers::MergedConfig.new
48
+ @config ||= Leftovers::MergedConfig.new(load_defaults: true)
33
49
  end
34
50
 
35
51
  def collector
@@ -40,24 +56,21 @@ module Leftovers # rubocop:disable Metrics/ModuleLength
40
56
  @reporter ||= Leftovers::Reporter.new
41
57
  end
42
58
 
43
- def leftovers # rubocop:disable Metrics/MethodLength
59
+ def leftovers
44
60
  @leftovers ||= begin
45
61
  collector.collect
46
- collector.definitions.reject do |definition|
47
- definition.skipped? || definition.in_collection?
48
- end
62
+ collector.definitions.reject(&:in_collection?)
49
63
  end
50
64
  end
51
65
 
52
- def run(stdout: StringIO.new, stderr: StringIO.new) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
53
- reset
66
+ def run(stdout: StringIO.new, stderr: StringIO.new) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
54
67
  @stdout = stdout
55
68
  @stderr = stderr
56
69
  return 0 if leftovers.empty?
57
70
 
58
71
  only_test = []
59
72
  none = []
60
- leftovers.sort.each do |definition|
73
+ leftovers.sort_by(&:location_s).each do |definition|
61
74
  if !definition.test? && definition.in_test_collection?
62
75
  only_test << definition
63
76
  else
@@ -78,7 +91,7 @@ module Leftovers # rubocop:disable Metrics/ModuleLength
78
91
  1
79
92
  end
80
93
 
81
- def reset # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
94
+ def reset # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
82
95
  remove_instance_variable(:@config) if defined?(@config)
83
96
  remove_instance_variable(:@collector) if defined?(@collector)
84
97
  remove_instance_variable(:@reporter) if defined?(@reporter)
@@ -87,20 +100,24 @@ module Leftovers # rubocop:disable Metrics/ModuleLength
87
100
  remove_instance_variable(:@stdout) if defined?(@stdout)
88
101
  remove_instance_variable(:@stderr) if defined?(@stderr)
89
102
  remove_instance_variable(:@parallel) if defined?(@parallel)
90
- remove_instance_variable(:@quiet) if defined?(@quiet)
91
103
  remove_instance_variable(:@pwd) if defined?(@pwd)
92
104
  end
93
105
 
94
106
  def warn(message)
95
- stderr.puts("\e[2K#{message}") unless quiet?
107
+ stderr.puts("\e[2K#{message}")
108
+ end
109
+
110
+ def error(message)
111
+ warn(message)
112
+ exit 1
96
113
  end
97
114
 
98
115
  def puts(message)
99
- stdout.puts("\e[2K#{message}") unless quiet?
116
+ stdout.puts("\e[2K#{message}")
100
117
  end
101
118
 
102
119
  def print(message)
103
- stdout.print(message) unless quiet?
120
+ stdout.print(message)
104
121
  end
105
122
 
106
123
  def newline
@@ -111,18 +128,26 @@ module Leftovers # rubocop:disable Metrics/ModuleLength
111
128
  @pwd ||= Pathname.new(Dir.pwd + '/')
112
129
  end
113
130
 
114
- def try_require(*requirables, message: nil) # rubocop:disable Metrics/MethodLength
131
+ def exit(status = 0)
132
+ throw :leftovers_exit, status
133
+ end
134
+
135
+ def try_require(requirable, message: nil) # rubocop:disable Metrics/MethodLength
115
136
  @try_require ||= {}
116
- requirables.each do |requirable|
117
- begin
118
- return @try_require[requirable] if @try_require.key?(requirable)
119
-
120
- @try_require[requirable] = require requirable
121
- rescue LoadError
122
- warn message if message
123
- @try_require[requirable] = false
137
+
138
+ @try_require[requirable] = begin
139
+ if @try_require.key?(requirable)
140
+ @try_require[requirable]
141
+ else
142
+ require requirable
143
+ true
124
144
  end
145
+ rescue LoadError
146
+ false
125
147
  end
148
+
149
+ warn message if !@try_require[requirable] && message
150
+ @try_require[requirable]
126
151
  end
127
152
 
128
153
  def each_or_self(value, &block)
@@ -132,12 +157,4 @@ module Leftovers # rubocop:disable Metrics/ModuleLength
132
157
  else yield(value)
133
158
  end
134
159
  end
135
-
136
- def array_wrap(value)
137
- case value
138
- when nil then [].freeze
139
- when Array then value
140
- else [value]
141
- end
142
- end
143
160
  end