Class: Lumin::Runner
- Inherits:
-
Object
- Object
- Lumin::Runner
- Defined in:
- lib/lumin/runner.rb
Defined Under Namespace
Classes: RunResult
Constant Summary collapse
- AUTO_PARALLEL_MIN_BYTES =
256 * 1024
- AUTO_WORKER_SCALE_BYTES =
32 * 1024
Instance Method Summary collapse
- #clear_cache ⇒ Object
-
#initialize(config:, registry: Registry, parallel: nil, cache: true, cache_dir: nil) ⇒ Runner
constructor
A new instance of Runner.
- #run(paths = [], fix: false, unsafe: false, dry_run: false) ⇒ Object
Constructor Details
#initialize(config:, registry: Registry, parallel: nil, cache: true, cache_dir: nil) ⇒ Runner
Returns a new instance of Runner.
15 16 17 18 19 20 21 22 |
# File 'lib/lumin/runner.rb', line 15 def initialize(config:, registry: Registry, parallel: nil, cache: true, cache_dir: nil) @config = config @registry = registry @parallel = parallel @cache_enabled = cache @cache_dir = cache_dir @cache = build_cache if @cache_enabled end |
Instance Method Details
#clear_cache ⇒ Object
24 25 26 |
# File 'lib/lumin/runner.rb', line 24 def clear_cache cache.clear end |
#run(paths = [], fix: false, unsafe: false, dry_run: false) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lumin/runner.rb', line 28 def run(paths = [], fix: false, unsafe: false, dry_run: false) files = enumerate(paths) cached_results, pending = load_cached(files, use_cache: @cache_enabled && !fix) executed_results = execute(pending, fix: fix, unsafe: unsafe, dry_run: dry_run) results = cached_results + executed_results if @cache_enabled && !dry_run store_results(executed_results) cache.flush end ordered = results.sort_by(&:path) RunResult.new( offenses: ordered.flat_map(&:offenses).sort_by { |offense| offense_key(offense) }.freeze, diffs: ordered.filter_map(&:diff).freeze, warnings: ordered.flat_map(&:warnings).freeze, errors: ordered.filter_map { |result| "#{result.path}: #{result.error}" if result.error }.freeze, files: files.freeze ) end |