Module: Dotsmack

Defined in:
lib/version.rb,
lib/dotsmack.rb

Overview

Dotsmack - File, dotignore, and dotconfig scanner.

Scans for files recursively.

Searches for dotfiles in:

  • The same directory as path
  • An ancestor directory, up to $HOME
  • If path is not $HOME-relative, search only $HOME

dotignore assumes fnmatch format. dotconfig may be in any format.

Defined Under Namespace

Classes: Smacker

Constant Summary collapse

VERSION =
'0.5'
HOME =
File.expand_path(ENV['HOME'])
PARENT_OF_HOME =
File.expand_path('..', HOME)
FNMATCH_FLAGS =
File::FNM_DOTMATCH | # Allow matching on Unix hidden dotfiles
File::FNM_EXTGLOB

Class Method Summary collapse

Class Method Details

.fnmatch?(pattern, path) ⇒ Boolean

More intuitive behavior for fnmatch

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/dotsmack.rb', line 31

def self.fnmatch?(pattern, path)
  # Assume non-directory path
  if File.fnmatch(pattern, path, FNMATCH_FLAGS) ||
      File.fnmatch("**#{File::SEPARATOR}#{pattern}", path, FNMATCH_FLAGS)
    true
  # Consider path as directory
  else
    path =
      if path.end_with?(File::SEPARATOR)
        path
      else
        "#{path}#{File::SEPARATOR}"
      end

    pattern =
      if pattern.end_with?(File::SEPARATOR)
        "#{pattern}*"
      else
        "#{pattern}#{File::SEPARATOR}*"
      end

    File.fnmatch(pattern, path, FNMATCH_FLAGS) ||
      File.fnmatch("**#{File::SEPARATOR}#{pattern}", path, FNMATCH_FLAGS)
  end
end