find 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/test.yml +24 -0
- data/.gitignore +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +53 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/find.gemspec +24 -0
- data/lib/find.rb +88 -0
- metadata +56 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d0857dc7c07577e14e5f768901d903c139620bfbc72bb8ccad29f1166333694f
|
4
|
+
data.tar.gz: 245fe328e0724879fa5019851a1e0bfe99163692681466105f155a10b6909d65
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3d3bbc65a7576629d123e074ef564deb1395263766cf2db901e28cd63e571ca2a5c61bb16de536a85d86f924a81106efca28c69e74f432d0830f7855de2f69bc
|
7
|
+
data.tar.gz: cfec8fd431bfaac5ebab2fe7b81fc41467de7f569a9b2cf9f6f01876ee11efc8466c008b6627a5006e5a230b8c8dd98f6e770cee4816fe7c37ad936f399c0d99
|
@@ -0,0 +1,24 @@
|
|
1
|
+
name: test
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
|
8
|
+
strategy:
|
9
|
+
matrix:
|
10
|
+
ruby: [ 2.7, 2.6, 2.5, head ]
|
11
|
+
os: [ ubuntu-latest, macos-latest ]
|
12
|
+
runs-on: ${{ matrix.os }}
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@master
|
15
|
+
- name: Set up Ruby
|
16
|
+
uses: ruby/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: ${{ matrix.ruby }}
|
19
|
+
- name: Install dependencies
|
20
|
+
run: |
|
21
|
+
gem install bundler --no-document
|
22
|
+
bundle install
|
23
|
+
- name: Run test
|
24
|
+
run: rake test
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions
|
5
|
+
are met:
|
6
|
+
1. Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
2. Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
13
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
14
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
15
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
16
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
17
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
18
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
19
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
20
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
21
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
22
|
+
SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Find
|
2
|
+
|
3
|
+
The +Find+ module supports the top-down traversal of a set of file paths.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'find'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install find
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
For example, to total the size of all files under your home directory,
|
24
|
+
ignoring anything in a "dot" directory (e.g. $HOME/.ssh):
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require 'find'
|
28
|
+
|
29
|
+
total_size = 0
|
30
|
+
|
31
|
+
Find.find(ENV["HOME"]) do |path|
|
32
|
+
if FileTest.directory?(path)
|
33
|
+
if File.basename(path).start_with?('.')
|
34
|
+
Find.prune # Don't look any further into this directory.
|
35
|
+
else
|
36
|
+
next
|
37
|
+
end
|
38
|
+
else
|
39
|
+
total_size += FileTest.size(path)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
## Development
|
45
|
+
|
46
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
47
|
+
|
48
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/find.
|
53
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "find"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/find.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "find"
|
3
|
+
spec.version = "0.1.0"
|
4
|
+
spec.authors = ['Kazuki Tsujimoto']
|
5
|
+
spec.email = ['kazuki@callcc.net']
|
6
|
+
|
7
|
+
spec.summary = %q{This module supports top-down traversal of a set of file paths.}
|
8
|
+
spec.description = %q{This module supports top-down traversal of a set of file paths.}
|
9
|
+
spec.homepage = "https://github.com/ruby/find"
|
10
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
11
|
+
spec.licenses = ["Ruby", "BSD-2-Clause"]
|
12
|
+
|
13
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
14
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
end
|
data/lib/find.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# find.rb: the Find module for processing all files under a given directory.
|
4
|
+
#
|
5
|
+
|
6
|
+
#
|
7
|
+
# The +Find+ module supports the top-down traversal of a set of file paths.
|
8
|
+
#
|
9
|
+
# For example, to total the size of all files under your home directory,
|
10
|
+
# ignoring anything in a "dot" directory (e.g. $HOME/.ssh):
|
11
|
+
#
|
12
|
+
# require 'find'
|
13
|
+
#
|
14
|
+
# total_size = 0
|
15
|
+
#
|
16
|
+
# Find.find(ENV["HOME"]) do |path|
|
17
|
+
# if FileTest.directory?(path)
|
18
|
+
# if File.basename(path).start_with?('.')
|
19
|
+
# Find.prune # Don't look any further into this directory.
|
20
|
+
# else
|
21
|
+
# next
|
22
|
+
# end
|
23
|
+
# else
|
24
|
+
# total_size += FileTest.size(path)
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
module Find
|
29
|
+
|
30
|
+
#
|
31
|
+
# Calls the associated block with the name of every file and directory listed
|
32
|
+
# as arguments, then recursively on their subdirectories, and so on.
|
33
|
+
#
|
34
|
+
# Returns an enumerator if no block is given.
|
35
|
+
#
|
36
|
+
# See the +Find+ module documentation for an example.
|
37
|
+
#
|
38
|
+
def find(*paths, ignore_error: true) # :yield: path
|
39
|
+
block_given? or return enum_for(__method__, *paths, ignore_error: ignore_error)
|
40
|
+
|
41
|
+
fs_encoding = Encoding.find("filesystem")
|
42
|
+
|
43
|
+
paths.collect!{|d| raise Errno::ENOENT, d unless File.exist?(d); d.dup}.each do |path|
|
44
|
+
path = path.to_path if path.respond_to? :to_path
|
45
|
+
enc = path.encoding == Encoding::US_ASCII ? fs_encoding : path.encoding
|
46
|
+
ps = [path]
|
47
|
+
while file = ps.shift
|
48
|
+
catch(:prune) do
|
49
|
+
yield file.dup
|
50
|
+
begin
|
51
|
+
s = File.lstat(file)
|
52
|
+
rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
|
53
|
+
raise unless ignore_error
|
54
|
+
next
|
55
|
+
end
|
56
|
+
if s.directory? then
|
57
|
+
begin
|
58
|
+
fs = Dir.children(file, encoding: enc)
|
59
|
+
rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
|
60
|
+
raise unless ignore_error
|
61
|
+
next
|
62
|
+
end
|
63
|
+
fs.sort!
|
64
|
+
fs.reverse_each {|f|
|
65
|
+
f = File.join(file, f)
|
66
|
+
ps.unshift f
|
67
|
+
}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
nil
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# Skips the current file or directory, restarting the loop with the next
|
77
|
+
# entry. If the current file is a directory, that directory will not be
|
78
|
+
# recursively entered. Meaningful only within the block associated with
|
79
|
+
# Find::find.
|
80
|
+
#
|
81
|
+
# See the +Find+ module documentation for an example.
|
82
|
+
#
|
83
|
+
def prune
|
84
|
+
throw :prune
|
85
|
+
end
|
86
|
+
|
87
|
+
module_function :find, :prune
|
88
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: find
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kazuki Tsujimoto
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-18 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This module supports top-down traversal of a set of file paths.
|
14
|
+
email:
|
15
|
+
- kazuki@callcc.net
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".github/workflows/test.yml"
|
21
|
+
- ".gitignore"
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- bin/console
|
27
|
+
- bin/setup
|
28
|
+
- find.gemspec
|
29
|
+
- lib/find.rb
|
30
|
+
homepage: https://github.com/ruby/find
|
31
|
+
licenses:
|
32
|
+
- Ruby
|
33
|
+
- BSD-2-Clause
|
34
|
+
metadata:
|
35
|
+
homepage_uri: https://github.com/ruby/find
|
36
|
+
source_code_uri: https://github.com/ruby/find
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.3.0
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubygems_version: 3.1.2
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
55
|
+
summary: This module supports top-down traversal of a set of file paths.
|
56
|
+
test_files: []
|