Sha256: 4033a6efaa6b806ac2cca2db7def09aaba970133b3d7452884adcc4e96122ac9

Contents?: true

Size: 1016 Bytes

Versions: 1

Compression:

Stored size: 1016 Bytes

Contents

module FS
  module Find

    # Find::find
    def find(dir, options={}, &block)
      defaults = {
        :current => false,
        :absolute => false,
        :condition => nil
      }
      options = defaults.merge(options)

      result = []

      full_dir = File.expand_path(dir)
      ::Find.find(dir) do |full_path|
        next if !options[:current] && full_path == full_dir
        path = options[:absolute] ? full_path : FS.chop(full_path, full_dir)
        next if options[:condition] && !options[:condition][path]

        if block
          block[path]
        else
          result << path
        end
      end

      block ? nil : result
    end

    def find_dirs(dir, options={}, &block)
      condition = ->(path){FileTest.directory?(path)}
      find(dir, options.merge(:condition => condition), &block)
    end

    def find_files(dir, options={}, &block)
      condition = ->(path){!FileTest.directory?(path)}
      find(dir, options.merge(:condition => condition), &block)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fs-0.2.0 lib/fs/find.rb