Class: Lookbook::EventedFileUpdateChecker

Inherits:
ActiveSupport::EventedFileUpdateChecker
  • Object
show all
Defined in:
lib/lookbook/support/evented_file_update_checker.rb

Defined Under Namespace

Classes: Core

Instance Method Summary collapse

Constructor Details

#initialize(files, dirs = {}, &block) ⇒ EventedFileUpdateChecker

Returns a new instance of EventedFileUpdateChecker.



9
10
11
12
# File 'lib/lookbook/support/evented_file_update_checker.rb', line 9

def initialize(files, dirs = {}, &block)
  super
  @core = Core.new(files, dirs)
end

Instance Method Details

#watching?(file) ⇒ Boolean

Patched to handle regex-style extension matchers like ‘.html.*`

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/lookbook/support/evented_file_update_checker.rb', line 44

def watching?(file)
  return true if super

  file = Pathname(file)
  name_parts = file.basename.to_s.split(".")
  ext = "." + name_parts.drop(1).join(".").to_s

  file.dirname.ascend do |dir|
    matching = @dirs.fetch(dir, []).map { |m| Regexp.new(m) }
    if matching.empty? || matching.find { |m| m.match?(ext) }
      break true
    elsif dir == @lcsp || dir.root?
      break false
    end
  end
end