Sha256: 395f48f05d7b65b8992b0f2e2ed81f9bd3b96028f58a3ff920fe6b3726bc2ec1

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

module Path
  def directory?
    return nil unless self.exist?
    File.directory?(self.find)
  end

  def dirname
    self.annotate(File.dirname(self))
  end

  def basename
    self.annotate(File.basename(self))
  end


  def glob(pattern = '*')
    if self.include? "*"
      self.glob_all
    else
      return [] unless self.exist? 
      found = self.find
      exp = File.join(found, pattern)
      paths = Dir.glob(exp).collect{|f| self.annotate(f) }

      paths.each do |p|
        p.original = File.join(found.original, p.sub(/^#{found}/, ''))
      end if found.original

      paths
    end
  end

  def glob_all(pattern = nil, caller_lib = nil, search_paths = nil)
    search_paths ||= Path.search_paths
    search_paths = search_paths.dup

    location_paths = {}
    search_paths.keys.collect do |where| 
      found = find(where, Path.caller_lib_dir, search_paths)
      paths = pattern ? Dir.glob(File.join(found, pattern)) : Dir.glob(found) 

      paths = paths.collect{|p| self.annotate p }

      paths = paths.each do |p|
        p.original = File.join(found.original, p.sub(/^#{found}/, ''))
        p.where = where
      end if found.original and pattern

      location_paths[where] = paths
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scout-gear-1.2.0 lib/scout/path/util.rb