Class: Leftovers::Collector
- Inherits:
-
Object
- Object
- Leftovers::Collector
- Defined in:
- lib/leftovers/collector.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#parallel ⇒ Object
writeonly
Sets the attribute parallel.
-
#progress ⇒ Object
writeonly
Sets the attribute progress.
Instance Method Summary collapse
- #collect ⇒ Object
- #collect_file(file) ⇒ Object
- #collect_file_list(list) ⇒ Object
- #finish_file(_item, _index, result) ⇒ Object
-
#initialize ⇒ Collector
constructor
A new instance of Collector.
- #progress_message ⇒ Object
Constructor Details
#initialize ⇒ Collector
Returns a new instance of Collector.
13 14 15 16 17 18 19 20 |
# File 'lib/leftovers/collector.rb', line 13 def initialize @count = 0 @count_calls = 0 @count_definitions = 0 @progress = true @parallel = true @collection ||= Collection.new end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
11 12 13 |
# File 'lib/leftovers/collector.rb', line 11 def collection @collection end |
#parallel=(value) ⇒ Object (writeonly)
Sets the attribute parallel
10 11 12 |
# File 'lib/leftovers/collector.rb', line 10 def parallel=(value) @parallel = value end |
#progress=(value) ⇒ Object (writeonly)
Sets the attribute progress
10 11 12 |
# File 'lib/leftovers/collector.rb', line 10 def progress=(value) @progress = value end |
Instance Method Details
#collect ⇒ Object
22 23 24 25 |
# File 'lib/leftovers/collector.rb', line 22 def collect collect_file_list(FileList.new) ::Leftovers.puts end |
#collect_file(file) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/leftovers/collector.rb', line 37 def collect_file(file) file_collector = FileCollector.new(file.ruby, file) file_collector.collect file_collector.to_h end |
#collect_file_list(list) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/leftovers/collector.rb', line 27 def collect_file_list(list) if @parallel ::Parallel.each(list, finish: method(:finish_file)) do |file| collect_file(file) end else list.each { |file| finish_file(nil, nil, collect_file(file)) } end end |
#finish_file(_item, _index, result) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/leftovers/collector.rb', line 48 def finish_file(_item, _index, result) @count += 1 @count_calls += result[:calls].length @count_definitions += result[:definitions].length ::Leftovers.print() if @progress @collection.concat(**result) end |
#progress_message ⇒ Object
44 45 46 |
# File 'lib/leftovers/collector.rb', line 44 def "checked #{@count} files, collected #{@count_calls} calls, #{@count_definitions} definitions" end |