Class: Guard::Compat::Test::Template::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/guard/compat/test/template.rb

Defined Under Namespace

Classes: GlobalWatchesNotImplemented, MultipleGuardNotImplemented

Instance Method Summary collapse

Constructor Details

#initialize(path, content) ⇒ Session

Returns a new instance of Session.



18
19
20
21
22
# File 'lib/guard/compat/test/template.rb', line 18

def initialize(path, content)
  @watches = {}
  @current = nil
  instance_eval(content, path, 1)
end

Instance Method Details

#guard(name, _options = {}) ⇒ Object



31
32
33
34
35
36
# File 'lib/guard/compat/test/template.rb', line 31

def guard(name, _options = {})
  @current = name
  @watches[@current] = []
  yield
  @current = nil
end

#match(file) ⇒ Object



24
25
26
27
28
29
# File 'lib/guard/compat/test/template.rb', line 24

def match(file)
  _watches.map do |expr, block|
    next unless (match = file.match(expr))
    block.nil? ? [file] : block.call([file] + match.captures)
  end.flatten.compact.uniq
end

#watch(expr, &block) ⇒ Object



38
39
40
# File 'lib/guard/compat/test/template.rb', line 38

def watch(expr, &block)
  @watches[@current] << [expr, block]
end