build-files 1.7.0 → 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 266f5c2f5a839934620afe4a06289bf7c4363d39c04b39fc3fef8b87104d7ff1
4
- data.tar.gz: b775a997766d4ff2fc751e08fc93d6512a373e944813ee09097731f432087714
3
+ metadata.gz: 13546b8a7c748816d55902380e09b9406074ea0983dc487de2afac9cef4a7000
4
+ data.tar.gz: 731d2f9b19bfcc42356db6c2c0bd8ae93025118c3c57e04fd2fb68ef93e3ab5f
5
5
  SHA512:
6
- metadata.gz: 303be1f16bcadc201db4fd2c9530250926942e1f3f63d269646d943ca439b2c2ca930c0a9fc5caeb16fc4c35362c84580699f5732917f9df51739f339aa7640c
7
- data.tar.gz: 52f6d5d1441dcd15d5be335cab08620aa41524aef8294a13c4adaa2df5513d9e1a03b29b42336afe29b98bdd6f8f1c53c1eb90d7279d855738acfe4e0a29be3b
6
+ metadata.gz: 7f378f74224fe53b757e3425ba2b540fdb34ab63570ac865288804a9d9abbafeea0245c6edb9b788409f4246fca88fb893c50ce471ab99cf6daf7ceac908f727
7
+ data.tar.gz: 52dbba181571f9bb1e7c84bdca6a18e2938c89f5260a826d7753214bd8ffe4634c7019e20c9dc1a71bbd7c08aa0a11dfb407a74686bea34118902a2dea366bef
checksums.yaml.gz.sig ADDED
Binary file
@@ -110,6 +110,8 @@ module Build
110
110
  @full_path.length
111
111
  end
112
112
 
113
+ alias size length
114
+
113
115
  def components
114
116
  @components ||= @full_path.split(File::SEPARATOR).freeze
115
117
  end
@@ -126,6 +128,10 @@ module Build
126
128
  root = Path.root(root)
127
129
  end
128
130
 
131
+ if root.size == full_path.size
132
+ root = Path.root(root)
133
+ end
134
+
129
135
  self.class.new(full_path, root)
130
136
  end
131
137
 
@@ -0,0 +1,172 @@
1
+ # Copyright, 2014, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require_relative 'list'
22
+
23
+ require 'forwardable'
24
+
25
+ module Build
26
+ module Files
27
+ # A stateful list of files captured at a specific time, which can then be checked for changes.
28
+ class State < List
29
+ extend Forwardable
30
+
31
+ # Represents a specific file on disk with a specific mtime.
32
+ class FileTime
33
+ include Comparable
34
+
35
+ def initialize(path, time)
36
+ @path = path
37
+ @time = time
38
+ end
39
+
40
+ attr :path
41
+ attr :time
42
+
43
+ def <=> other
44
+ @time <=> other.time
45
+ end
46
+
47
+ def inspect
48
+ "<FileTime #{@path.inspect} #{@time.inspect}>"
49
+ end
50
+ end
51
+
52
+ def initialize(files)
53
+ raise ArgumentError.new("Invalid files list: #{files}") unless Files::List === files
54
+
55
+ @files = files
56
+
57
+ @times = {}
58
+
59
+ update!
60
+ end
61
+
62
+ attr :files
63
+
64
+ attr :added
65
+ attr :removed
66
+ attr :changed
67
+ attr :missing
68
+
69
+ attr :times
70
+
71
+ def_delegators :@files, :each, :roots, :count
72
+
73
+ def update!
74
+ last_times = @times
75
+ @times = {}
76
+
77
+ @added = []
78
+ @removed = []
79
+ @changed = []
80
+ @missing = []
81
+
82
+ file_times = []
83
+
84
+ @files.each do |path|
85
+ # When processing the same path twice (perhaps by accident), we should skip it otherwise it might cause issues when being deleted from last_times multuple times.
86
+ next if @times.include? path
87
+
88
+ if File.exist?(path)
89
+ modified_time = File.mtime(path)
90
+
91
+ if last_time = last_times.delete(path)
92
+ # Path was valid last update:
93
+ if modified_time != last_time
94
+ @changed << path
95
+
96
+ # puts "Changed: #{path}"
97
+ end
98
+ else
99
+ # Path didn't exist before:
100
+ @added << path
101
+
102
+ # puts "Added: #{path}"
103
+ end
104
+
105
+ @times[path] = modified_time
106
+
107
+ unless File.directory?(path)
108
+ file_times << FileTime.new(path, modified_time)
109
+ end
110
+ else
111
+ @missing << path
112
+
113
+ # puts "Missing: #{path}"
114
+ end
115
+ end
116
+
117
+ @removed = last_times.keys
118
+ # puts "Removed: #{@removed.inspect}" if @removed.size > 0
119
+
120
+ @oldest_time = file_times.min
121
+ @newest_time = file_times.max
122
+
123
+ return @added.size > 0 || @changed.size > 0 || @removed.size > 0 || @missing.size > 0
124
+ end
125
+
126
+ attr :oldest_time
127
+ attr :newest_time
128
+
129
+ def missing?
130
+ !@missing.empty?
131
+ end
132
+
133
+ def empty?
134
+ @times.empty?
135
+ end
136
+
137
+ def inspect
138
+ "<State Added:#{@added} Removed:#{@removed} Changed:#{@changed} Missing:#{@missing}>"
139
+ end
140
+
141
+ # Are these (output) files dirty with respect to the given inputs?
142
+ def dirty?(inputs)
143
+ if self.missing?
144
+ return true
145
+ end
146
+
147
+ # If there are no inputs or no outputs, we are always clean:
148
+ if inputs.empty? or self.empty?
149
+ return false
150
+ end
151
+
152
+ oldest_output_time = self.oldest_time
153
+ newest_input_time = inputs.newest_time
154
+
155
+ if newest_input_time and oldest_output_time
156
+ # We are dirty if any inputs are newer (bigger) than any outputs:
157
+ if newest_input_time > oldest_output_time
158
+ return true
159
+ else
160
+ return false
161
+ end
162
+ end
163
+
164
+ return true
165
+ end
166
+
167
+ def self.dirty?(inputs, outputs)
168
+ outputs.dirty?(inputs)
169
+ end
170
+ end
171
+ end
172
+ end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Build
22
22
  module Files
23
- VERSION = "1.7.0"
23
+ VERSION = "1.8.1"
24
24
  end
25
25
  end
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,17 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: build-files
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain: []
11
- date: 2021-05-22 00:00:00.000000000 Z
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEhDCCAuygAwIBAgIBATANBgkqhkiG9w0BAQsFADA3MTUwMwYDVQQDDCxzYW11
14
+ ZWwud2lsbGlhbXMvREM9b3Jpb250cmFuc2Zlci9EQz1jby9EQz1uejAeFw0yMTA4
15
+ MTYwNjMzNDRaFw0yMjA4MTYwNjMzNDRaMDcxNTAzBgNVBAMMLHNhbXVlbC53aWxs
16
+ aWFtcy9EQz1vcmlvbnRyYW5zZmVyL0RDPWNvL0RDPW56MIIBojANBgkqhkiG9w0B
17
+ AQEFAAOCAY8AMIIBigKCAYEAyXLSS/cw+fXJ5e7hi+U/TeChPWeYdwJojDsFY1xr
18
+ xvtqbTTL8gbLHz5LW3QD2nfwCv3qTlw0qI3Ie7a9VMJMbSvgVEGEfQirqIgJXWMj
19
+ eNMDgKsMJtC7u/43abRKx7TCURW3iWyR19NRngsJJmaR51yGGGm2Kfsr+JtKKLtL
20
+ L188Wm3f13KAx7QJU8qyuBnj1/gWem076hzdA7xi1DbrZrch9GCRz62xymJlrJHn
21
+ 9iZEZ7AxrS7vokhMlzSr/XMUihx/8aFKtk+tMLClqxZSmBWIErWdicCGTULXCBNb
22
+ E/mljo4zEVKhlTWpJklMIhr55ZRrSarKFuW7en0+tpJrfsYiAmXMJNi4XAYJH7uL
23
+ rgJuJwSaa/dMz+VmUoo7VKtSfCoOI+6v5/z0sK3oT6sG6ZwyI47DBq2XqNC6tnAj
24
+ w+XmCywiTQrFzMMAvcA7rPI4F0nU1rZId51rOvvfxaONp+wgTi4P8owZLw0/j0m4
25
+ 8C20DYi6EYx4AHDXiLpElWh3AgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8E
26
+ BAMCBLAwHQYDVR0OBBYEFB6ZaeWKxQjGTI+pmz7cKRmMIywwMC4GA1UdEQQnMCWB
27
+ I3NhbXVlbC53aWxsaWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWB
28
+ I3NhbXVlbC53aWxsaWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEB
29
+ CwUAA4IBgQBVoM+pu3dpdUhZM1w051iw5GfiqclAr1Psypf16Tiod/ho//4oAu6T
30
+ 9fj3DPX/acWV9P/FScvqo4Qgv6g4VWO5ZU7z2JmPoTXZtYMunRAmQPFL/gSUc6aK
31
+ vszMHIyhtyzRc6DnfW2AiVOjMBjaYv8xXZc9bduniRVPrLR4J7ozmGLh4o4uJp7w
32
+ x9KCFaR8Lvn/r0oJWJOqb/DMAYI83YeN2Dlt3jpwrsmsONrtC5S3gOUle5afSGos
33
+ bYt5ocnEpKSomR9ZtnCGljds/aeO1Xgpn2r9HHcjwnH346iNrnHmMlC7BtHUFPDg
34
+ Ts92S47PTOXzwPBDsrFiq3VLbRjHSwf8rpqybQBH9MfzxGGxTaETQYOd6b4e4Ag6
35
+ y92abGna0bmIEb4+Tx9rQ10Uijh1POzvr/VTH4bbIPy9FbKrRsIQ24qDbNJRtOpE
36
+ RAOsIl+HOBTb252nx1kIRN5hqQx272AJCbCjKx8egcUQKffFVVCI0nye09v5CK+a
37
+ HiLJ8VOFx6w=
38
+ -----END CERTIFICATE-----
39
+ date: 2022-05-22 00:00:00.000000000 Z
12
40
  dependencies:
13
41
  - !ruby/object:Gem::Dependency
14
- name: covered
42
+ name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
16
44
  requirements:
17
45
  - - ">="
@@ -25,7 +53,7 @@ dependencies:
25
53
  - !ruby/object:Gem::Version
26
54
  version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
- name: bundler
56
+ name: covered
29
57
  requirement: !ruby/object:Gem::Requirement
30
58
  requirements:
31
59
  - - ">="
@@ -52,33 +80,12 @@ dependencies:
52
80
  - - "~>"
53
81
  - !ruby/object:Gem::Version
54
82
  version: '3.4'
55
- - !ruby/object:Gem::Dependency
56
- name: bake-bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
83
  description:
70
84
  email:
71
- - samuel.williams@oriontransfer.co.nz
72
85
  executables: []
73
86
  extensions: []
74
87
  extra_rdoc_files: []
75
88
  files:
76
- - ".gitignore"
77
- - ".rspec"
78
- - ".travis.yml"
79
- - Gemfile
80
- - README.md
81
- - build-files.gemspec
82
89
  - lib/build/files.rb
83
90
  - lib/build/files/composite.rb
84
91
  - lib/build/files/difference.rb
@@ -87,21 +94,14 @@ files:
87
94
  - lib/build/files/list.rb
88
95
  - lib/build/files/path.rb
89
96
  - lib/build/files/paths.rb
97
+ - lib/build/files/state.rb
90
98
  - lib/build/files/system.rb
91
99
  - lib/build/files/version.rb
92
- - spec/build/files/directory_spec.rb
93
- - spec/build/files/directory_spec/.dot_file.yaml
94
- - spec/build/files/directory_spec/normal_file.txt
95
- - spec/build/files/glob_spec.rb
96
- - spec/build/files/glob_spec/dotfiles/.file
97
- - spec/build/files/list_spec.rb
98
- - spec/build/files/path_spec.rb
99
- - spec/build/files/system_spec.rb
100
- - spec/spec_helper.rb
101
- homepage: ''
100
+ homepage: https://github.com/ioquatix/build-files
102
101
  licenses:
103
102
  - MIT
104
- metadata: {}
103
+ metadata:
104
+ funding_uri: https://github.com/sponsors/ioquatix/
105
105
  post_install_message:
106
106
  rdoc_options: []
107
107
  require_paths:
@@ -117,18 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
- rubygems_version: 3.2.3
120
+ rubygems_version: 3.1.6
121
121
  signing_key:
122
122
  specification_version: 4
123
- summary: Build::Files is a set of idiomatic classes for dealing with paths and monitoring
124
- directories.
125
- test_files:
126
- - spec/build/files/directory_spec.rb
127
- - spec/build/files/directory_spec/.dot_file.yaml
128
- - spec/build/files/directory_spec/normal_file.txt
129
- - spec/build/files/glob_spec.rb
130
- - spec/build/files/glob_spec/dotfiles/.file
131
- - spec/build/files/list_spec.rb
132
- - spec/build/files/path_spec.rb
133
- - spec/build/files/system_spec.rb
134
- - spec/spec_helper.rb
123
+ summary: Abstractions for handling and mapping paths.
124
+ test_files: []
metadata.gz.sig ADDED
Binary file
data/.gitignore DELETED
@@ -1,24 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- *.bundle
19
- *.so
20
- *.o
21
- *.a
22
- mkmf.log
23
- .rspec_status
24
-
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --format documentation
2
- --backtrace
3
- --warnings
4
- --require spec_helper
data/.travis.yml DELETED
@@ -1,14 +0,0 @@
1
- language: ruby
2
- dist: xenial
3
- cache: bundler
4
-
5
- matrix:
6
- include:
7
- - rvm: 2.3
8
- - rvm: 2.4
9
- - rvm: 2.5
10
- - rvm: 2.6
11
- env: COVERAGE=BriefSummary,Coveralls
12
- - rvm: 2.6
13
- os: osx
14
- env: COVERAGE=BriefSummary,Coveralls
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in build-files.gemspec
4
- gemspec
5
-
6
- group :test do
7
- gem 'rb-fsevent'
8
- gem 'rb-inotify'
9
- end
data/README.md DELETED
@@ -1,69 +0,0 @@
1
- # Build::Files
2
-
3
- Build::Files is a set of idiomatic classes for dealing with paths and monitoring directories. File paths are represented with both root and relative parts which makes copying directory structures intuitive.
4
-
5
- [![Build Status](https://secure.travis-ci.org/ioquatix/build-files.svg)](http://travis-ci.org/ioquatix/build-files)
6
- [![Code Climate](https://codeclimate.com/github/ioquatix/build-files.svg)](https://codeclimate.com/github/ioquatix/build-files)
7
- [![Coverage Status](https://coveralls.io/repos/ioquatix/build-files/badge.svg)](https://coveralls.io/r/ioquatix/build-files)
8
-
9
- ## Installation
10
-
11
- Add this line to your application's Gemfile:
12
-
13
- gem 'build-files'
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install build-files
22
-
23
- ## Usage
24
-
25
- The basic structure is the `Path`. Paths are stored with a root and relative part. By default, if no root is specified, it is the `dirname` part.
26
-
27
- require 'build/files'
28
-
29
- path = Build::Files::Path("/foo/bar/baz")
30
- => "/foo/bar"/"baz"
31
-
32
- > path.root
33
- => "/foo/bar"
34
- > path.relative_path
35
- => "baz"
36
-
37
- Paths can be coerced to strings and thus are suitable arguments to `exec`/`system` functions.
38
-
39
- ## Contributing
40
-
41
- 1. Fork it
42
- 2. Create your feature branch (`git checkout -b my-new-feature`)
43
- 3. Commit your changes (`git commit -am 'Add some feature'`)
44
- 4. Push to the branch (`git push origin my-new-feature`)
45
- 5. Create new Pull Request
46
-
47
- ## License
48
-
49
- Released under the MIT license.
50
-
51
- Copyright, 2014, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
52
-
53
- Permission is hereby granted, free of charge, to any person obtaining a copy
54
- of this software and associated documentation files (the "Software"), to deal
55
- in the Software without restriction, including without limitation the rights
56
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
57
- copies of the Software, and to permit persons to whom the Software is
58
- furnished to do so, subject to the following conditions:
59
-
60
- The above copyright notice and this permission notice shall be included in
61
- all copies or substantial portions of the Software.
62
-
63
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
64
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
65
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
66
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
67
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
68
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
69
- THE SOFTWARE.
data/build-files.gemspec DELETED
@@ -1,25 +0,0 @@
1
-
2
- require_relative 'lib/build/files/version'
3
-
4
- Gem::Specification.new do |spec|
5
- spec.name = "build-files"
6
- spec.version = Build::Files::VERSION
7
- spec.authors = ["Samuel Williams"]
8
- spec.email = ["samuel.williams@oriontransfer.co.nz"]
9
- # spec.description = %q{}
10
- spec.summary = %q{Build::Files is a set of idiomatic classes for dealing with paths and monitoring directories.}
11
- spec.homepage = ""
12
- spec.license = "MIT"
13
-
14
- spec.files = `git ls-files`.split($/)
15
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
- spec.require_paths = ["lib"]
18
-
19
- spec.required_ruby_version = '>= 2.0'
20
-
21
- spec.add_development_dependency "covered"
22
- spec.add_development_dependency "bundler"
23
- spec.add_development_dependency "rspec", "~> 3.4"
24
- spec.add_development_dependency "bake-bundler"
25
- end
File without changes
File without changes
@@ -1,80 +0,0 @@
1
- # Copyright, 2014, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'build/files/directory'
22
-
23
- module Build::Files::DirectorySpec
24
- include Build::Files
25
-
26
- describe Build::Files::Directory do
27
- let(:path) {Path.new("/foo/bar/baz", "/foo")}
28
- let(:directory) {Directory.new(path)}
29
-
30
- it "can be constructed using join" do
31
- joined_directory = Directory.join('/foo', 'bar/baz')
32
-
33
- expect(joined_directory).to be == directory
34
- end
35
-
36
- it "has a root and path component" do
37
- expect(directory.root).to be == path
38
- expect(directory.to_path).to be == path
39
-
40
- expect(directory.roots).to be_include(path)
41
- end
42
-
43
- it "can be converted into a string" do
44
- expect(directory.to_str).to be == path.to_str
45
- end
46
-
47
- it "can be used as a key" do
48
- hash = {directory => true}
49
-
50
- expect(hash).to be_include directory
51
- end
52
-
53
- it "includes subpaths" do
54
- expect(directory).to be_include "/foo/bar/baz/bob/dole"
55
- end
56
-
57
- it "can be compared" do
58
- other_directory = Directory.new(path + 'dole')
59
-
60
- expect(directory).to be_eql directory
61
- expect(directory).to_not be_eql other_directory
62
- end
63
-
64
- it "can be rebased" do
65
- rebased_directory = directory.rebase("/fu")
66
-
67
- expect(rebased_directory.root).to be == '/fu/bar/baz'
68
- end
69
-
70
- context Directory.join(__dir__, "directory_spec") do
71
- it "can list dot files" do
72
- expect(subject).to include(subject.root + '.dot_file.yaml')
73
- end
74
-
75
- it "can list normal files" do
76
- expect(subject).to include(subject.root + 'normal_file.txt')
77
- end
78
- end
79
- end
80
- end
File without changes
@@ -1,53 +0,0 @@
1
- # Copyright, 2014, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'build/files/glob'
22
-
23
- RSpec.describe Build::Files::Glob do
24
- let(:path) {Build::Files::Path.new(__dir__)}
25
-
26
- it "can glob paths" do
27
- paths = path.glob("*.rb")
28
-
29
- expect(paths.count).to be >= 1
30
- end
31
-
32
- it "can be used as key in hash" do
33
- cache = {}
34
-
35
- cache[path.glob("*.rb")] = true
36
-
37
- expect(cache).to be_include(path.glob("*.rb"))
38
- end
39
-
40
- it "should print nice string represenation" do
41
- glob = Build::Files::Glob.new(".", "*.rb")
42
-
43
- expect("#{glob}").to be == '<Glob "."/"*.rb">'
44
- end
45
-
46
- context 'with dotfiles' do
47
- it "should list files starting with dot" do
48
- paths = path.glob("glob_spec/dotfiles/**/*")
49
-
50
- expect(paths.count).to be == 1
51
- end
52
- end
53
- end
@@ -1,182 +0,0 @@
1
- # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'build/files'
22
- require 'build/files/list'
23
- require 'build/files/glob'
24
-
25
- module Build::Files::ListSpec
26
- include Build::Files
27
-
28
- describe Build::Files::Paths do
29
- let(:path) {Path.new("/foo/bar/baz", "/foo")}
30
-
31
- it "should be inspectable" do
32
- paths = Paths.new(path)
33
-
34
- expect(paths.inspect).to be_include path.inspect
35
- end
36
-
37
- it "should be possible to convert to paths" do
38
- paths = Paths.new(path)
39
-
40
- expect(paths.to_paths).to be paths
41
- end
42
-
43
- it "should be count number of paths" do
44
- paths = Paths.new(path)
45
-
46
- expect(paths.count).to be == 1
47
- end
48
-
49
- it "should coerce array to paths" do
50
- paths = Paths.coerce([path])
51
-
52
- expect(paths).to be_kind_of Paths
53
- expect(paths.count).to be == 1
54
- expect(paths).to be_include path
55
-
56
- same_paths = Paths.coerce(paths)
57
- expect(same_paths).to be paths
58
- end
59
-
60
- it "can add two lists of paths together" do
61
- paths_a = Paths.new(path)
62
- paths_b = Paths.new(Path.join('/foo/bar', 'alice'))
63
-
64
- paths = paths_a + paths_b
65
-
66
- expect(paths.count).to be 2
67
- expect(paths).to be_include path
68
- expect(paths).to be_kind_of Composite
69
-
70
- # Composite equality
71
- expect(paths).to be_eql paths
72
- expect(paths).to_not be_eql paths_a
73
- end
74
-
75
- it "maps paths with a new extension" do
76
- paths = Paths.new([
77
- Path.join('/foo/bar', 'alice'),
78
- Path.join('/foo/bar', 'bob'),
79
- Path.join('/foo/bar', 'charles'),
80
- path
81
- ])
82
-
83
- expect(paths).to include(path)
84
-
85
- expect(paths).to be_intersects(paths)
86
- expect(paths).to_not be_intersects(Paths::NONE)
87
-
88
- mapped_paths = paths.map {|path| path + ".o"}
89
-
90
- expect(mapped_paths).to be_kind_of(Paths)
91
- expect(mapped_paths.roots).to be == paths.roots
92
- end
93
-
94
- it "globs multiple files" do
95
- glob = Glob.new(__dir__, '*.rb')
96
-
97
- expect(glob.count).to be > 1
98
-
99
- mapped_paths = glob.map {|path| path + ".txt"}
100
-
101
- expect(glob.roots).to be == mapped_paths.roots
102
- end
103
-
104
- it "should intersect one file in the glob" do
105
- # Glob all test files:
106
- glob = Glob.new(__dir__, "*.rb")
107
-
108
- expect(glob.count).to be > 0
109
-
110
- # Should include this file:
111
- expect(glob).to include(__FILE__)
112
-
113
- # Glob should intersect self:
114
- expect(glob).to be_intersects(glob)
115
- end
116
-
117
- it "should include composites" do
118
- lib = File.join(__dir__, "../lib")
119
-
120
- test_glob = Glob.new(__dir__, "*.rb")
121
- lib_glob = Glob.new(lib, "*.rb")
122
-
123
- both = test_glob + lib_glob
124
-
125
- # List#roots is the generic accessor for Lists
126
- expect(both.roots).to include test_glob.root
127
-
128
- # The composite should include both:
129
- expect(both).to include(__FILE__)
130
- end
131
-
132
- it "should have path with correct root" do
133
- test_glob = Glob.new(__dir__, "*.rb")
134
-
135
- expect(test_glob.first).to be_kind_of Path
136
-
137
- expect(test_glob.first.root).to be == __dir__
138
- end
139
-
140
- it "maps paths with new extension" do
141
- glob = Glob.new(__dir__, "*.rb")
142
-
143
- paths = glob.map {|path| path.append ".txt"}
144
-
145
- expect(paths.first).to be == (glob.first.append ".txt")
146
- expect(paths.first.to_s).to be_end_with ".rb.txt"
147
- end
148
-
149
- it "should map paths using with" do
150
- glob = Glob.new(__dir__, "*.rb")
151
-
152
- paths = glob.with extension: ".txt"
153
- path = paths.first
154
-
155
- expect(path).to be_kind_of Array
156
-
157
- expect(path[0]).to be == glob.first
158
- expect(path[1]).to be == glob.first.append(".txt")
159
- end
160
-
161
- it "should define an empty set of files" do
162
- expect(Paths::NONE).to be_kind_of List
163
-
164
- expect(Paths::NONE.count).to be 0
165
- end
166
-
167
- it "can be used as key in hash" do
168
- cache = {}
169
-
170
- cache[Paths.new(path)] = true
171
-
172
- expect(cache).to be_include(Paths.new(path))
173
- end
174
-
175
- it "can be constructed from a list of relative paths" do
176
- paths = Paths.directory('/foo', ['bar', 'baz', 'bob'])
177
-
178
- expect(paths.count).to be 3
179
- expect(paths).to be_include Path.new('/foo/bar')
180
- end
181
- end
182
- end
@@ -1,223 +0,0 @@
1
- # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'build/files'
22
- require 'build/files/path'
23
-
24
- require 'pathname'
25
-
26
- RSpec.describe Build::Files::Path do
27
- it "can get current path" do
28
- expect(Build::Files::Path.current.full_path).to be == Dir.pwd
29
- end
30
-
31
- it "should expand the path" do
32
- expect(Build::Files::Path.expand("foo", "/bar")).to be == "/bar/foo"
33
- end
34
-
35
- it "should give current path" do
36
- path = Build::Files::Path.new("/a/b/c/file.cpp")
37
-
38
- expect(path.shortest_path(path)).to be == "."
39
- end
40
-
41
- it "should give the shortest path for outer paths" do
42
- input = Build::Files::Path.new("/a/b/c/file.cpp")
43
- output = Build::Files::Path.new("/a/b/c/d/e/")
44
-
45
- expect(input.root).to be == "/a/b/c"
46
- expect(output.root).to be == "/a/b/c/d/e"
47
-
48
- short = input.shortest_path(output)
49
-
50
- expect(short).to be == "../../file.cpp"
51
-
52
- expect(File.expand_path(short, output)).to be == input
53
- end
54
-
55
- it "should give the shortest path for inner paths" do
56
- input = Build::Files::Path.new("/a/b/c/file.cpp")
57
- output = Build::Files::Path.new("/a/")
58
-
59
- expect(input.root).to be == "/a/b/c"
60
- expect(output.root).to be == "/a"
61
-
62
- short = input.shortest_path(output)
63
-
64
- expect(short).to be == "b/c/file.cpp"
65
-
66
- expect(File.expand_path(short, output)).to be == input
67
- end
68
- end
69
-
70
- RSpec.describe Build::Files::Path.new("/test") do
71
- it "should start_with? full path" do
72
- expect(subject).to be_start_with '/test'
73
- end
74
-
75
- it "should start_with? partial pattern" do
76
- expect(subject).to be_start_with '/te'
77
- end
78
- end
79
-
80
- RSpec.describe Build::Files::Path.new("/foo/bar.txt") do
81
- it "should replace existing file extension" do
82
- expect(subject.with(extension: '.jpeg', basename: true)).to be == "/foo/bar.jpeg"
83
- end
84
-
85
- it "should append file extension" do
86
- expect(subject.with(extension: '.jpeg')).to be == "/foo/bar.txt.jpeg"
87
- end
88
-
89
- it "should change basename" do
90
- expect(subject.with(basename: 'baz', extension: '.txt')).to be == "/foo/baz.txt"
91
- end
92
- end
93
-
94
- RSpec.describe Build::Files::Path.new("/foo/bar/baz", "/foo") do
95
- it "can compute parent path" do
96
- parent = subject.parent
97
-
98
- expect(parent.root).to be == subject.root
99
- expect(parent.relative_path).to be == "bar"
100
- expect(parent.full_path).to be == "/foo/bar"
101
- end
102
-
103
- it "can add nil path" do
104
- expect(subject + nil).to be == subject
105
- end
106
-
107
- it "can inspect path with nil root" do
108
- expect do
109
- (subject / nil).inspect
110
- end.to_not raise_error
111
- end
112
-
113
- it "can add nil root" do
114
- expect(subject / nil).to be == subject
115
- end
116
-
117
- it "should be inspectable" do
118
- expect(subject.inspect).to be_include subject.root.to_s
119
- expect(subject.inspect).to be_include subject.relative_path.to_s
120
- end
121
-
122
- it "should convert to path" do
123
- pathname = Pathname("/foo/bar/baz")
124
-
125
- expect(Build::Files::Path[pathname]).to be == subject
126
- expect(Build::Files::Path["/foo/bar/baz"]).to be == subject
127
- end
128
-
129
- it "should be equal" do
130
- expect(subject).to be_eql subject
131
- expect(subject).to be == subject
132
-
133
- different_root_path = Build::Files::Path.join("/foo/bar", "baz")
134
- expect(subject).to_not be_eql different_root_path
135
- expect(subject).to be == different_root_path
136
- end
137
-
138
- it "should convert to string" do
139
- expect(subject.to_s).to be == "/foo/bar/baz"
140
-
141
- # The to_str method should return the full path (i.e. the same as to_s):
142
- expect(subject.to_s).to be == subject.to_str
143
-
144
- # Check the equality operator:
145
- expect(subject).to be == subject.dup
146
-
147
- # The length should be reported correctly:
148
- expect(subject.length).to be == subject.to_s.length
149
-
150
- # Check the return types:
151
- expect(subject).to be_kind_of Build::Files::Path
152
- expect(subject.root).to be_kind_of String
153
- expect(subject.relative_path).to be_kind_of String
154
- end
155
-
156
- it "should consist of parts" do
157
- expect(subject.parts).to be == ["", "foo", "bar", "baz"]
158
-
159
- expect(subject.root).to be == "/foo"
160
-
161
- expect(subject.relative_path).to be == "bar/baz"
162
-
163
- expect(subject.relative_parts).to be == ["bar", "baz"]
164
- end
165
-
166
- it "should have a new extension" do
167
- renamed_path = subject.with(root: '/tmp', extension: '.txt')
168
-
169
- expect(renamed_path.root).to be == '/tmp'
170
-
171
- expect(renamed_path.relative_path).to be == 'bar/baz.txt'
172
-
173
- object_path = subject.append(".o")
174
-
175
- expect(object_path.root).to be == "/foo"
176
- expect(object_path.relative_path).to be == "bar/baz.o"
177
- end
178
-
179
- it "should append a path" do
180
- subject = Build::Files::Path.new("/a/b/c")
181
-
182
- expect(subject + "d/e/f").to be == "/a/b/c/d/e/f"
183
- end
184
-
185
- it "should give a list of components" do
186
- expect(Build::Files::Path.components(subject)).to be == ["", "foo", "bar", "baz"]
187
- expect(Build::Files::Path.components(subject.to_s)).to be == ["", "foo", "bar", "baz"]
188
- end
189
-
190
- it "should give a basename" do
191
- expect(subject.basename).to be == "baz"
192
- end
193
-
194
- it "should have a new root" do
195
- rerooted_path = subject / "cat"
196
-
197
- expect(rerooted_path.root).to be == "/foo/bar/baz"
198
- expect(rerooted_path.relative_path).to be == "cat"
199
- end
200
-
201
- it "should give correct modes for reading" do
202
- expect(subject.for_reading).to be == [subject.to_s, File::RDONLY]
203
- end
204
-
205
- it "should give correct modes for writing" do
206
- expect(subject.for_writing).to be == [subject.to_s, File::CREAT|File::TRUNC|File::WRONLY]
207
- end
208
-
209
- it "should give correct modes for appending" do
210
- expect(subject.for_appending).to be == [subject.to_s, File::CREAT|File::APPEND|File::WRONLY]
211
- end
212
-
213
- it "should match against relative path" do
214
- expect(subject.match(subject.relative_path)).to be_truthy
215
- expect(subject.match("*/baz")).to be_truthy
216
- expect(subject.match("/baz")).to be_falsey
217
- end
218
-
219
- it "should match against absolute path" do
220
- expect(subject.match(subject.to_s)).to be_truthy
221
- expect(subject.match("/foo/**")).to be_truthy
222
- end
223
- end
@@ -1,56 +0,0 @@
1
- # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'build/files'
22
- require 'build/files/path'
23
- require 'build/files/system'
24
-
25
- require 'pathname'
26
-
27
- module Build::Files::FilesystemSpec
28
- include Build::Files
29
-
30
- describe Build::Files::Path do
31
- let(:root) {Path.new(__dir__)}
32
- let(:path) {root + "filesystem_spec"}
33
-
34
- after(:each) do
35
- path.delete
36
- end
37
-
38
- it "should open file for writing" do
39
- path.write("Hello World")
40
-
41
- expect(File).to be_exist(path)
42
- expect(path.read).to be == "Hello World"
43
-
44
- expect(path).to be_exist
45
- expect(path.directory?).to be == false
46
-
47
- expect(path.modified_time.to_f).to be_within(5.0).of(Time.now.to_f)
48
- end
49
-
50
- it "should make a directory" do
51
- path.create
52
-
53
- expect(path.directory?).to be == true
54
- end
55
- end
56
- end
data/spec/spec_helper.rb DELETED
@@ -1,11 +0,0 @@
1
-
2
- require "covered/rspec"
3
-
4
- RSpec.configure do |config|
5
- # Enable flags like --only-failures and --next-failure
6
- config.example_status_persistence_file_path = ".rspec_status"
7
-
8
- config.expect_with :rspec do |c|
9
- c.syntax = :expect
10
- end
11
- end