Class: Pinspec::Batch

Inherits:
Object
  • Object
show all
Defined in:
lib/pinspec/batch.rb

Defined Under Namespace

Classes: Outcome, Report

Constant Summary collapse

SKIP_PATTERNS =
[%r{/concerns/}, %r{_spec\.rb\z}, %r{/spec/}, %r{/test/}].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files, &pin) ⇒ Batch

Returns a new instance of Batch.



50
51
52
53
# File 'lib/pinspec/batch.rb', line 50

def initialize(files, &pin)
  @files = files
  @pin = pin
end

Class Method Details

.targets_in(path) ⇒ Object

Patterns match the path RELATIVE to the directory being pinned. Matching the absolute path means an app that happens to live under a directory called spec has every one of its files skipped.



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pinspec/batch.rb', line 38

def self.targets_in(path)
  return [path] if File.file?(path)

  root = File.expand_path(path)

  Dir.glob(File.join(root, "**", "*.rb")).reject do |file|
    relative = file.delete_prefix("#{root}/")

    SKIP_PATTERNS.any? { |pattern| "/#{relative}".match?(pattern) }
  end.sort
end

Instance Method Details

#runObject

A refusal is information, not a stop: one target that takes a block must not end a run over a directory of forty.



57
58
59
# File 'lib/pinspec/batch.rb', line 57

def run
  Report.new(outcomes: @files.map { |file| attempt(file) })
end