Sha256: ca9913e3b156ca7149f09e428b3e2ec3611d458b9d735db653c0140f580391f4

Contents?: true

Size: 944 Bytes

Versions: 8

Compression:

Stored size: 944 Bytes

Contents

module Gumdrop::Util

  class Scanner
    include Loggable

    attr_reader :options

    def initialize(base_path, opts={}, &block)
      @source_glob= base_path / "**" / "*"
      @options= opts
      @src_path= base_path
      @validator= block || method(:_default_validator)
    end

    def each
      Dir.glob(@source_glob, File::FNM_DOTMATCH).each do |path|
        rel_path= _relative(path)
        unless should_skip? rel_path, path
          yield path, rel_path
        else
          log.debug " excluding: #{ rel_path }"
        end
      end
    end

    def should_skip?(path, full_path)
      return true if File.directory?(full_path)
      @validator.call(path, full_path) || false
    end

  private

    def _default_validator(src,full)
      true
    end

    def _relative(path)
      relpath= path.gsub @src_path, ''
      if relpath[0]== '/'
        relpath[1..-1]
      else
        relpath
      end
    end
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gumdrop-1.1.3 lib/gumdrop/util/scanner.rb
gumdrop-1.1.2 lib/gumdrop/util/scanner.rb
gumdrop-1.1.1 lib/gumdrop/util/scanner.rb
gumdrop-1.1.0 lib/gumdrop/util/scanner.rb
gumdrop-1.0.3 lib/gumdrop/util/scanner.rb
gumdrop-1.0.2 lib/gumdrop/util/scanner.rb
gumdrop-1.0.1 lib/gumdrop/util/scanner.rb
gumdrop-1.0.0 lib/gumdrop/util/scanner.rb