class Rubble::Resource::Directory

Attributes

excludes[R]
includes[R]

Public Class Methods

new(name) click to toggle source
# File lib/rubble/resource/fileset.rb, line 13
def initialize(name)
    @name = name
    @includes = []
    @excludes = []
    @default_includes = ['**/*']
    @default_excludes = ['**/*~', '**/#*#']
    @flags = File::FNM_PATHNAME
end

Public Instance Methods

get_fileset() click to toggle source
# File lib/rubble/resource/fileset.rb, line 42
def get_fileset
    files = []
    dir = Pathname.new(@name)

    Find.find(dir) do |path|
        pathname = Pathname.new(path).relative_path_from(dir).to_s

        if pathname != '.' then
            match = (@includes.empty? ? @default_includes : @includes).any? {|p| File.fnmatch?(p, pathname, @flags)}
            match = match and not (@excludes.empty? ? @default_excludes : @excludes).any? {|p| File.fnmatch?(p, pathname, @flags)}

            if match then
                if not File.directory?(path) then
                    files << pathname
                end
            else
                if File.directory?(path) then
                    Find.prune
                end
            end
        end
    end

    FileSet.new(dir.to_s, files)
end
hidden(*values) click to toggle source
# File lib/rubble/resource/fileset.rb, line 30
def hidden(*values)
    if values.empty? then
        (@flags & File.FNM_DOTMATCH) != 0
    else
        if values[0] then
            @flags |= File.FNM_DOTMATCH
        else
            @flags &= ~File.FNM_DOTMATCH
        end
    end
end