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.



36
37
38
39
40
41
42
# File 'lib/lookbook/reloaders.rb', line 36

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)



33
34
35
# File 'lib/lookbook/reloaders.rb', line 33

def callback
  @callback
end

#directoriesObject (readonly)



33
34
35
# File 'lib/lookbook/reloaders.rb', line 33

def directories
  @directories
end

#extensionsObject (readonly)



33
34
35
# File 'lib/lookbook/reloaders.rb', line 33

def extensions
  @extensions
end

#last_changesObject



34
35
36
# File 'lib/lookbook/reloaders.rb', line 34

def last_changes
  @last_changes
end

#nameObject (readonly)



33
34
35
# File 'lib/lookbook/reloaders.rb', line 33

def name
  @name
end

Instance Method Details

#watching?(changes) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
52
53
# File 'lib/lookbook/reloaders.rb', line 44

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