Class: Sorbet::Eraser::CLI
- Inherits:
-
Object
- Object
- Sorbet::Eraser::CLI
- Defined in:
- lib/sorbet/eraser/cli.rb
Overview
A small CLI that takes filepaths and erases them by writing back to the original file.
Constant Summary collapse
- POOL_SIZE =
4
Instance Attribute Summary collapse
-
#filepaths ⇒ Object
readonly
Returns the value of attribute filepaths.
-
#verify ⇒ Object
readonly
Returns the value of attribute verify.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(verify, filepaths) ⇒ CLI
constructor
A new instance of CLI.
- #start ⇒ Object
Constructor Details
#initialize(verify, filepaths) ⇒ CLI
Returns a new instance of CLI.
12 13 14 15 |
# File 'lib/sorbet/eraser/cli.rb', line 12 def initialize(verify, filepaths) @verify = verify @filepaths = filepaths end |
Instance Attribute Details
#filepaths ⇒ Object (readonly)
Returns the value of attribute filepaths.
10 11 12 |
# File 'lib/sorbet/eraser/cli.rb', line 10 def filepaths @filepaths end |
#verify ⇒ Object (readonly)
Returns the value of attribute verify.
10 11 12 |
# File 'lib/sorbet/eraser/cli.rb', line 10 def verify @verify end |
Class Method Details
.start(argv) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sorbet/eraser/cli.rb', line 38 def self.start(argv) verify = false if argv.first == "--verify" verify = true argv.shift end filepaths = [] argv.each { |pattern| filepaths.concat(Dir.glob(pattern)) } new(verify, filepaths).start end |
Instance Method Details
#start ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sorbet/eraser/cli.rb', line 17 def start queue = Queue.new filepaths.each { |filepath| queue << filepath } workers = POOL_SIZE.times.map do # push a symbol onto the queue for each thread so that it knows when # the end of the queue is and will exit its infinite loop queue << :eoq Thread.new do while filepath = queue.shift break if filepath == :eoq process(filepath) end end.tap { |thread| thread.abort_on_exception = true } end workers.each(&:join) end |