Class: Lookbook::Reloaders::Reloader

Inherits:
Object
  • Object
show all
Defined in:
lib/lookbook/reloaders.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, directories, extensions, &callback) ⇒ Reloader

Returns a new instance of Reloader.



40
41
42
43
44
45
46
# File 'lib/lookbook/reloaders.rb', line 40

def initialize(name, directories, extensions, &callback)
  @name = name.to_sym
  @directories = directories
  @extensions = extensions
  @callback = callback
  @last_changes = nil
end

Instance Attribute Details

#callbackObject (readonly)



37
38
39
# File 'lib/lookbook/reloaders.rb', line 37

def callback
  @callback
end

#directoriesObject (readonly)



37
38
39
# File 'lib/lookbook/reloaders.rb', line 37

def directories
  @directories
end

#extensionsObject (readonly)



37
38
39
# File 'lib/lookbook/reloaders.rb', line 37

def extensions
  @extensions
end

#last_changesObject



38
39
40
# File 'lib/lookbook/reloaders.rb', line 38

def last_changes
  @last_changes
end

#nameObject (readonly)



37
38
39
# File 'lib/lookbook/reloaders.rb', line 37

def name
  @name
end

Instance Method Details

#watching?(changes) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
56
57
# File 'lib/lookbook/reloaders.rb', line 48

def watching?(changes)
  file_paths = changes.to_h.values.flatten
  !!file_paths.find do |file_path|
    file_path = Pathname(file_path).expand_path
    directories.find do |dir_path|
      matcher = File.expand_path(File.join(dir_path, "**"))
      file_path.fnmatch?(matcher)
    end
  end
end