Sha256: 86e702c1276cfea2674fcb523ff6e43aabf629877153e8ff8b37abd76b677754

Contents?: true

Size: 732 Bytes

Versions: 4

Compression:

Stored size: 732 Bytes

Contents

require_relative 'fshelpyhelp'
require_relative 'file'

module Stowaway
  class Locator
    include FSHelpyHelp
  
    def initialize(extensions)
      @extensions = extensions
      @ignore = [/^\./]
    end
  
    def type?(file)
      @extensions.each do |e|
        return true if file.match(/#{e}$/)
      end
      false
    end
  
    def find_all(path, files = [])
      @root = path if @root.nil?

      dir = Dir.new(path)
    
      dir.each do |f|
        next if ignore?(f)
        
        file = File.join(dir.path, f)
        
        if File.directory?(file) 
          find_all file, files
        elsif type?(f)
          files << FileObj.new(file, @root)
        end
      end
      files
    end
    
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
stowaway-0.1.9 lib/stowaway/locator.rb
stowaway-0.1.8 lib/stowaway/locator.rb
stowaway-0.1.6 lib/stowaway/locator.rb
stowaway-0.1.5 lib/stowaway/locator.rb