build-files 0.3.4 → 1.0.0

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
  SHA1:
3
- metadata.gz: 219675f752dc63697b9075f9b14c5e528ad8571e
4
- data.tar.gz: 632cd210ac7a90160607bb02ab03d70d33583a74
3
+ metadata.gz: 175cf300ef1bb7f8873e0932c313a2d43ec1fdaf
4
+ data.tar.gz: 12f0e5f2dac80a6f59c7e1945fe6a04467604e39
5
5
  SHA512:
6
- metadata.gz: 88cfce577e99a4c3bba47890ce126675649e8880b8bc447d706a7c06bb45c663b3f5951824b2865cbe7f45d0040e29bd7b28a48a3925f08aeb582a05aa5ff5c1
7
- data.tar.gz: 92471caf1ea8d0cd24713cacd34a92f04d5c02a37327489447cdc7b2fb5f7c267092e3fd9c565ea1dc88525c65fc73e7405ff9e1b2a44bb008c762a17c85f4ab
6
+ metadata.gz: 19cbf2b9570233c4cd423f53e9c59e4053c6e3cf020157bcf1c2cae28389996872351cb374b9001ede12070de73b0a625d06ce5a0f56e8e8306e1c0576429b80
7
+ data.tar.gz: bac413fc3b5e4503d6ea4d85c8b2632134d8e603c0fdb84d5411f8b12412d84a3f2de673cca28b56c7427ca94723d1f93fbf097dc8a3b4df3d84965262294d25
@@ -46,11 +46,11 @@ module Build
46
46
  yield Path.new(path, @root)
47
47
  end
48
48
  end
49
-
49
+
50
50
  def eql?(other)
51
51
  self.class.eql?(other.class) and @root.eql?(other.root)
52
52
  end
53
-
53
+
54
54
  def hash
55
55
  @root.hash
56
56
  end
@@ -35,6 +35,17 @@ module Build
35
35
  Composite.new([self, list])
36
36
  end
37
37
 
38
+ # This isn't very efficient, but it IS generic.
39
+ def ==(other)
40
+ if self.class == other.class
41
+ self.eql?(other)
42
+ elsif other.kind_of? self.class
43
+ self.to_a.sort == other.to_a.sort
44
+ else
45
+ super
46
+ end
47
+ end
48
+
38
49
  # Does this list of files include the path of any other?
39
50
  def intersects? other
40
51
  other.any?{|path| include?(path)}
@@ -77,54 +88,6 @@ module Build
77
88
  end
78
89
  end
79
90
 
80
- class Paths < List
81
- def initialize(list, roots = nil)
82
- @list = Array(list).freeze
83
- @roots = roots
84
- end
85
-
86
- attr :list
87
-
88
- # The list of roots for a given list of immutable files is also immutable, so we cache it for performance:
89
- def roots
90
- @roots ||= super
91
- end
92
-
93
- def count
94
- @list.count
95
- end
96
-
97
- def each
98
- return to_enum(:each) unless block_given?
99
-
100
- @list.each{|path| yield path}
101
- end
102
-
103
- def eql?(other)
104
- self.class.eql?(other.class) and @list.eql?(other.list)
105
- end
106
-
107
- def hash
108
- @list.hash
109
- end
110
-
111
- def to_paths
112
- self
113
- end
114
-
115
- def inspect
116
- "<Paths #{@list.inspect}>"
117
- end
118
-
119
- def self.directory(root, relative_paths)
120
- paths = relative_paths.collect do |path|
121
- Path.join(root, path)
122
- end
123
-
124
- self.new(paths, [root])
125
- end
126
- end
127
-
128
91
  class Composite < List
129
92
  def initialize(files, roots = nil)
130
93
  @files = []
@@ -0,0 +1,73 @@
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
+ module Build
24
+ module Files
25
+ class Paths < List
26
+ def initialize(list, roots = nil)
27
+ @list = Array(list).freeze
28
+ @roots = roots
29
+ end
30
+
31
+ attr :list
32
+
33
+ # The list of roots for a given list of immutable files is also immutable, so we cache it for performance:
34
+ def roots
35
+ @roots ||= super
36
+ end
37
+
38
+ def count
39
+ @list.count
40
+ end
41
+
42
+ def each
43
+ return to_enum(:each) unless block_given?
44
+
45
+ @list.each{|path| yield path}
46
+ end
47
+
48
+ def eql?(other)
49
+ self.class.eql?(other.class) and @list.eql?(other.list)
50
+ end
51
+
52
+ def hash
53
+ @list.hash
54
+ end
55
+
56
+ def to_paths
57
+ self
58
+ end
59
+
60
+ def inspect
61
+ "<Paths #{@list.inspect}>"
62
+ end
63
+
64
+ def self.directory(root, relative_paths)
65
+ paths = relative_paths.collect do |path|
66
+ Path.join(root, path)
67
+ end
68
+
69
+ self.new(paths, [root])
70
+ end
71
+ end
72
+ end
73
+ end
@@ -20,54 +20,82 @@
20
20
 
21
21
  require 'fileutils'
22
22
 
23
+ require_relative 'path'
24
+ require_relative 'list'
25
+
23
26
  module Build
24
27
  module Files
25
28
  class Path
29
+ # Open a file with the specified mode.
26
30
  def open(mode, &block)
27
31
  File.open(self, mode, &block)
28
32
  end
29
33
 
34
+ # Read the entire contents of the file.
30
35
  def read(mode = File::RDONLY)
31
36
  open(mode) do |file|
32
37
  file.read
33
38
  end
34
39
  end
35
40
 
41
+ # Write a buffer to the file, creating it if it doesn't exist.
36
42
  def write(buffer, mode = File::CREAT|File::TRUNC|File::WRONLY)
37
43
  open(mode) do |file|
38
44
  file.write(buffer)
39
45
  end
40
46
  end
41
47
 
48
+ # Touch the file, changing it's last modified time.
42
49
  def touch
43
50
  FileUtils.touch self
44
51
  end
45
52
 
53
+ # Checks if the file exists in the local file system.
46
54
  def exist?
47
55
  File.exist? self
48
56
  end
49
57
 
58
+ # Checks if the path refers to a directory.
50
59
  def directory?
51
60
  File.directory? self
52
61
  end
53
62
 
63
+ # The time the file was last modified.
54
64
  def modified_time
55
65
  File.mtime self
56
66
  end
57
67
 
58
- alias mtime modified_time
59
-
68
+ # Recursively create a directory hierarchy for the given path.
60
69
  def create
61
70
  FileUtils.mkpath self
62
71
  end
63
72
 
64
- alias mkpath create
65
-
73
+ # Recursively delete the given path and all contents.
66
74
  def delete
67
75
  FileUtils.rm_rf self
68
76
  end
77
+ end
78
+
79
+ class List
80
+ # Touch all listed files.
81
+ def touch
82
+ each(&:touch)
83
+ end
84
+
85
+ # Check that all files listed exist.
86
+ def exist?
87
+ all?(&:exist?)
88
+ end
69
89
 
70
- alias rmpath delete
90
+ # Recursively create paths for all listed paths.
91
+ def create
92
+ each(&:create)
93
+ end
94
+
95
+ # Recursively delete all paths and all contents within those paths.
96
+ def delete
97
+ each(&:delete)
98
+ end
71
99
  end
72
100
  end
73
101
  end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Build
22
22
  module Files
23
- VERSION = "0.3.4"
23
+ VERSION = "1.0.0"
24
24
  end
25
25
  end
data/lib/build/files.rb CHANGED
@@ -19,10 +19,11 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  require_relative 'files/list'
22
+ require_relative 'files/paths'
22
23
  require_relative 'files/glob'
23
24
  require_relative 'files/directory'
24
25
 
25
26
  require_relative 'files/state'
26
27
  require_relative 'files/monitor'
27
28
 
28
- require_relative 'files/path/filesystem'
29
+ require_relative 'files/system'
@@ -24,16 +24,47 @@ module Build::Files::DirectorySpec
24
24
  include Build::Files
25
25
 
26
26
  describe Build::Files::Directory do
27
- let(:path) {Path.new("/foo/bar/baz", "/bob")}
27
+ let(:path) {Path.new("/foo/bar/baz", "/foo")}
28
28
  let(:directory) {Directory.new(path)}
29
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
+
30
36
  it "has a root and path component" do
31
37
  expect(directory.root).to be == path
38
+ expect(directory.to_path).to be == path
39
+
32
40
  expect(directory.roots).to be_include(path)
33
41
  end
34
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
+
35
53
  it "includes subpaths" do
36
54
  expect(directory).to be_include "/foo/bar/baz/bob/dole"
37
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
38
69
  end
39
70
  end
@@ -31,5 +31,13 @@ module Build::Files::GlobSpec
31
31
 
32
32
  expect(paths.count).to be >= 1
33
33
  end
34
+
35
+ it "can be used as key in hash" do
36
+ cache = {}
37
+
38
+ cache[path.glob("*.rb")] = true
39
+
40
+ expect(cache).to be_include(path.glob("*.rb"))
41
+ end
34
42
  end
35
43
  end
@@ -166,7 +166,14 @@ module Build::Files::ListSpec
166
166
 
167
167
  cache[Paths.new(path)] = true
168
168
 
169
- expect(cache).to include(Paths.new(path))
169
+ expect(cache).to be_include(Paths.new(path))
170
+ end
171
+
172
+ it "can be constructed from a list of relative paths" do
173
+ paths = Paths.directory('/foo', ['bar', 'baz', 'bob'])
174
+
175
+ expect(paths.count).to be 3
176
+ expect(paths).to be_include Path.new('/foo/bar')
170
177
  end
171
178
  end
172
179
  end
@@ -22,7 +22,7 @@
22
22
 
23
23
  require 'build/files/monitor'
24
24
  require 'build/files/path'
25
- require 'build/files/path/filesystem'
25
+ require 'build/files/system'
26
26
  require 'build/files/directory'
27
27
 
28
28
  module Build::Files::MonitorSpec
@@ -56,13 +56,35 @@ module Build::Files::StateSpec
56
56
  expect(state.removed).to be == []
57
57
  expect(state.missing).to be == []
58
58
  end
59
+ end
60
+
61
+ describe Build::Files::State do
62
+ before(:each) do
63
+ @temporary_files = Build::Files::Paths.directory(__dir__, ['a'])
64
+ @temporary_files.touch
65
+
66
+ @new_files = Build::Files::State.new(@temporary_files)
67
+ @old_files = Build::Files::State.new(Build::Files::Glob.new(__dir__, "*.rb"))
68
+ end
69
+
70
+ after(:each) do
71
+ @temporary_files.delete
72
+ end
73
+
74
+ let(:empty) {Build::Files::State.new(Build::Files::Paths::NONE)}
59
75
 
60
76
  it "should be clean with empty inputs or outputs" do
61
- empty = Build::Files::State.new(Build::Files::Paths::NONE)
62
- something = Build::Files::State.new(files)
63
-
64
- expect(Build::Files::State.dirty?(empty, something)).to be false
65
- expect(Build::Files::State.dirty?(something, empty)).to be false
77
+ expect(Build::Files::State.dirty?(empty, @new_files)).to be false
78
+ expect(Build::Files::State.dirty?(@new_files, empty)).to be false
79
+ end
80
+
81
+ it "should be clean if files are newer" do
82
+ expect(Build::Files::State.dirty?(@old_files, @new_files)).to be false
83
+ end
84
+
85
+ it "should be dirty if files are modified" do
86
+ # In this case, the file mtime is usually different so...
87
+ expect(Build::Files::State.dirty?(@new_files, @old_files)).to be true
66
88
  end
67
89
  end
68
90
  end
@@ -20,7 +20,7 @@
20
20
 
21
21
  require 'build/files'
22
22
  require 'build/files/path'
23
- require 'build/files/path/filesystem'
23
+ require 'build/files/system'
24
24
 
25
25
  require 'pathname'
26
26
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: build-files
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-22 00:00:00.000000000 Z
11
+ date: 2015-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,16 +71,17 @@ files:
71
71
  - lib/build/files/list.rb
72
72
  - lib/build/files/monitor.rb
73
73
  - lib/build/files/path.rb
74
- - lib/build/files/path/filesystem.rb
74
+ - lib/build/files/paths.rb
75
75
  - lib/build/files/state.rb
76
+ - lib/build/files/system.rb
76
77
  - lib/build/files/version.rb
77
78
  - spec/build/files/directory_spec.rb
78
- - spec/build/files/filesystem_spec.rb
79
79
  - spec/build/files/glob_spec.rb
80
80
  - spec/build/files/list_spec.rb
81
81
  - spec/build/files/monitor_spec.rb
82
82
  - spec/build/files/path_spec.rb
83
83
  - spec/build/files/state_spec.rb
84
+ - spec/build/files/system_spec.rb
84
85
  homepage: ''
85
86
  licenses:
86
87
  - MIT
@@ -108,9 +109,9 @@ summary: Build::Files is a set of idiomatic classes for dealing with paths and m
108
109
  directories.
109
110
  test_files:
110
111
  - spec/build/files/directory_spec.rb
111
- - spec/build/files/filesystem_spec.rb
112
112
  - spec/build/files/glob_spec.rb
113
113
  - spec/build/files/list_spec.rb
114
114
  - spec/build/files/monitor_spec.rb
115
115
  - spec/build/files/path_spec.rb
116
116
  - spec/build/files/state_spec.rb
117
+ - spec/build/files/system_spec.rb