Class: Specwrk::Watcher::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/specwrk/watcher.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default_config = true) ⇒ Config

Returns a new instance of Config.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/specwrk/watcher.rb', line 16

def initialize(default_config = true)
  if default_config
    @mappings = [
      [/_spec\.rb$/, proc { |changed_file_path| changed_file_path }]
    ]

    @ignore_patterns = [/^(?!.*\.rb$).+/]
  else
    @mappings = []
    @ignore_patterns = []
  end
end

Class Method Details

.load(file) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/specwrk/watcher.rb', line 8

def self.load(file)
  if file && File.exist?(file)
    new(false).tap { |instance| instance.instance_eval(File.read(file), file, 1) }
  else
    new
  end
end

Instance Method Details

#ignore(*patterns) ⇒ Object



33
34
35
# File 'lib/specwrk/watcher.rb', line 33

def ignore(*patterns)
  @ignore_patterns.concat(patterns)
end

#map(pattern, &block) ⇒ Object



29
30
31
# File 'lib/specwrk/watcher.rb', line 29

def map(pattern, &block)
  @mappings << [pattern, block]
end

#spec_files_for(path) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/specwrk/watcher.rb', line 37

def spec_files_for(path)
  return [] if @ignore_patterns.any? { |pattern| pattern.match? path }

  @mappings.map do |pattern, block|
    next unless pattern.match? path

    block.call(path)
  end.flatten.compact.uniq
end