file-visitor 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a90c3de765cb74ab492da1d8ded9a60843f268c2
4
+ data.tar.gz: 6f0df4e777c51f4b87729a4d7038dd039bead761
5
+ SHA512:
6
+ metadata.gz: 02b9f326d9c5d563836e9bf8609b9a6c0d106a81f65c58e60f667940e70b75eb137291b168354c4421bf92718aa0b4abb2dbe80370af9681d3a237f9b1b1e34a
7
+ data.tar.gz: 9f1ba5f1bf647649779d154a3d5525c0969d32d60225deb93cafaba10f106b213c4ce76b35d38dd7aeb64df2af301f4c2c043cb1161e069aa92aedd9084fb53d
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/
data/.rspec CHANGED
@@ -1 +1,2 @@
1
+ --format documentation
1
2
  --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at bonar@me.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile CHANGED
@@ -1,12 +1,11 @@
1
- source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in file-visitor.gemspec
4
+ gemspec
5
5
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
6
  group :development do
9
- gem "rspec", "~> 2.8.0"
10
- gem "rdoc", "~> 3.12"
11
- gem "jeweler", "~> 1.8.4"
7
+ gem 'rspec-core'
8
+ gem 'rspec-expectations'
9
+ gem 'rspec-mocks'
10
+ gem 'rspec-support'
12
11
  end
@@ -1,30 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ file-visitor (0.1.1)
5
+
1
6
  GEM
2
- remote: http://rubygems.org/
7
+ remote: https://rubygems.org/
3
8
  specs:
4
- diff-lcs (1.1.3)
5
- git (1.2.5)
6
- jeweler (1.8.4)
7
- bundler (~> 1.0)
8
- git (>= 1.2.5)
9
- rake
10
- rdoc
11
- json (1.7.5)
12
- rake (0.9.2.2)
13
- rdoc (3.12)
14
- json (~> 1.4)
15
- rspec (2.8.0)
16
- rspec-core (~> 2.8.0)
17
- rspec-expectations (~> 2.8.0)
18
- rspec-mocks (~> 2.8.0)
19
- rspec-core (2.8.0)
20
- rspec-expectations (2.8.0)
21
- diff-lcs (~> 1.1.2)
22
- rspec-mocks (2.8.0)
9
+ diff-lcs (1.2.5)
10
+ rake (11.1.2)
11
+ rspec (3.4.0)
12
+ rspec-core (~> 3.4.0)
13
+ rspec-expectations (~> 3.4.0)
14
+ rspec-mocks (~> 3.4.0)
15
+ rspec-core (3.4.4)
16
+ rspec-support (~> 3.4.0)
17
+ rspec-expectations (3.4.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.4.0)
20
+ rspec-mocks (3.4.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.4.0)
23
+ rspec-support (3.4.1)
23
24
 
24
25
  PLATFORMS
25
26
  ruby
26
27
 
27
28
  DEPENDENCIES
28
- jeweler (~> 1.8.4)
29
- rdoc (~> 3.12)
30
- rspec (~> 2.8.0)
29
+ bundler
30
+ file-visitor!
31
+ rake
32
+ rspec
33
+ rspec-core
34
+ rspec-expectations
35
+ rspec-mocks
36
+ rspec-support
37
+
38
+ BUNDLED WITH
39
+ 1.11.2
@@ -0,0 +1,167 @@
1
+ # File::Visitor
2
+
3
+ file path collectiong utility
4
+
5
+ ## DESCRIPTION
6
+
7
+ file-visitor is an alternative way to collecting files.
8
+ We often write code to collect file, like this.
9
+
10
+ Dir.glob("/usr/local/lib/*.a")
11
+
12
+ Dir.glob or UNIX find command is very useful.
13
+ But in the following cases, it is not enough.
14
+
15
+ * need to combine various conditions.
16
+ * need to write the conditions of the file path to collect by ruby.
17
+ * need to test and reuse conditions.
18
+
19
+ file-visitor way to collect files
20
+
21
+ require 'file/visitor'
22
+
23
+ visitor = File::Visitor.new
24
+
25
+ # files with extension .log
26
+ visitor.add_filter(:ext, :log)
27
+
28
+ # and last modified is more than 30 days ago
29
+ visitor.add_filter(:mtime, :passed, 30, :days)
30
+
31
+ # remove all the matched files
32
+ visitor.visit(root_dir) do |path|
33
+ FileUtils.rm(path)
34
+ end
35
+
36
+ You can add custom filters.
37
+
38
+ class BigFileFilter
39
+
40
+ def initialize(size)
41
+ @size = size
42
+ end
43
+
44
+ # filter must implement match?(path)
45
+ def match?(path)
46
+ File.size(path) > @size
47
+ end
48
+
49
+ end
50
+
51
+ filter = BigFileFilter(2048)
52
+ visitor.add_filter(filter)
53
+
54
+ BigFileFilter is testable and reusable.
55
+
56
+ ### Filters
57
+
58
+ #### Filename
59
+
60
+ filename string or regexp.
61
+
62
+ visitor.add_filter(:filename, "sample.txt")
63
+ visitor.add_filter(:filename. /\d{4}\-\d{2}\-\d{2}\.txt/)
64
+
65
+ #### Extension
66
+
67
+ file extension sym or string.
68
+
69
+ visitor.add_filter(:ext, :txt)
70
+
71
+ #### Modified time
72
+
73
+ # 1. specify Time instance
74
+ # add_filter(:mtime, comparetor_sym, time)
75
+ visitor.add_filter(:mtime, :equals_to, Time.parse("2013-01-03 04:59"))
76
+ visitor.add_filter(:mtime, :is_less_than, Time.parse("2013-01-03 04:59"))
77
+
78
+ # 2 specify number and unit sym
79
+ # add_filter(:mtime, :passed, number, time_unit)
80
+ visitor.add_filter(:mtime, :passed, 3, :days)
81
+
82
+ Comparator syms you can use:
83
+
84
+ * :equals_to (:==)
85
+ * :is_greater_than (:is_younger_than, :>)
86
+ * :is_greater_than= (:is_younger_than=, :>=)
87
+ * :is_less_than (:is_older_than, :<)
88
+ * :is_less_than= (:is_older_than=, :<=)
89
+
90
+ Time unit
91
+
92
+ * :sec, :second, :seconds
93
+ * :min, :mins, :minute, :minutes
94
+ * :hour, :hours
95
+ * :day, :days
96
+ * :month, :months (1 month = 30 days)
97
+ * :year, :years
98
+
99
+ #### Block filter
100
+
101
+ visitor.add_filter do |path|
102
+ # return true/false
103
+ end
104
+
105
+ #### custom filter
106
+
107
+ class HaveMD5SumFilter
108
+ def match?(path)
109
+ File.readable?("#{path}.md5")
110
+ end
111
+ end
112
+
113
+ filter = HaveMD5SumFilter.new
114
+ visitor.add_filter(filter)
115
+
116
+ filter instance must repond_to :match?.
117
+
118
+ ### methods
119
+
120
+ #### visit(dir)
121
+
122
+ Collect files and execute given block.
123
+
124
+ #### file_list(dir)
125
+
126
+ Collect files and return path array.
127
+
128
+ #### target?(path)
129
+
130
+ return if the given path is target.
131
+
132
+
133
+ ## Installation
134
+
135
+ Add this line to your application's Gemfile:
136
+
137
+ ```ruby
138
+ gem 'file-visitor'
139
+ ```
140
+
141
+ And then execute:
142
+
143
+ $ bundle
144
+
145
+ Or install it yourself as:
146
+
147
+ $ gem install file-visitor
148
+
149
+ ## Usage
150
+
151
+ TODO: Write usage instructions here
152
+
153
+ ## Development
154
+
155
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
156
+
157
+ 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).
158
+
159
+ ## Contributing
160
+
161
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/file-visitor. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
162
+
163
+
164
+ ## License
165
+
166
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
167
+
data/Rakefile CHANGED
@@ -1,49 +1,6 @@
1
- # encoding: utf-8
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
2
3
 
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "file-visitor"
18
- gem.homepage = "http://github.com/bonar/file-visitor"
19
- gem.license = "MIT"
20
- gem.summary = %Q{file path collecting utility}
21
- gem.description = %Q{you can collect file paths by mtime/name/ext/block filters.}
22
- gem.email = "bonar@me.com"
23
- gem.authors = ["bonar"]
24
- # dependencies defined in Gemfile
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
-
28
- require 'rspec/core'
29
- require 'rspec/core/rake_task'
30
- RSpec::Core::RakeTask.new(:spec) do |spec|
31
- spec.pattern = FileList['spec/**/*_spec.rb']
32
- end
33
-
34
- RSpec::Core::RakeTask.new(:rcov) do |spec|
35
- spec.pattern = 'spec/**/*_spec.rb'
36
- spec.rcov = true
37
- end
4
+ RSpec::Core::RakeTask.new(:spec)
38
5
 
39
6
  task :default => :spec
40
-
41
- require 'rdoc/task'
42
- Rake::RDocTask.new do |rdoc|
43
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
-
45
- rdoc.rdoc_dir = 'rdoc'
46
- rdoc.title = "file-visitor #{version}"
47
- rdoc.rdoc_files.include('README*')
48
- rdoc.rdoc_files.include('lib/**/*.rb')
49
- end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "file/visitor"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'file/visitor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "file-visitor"
8
+ spec.version = File::Visitor::VERSION
9
+ spec.authors = ["bonar"]
10
+ spec.email = ["bonar@me.com"]
11
+
12
+ spec.summary = %q{File path collectiong utility}
13
+ spec.description = %q{file-visitor is an alternative way to collecting files.}
14
+ spec.homepage = "https://github.com/bonar/file-visitor"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ end
@@ -0,0 +1,5 @@
1
+ class File
2
+ class Visitor
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
metadata CHANGED
@@ -1,87 +1,77 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: file-visitor
3
- version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 0
10
- version: 0.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - bonar
14
8
  autorequire:
15
- bindir: bin
9
+ bindir: exe
16
10
  cert_chain: []
17
-
18
- date: 2013-02-04 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2016-05-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
21
20
  type: :development
22
- requirement: &id001 !ruby/object:Gem::Requirement
23
- none: false
24
- requirements:
25
- - - ~>
26
- - !ruby/object:Gem::Version
27
- hash: 47
28
- segments:
29
- - 2
30
- - 8
31
- - 0
32
- version: 2.8.0
33
- version_requirements: *id001
34
- name: rspec
35
21
  prerelease: false
36
- - !ruby/object:Gem::Dependency
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
37
34
  type: :development
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 31
44
- segments:
45
- - 3
46
- - 12
47
- version: "3.12"
48
- version_requirements: *id002
49
- name: rdoc
50
35
  prerelease: false
51
- - !ruby/object:Gem::Dependency
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
52
48
  type: :development
53
- requirement: &id003 !ruby/object:Gem::Requirement
54
- none: false
55
- requirements:
56
- - - ~>
57
- - !ruby/object:Gem::Version
58
- hash: 63
59
- segments:
60
- - 1
61
- - 8
62
- - 4
63
- version: 1.8.4
64
- version_requirements: *id003
65
- name: jeweler
66
49
  prerelease: false
67
- description: you can collect file paths by mtime/name/ext/block filters.
68
- email: bonar@me.com
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: file-visitor is an alternative way to collecting files.
56
+ email:
57
+ - bonar@me.com
69
58
  executables: []
70
-
71
59
  extensions: []
72
-
73
- extra_rdoc_files:
74
- - LICENSE.txt
75
- - README.rdoc
76
- files:
77
- - .document
78
- - .rspec
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".document"
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
79
67
  - Gemfile
80
68
  - Gemfile.lock
81
69
  - LICENSE.txt
82
- - README.rdoc
70
+ - README.md
83
71
  - Rakefile
84
- - VERSION
72
+ - bin/console
73
+ - bin/setup
74
+ - file-visitor.gemspec
85
75
  - lib/file/visitor.rb
86
76
  - lib/file/visitor/filter.rb
87
77
  - lib/file/visitor/filter/ext.rb
@@ -90,50 +80,29 @@ files:
90
80
  - lib/file/visitor/filter/proc.rb
91
81
  - lib/file/visitor/filter_dispatcher.rb
92
82
  - lib/file/visitor/time_utils.rb
93
- - spec/integration/use_case_spec.rb
94
- - spec/lib/file/vistor/filter/ext_spec.rb
95
- - spec/lib/file/vistor/filter/mtime_spec.rb
96
- - spec/lib/file/vistor/filter/name_spec.rb
97
- - spec/lib/file/vistor/filter/proc_spec.rb
98
- - spec/lib/file/vistor/filter_dispatcher_spec.rb
99
- - spec/lib/file/vistor/filter_spec.rb
100
- - spec/lib/file/vistor/time_utils_spec.rb
101
- - spec/lib/file/vistor_spec.rb
102
- - spec/spec.opts
103
- - spec/spec_helper.rb
104
- - spec/spec_utils.rb
105
- homepage: http://github.com/bonar/file-visitor
106
- licenses:
83
+ - lib/file/visitor/version.rb
84
+ homepage: https://github.com/bonar/file-visitor
85
+ licenses:
107
86
  - MIT
87
+ metadata: {}
108
88
  post_install_message:
109
89
  rdoc_options: []
110
-
111
- require_paths:
90
+ require_paths:
112
91
  - lib
113
- required_ruby_version: !ruby/object:Gem::Requirement
114
- none: false
115
- requirements:
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
116
94
  - - ">="
117
- - !ruby/object:Gem::Version
118
- hash: 3
119
- segments:
120
- - 0
121
- version: "0"
122
- required_rubygems_version: !ruby/object:Gem::Requirement
123
- none: false
124
- requirements:
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
125
99
  - - ">="
126
- - !ruby/object:Gem::Version
127
- hash: 3
128
- segments:
129
- - 0
130
- version: "0"
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
131
102
  requirements: []
132
-
133
103
  rubyforge_project:
134
- rubygems_version: 1.8.24
104
+ rubygems_version: 2.6.3
135
105
  signing_key:
136
- specification_version: 3
137
- summary: file path collecting utility
106
+ specification_version: 4
107
+ summary: File path collectiong utility
138
108
  test_files: []
139
-