fun_with_files 0.0.14 → 0.0.18

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.
Files changed (58) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.markdown +15 -3
  3. data/Gemfile +17 -7
  4. data/{README.rdoc → README.markdown} +12 -11
  5. data/Rakefile +3 -3
  6. data/VERSION +1 -1
  7. data/lib/fun_with/files/bootstrapper.rb +87 -0
  8. data/lib/fun_with/files/core_extensions/file.rb +15 -3
  9. data/lib/fun_with/files/core_extensions/set.rb +12 -0
  10. data/lib/fun_with/files/core_extensions/true_class.rb +11 -0
  11. data/lib/fun_with/files/digest_methods.rb +50 -17
  12. data/lib/fun_with/files/directory_builder.rb +9 -4
  13. data/lib/fun_with/files/downloader.rb +29 -16
  14. data/lib/fun_with/files/errors.rb +9 -1
  15. data/lib/fun_with/files/file_manipulation_methods.rb +25 -15
  16. data/lib/fun_with/files/file_orderer.rb +2 -0
  17. data/lib/fun_with/files/file_path.rb +242 -156
  18. data/lib/fun_with/files/file_path_class_methods.rb +23 -2
  19. data/lib/fun_with/files/file_permission_methods.rb +18 -7
  20. data/lib/fun_with/files/file_requirements.rb +63 -7
  21. data/lib/fun_with/files/requirements/manager.rb +104 -0
  22. data/lib/fun_with/files/root_path.rb +3 -3
  23. data/lib/fun_with/files/stat_methods.rb +33 -0
  24. data/lib/fun_with/files/string_behavior.rb +6 -2
  25. data/lib/fun_with/files/utils/byte_size.rb +143 -0
  26. data/lib/fun_with/files/utils/opts.rb +26 -0
  27. data/lib/fun_with/files/utils/succession.rb +47 -0
  28. data/lib/fun_with/files/utils/timestamp.rb +47 -0
  29. data/lib/fun_with/files/utils/timestamp_format.rb +31 -0
  30. data/lib/fun_with/files/watcher.rb +157 -0
  31. data/lib/fun_with/files/watchers/directory_watcher.rb +67 -0
  32. data/lib/fun_with/files/watchers/file_watcher.rb +45 -0
  33. data/lib/fun_with/files/watchers/missing_watcher.rb +23 -0
  34. data/lib/fun_with/files/watchers/node_watcher.rb +44 -0
  35. data/lib/fun_with/testing/assertions/fun_with_files.rb +91 -0
  36. data/lib/fun_with/testing/test_case_extensions.rb +12 -0
  37. data/lib/fun_with_files.rb +5 -31
  38. data/test/helper.rb +13 -5
  39. data/test/test_core_extensions.rb +6 -0
  40. data/test/test_descent.rb +2 -2
  41. data/test/test_directory_builder.rb +29 -10
  42. data/test/test_extension_methods.rb +62 -0
  43. data/test/test_file_manipulation.rb +4 -4
  44. data/test/test_file_path.rb +83 -56
  45. data/test/test_file_requirements.rb +36 -0
  46. data/test/test_fun_with_files.rb +1 -1
  47. data/test/test_fwf_assertions.rb +62 -0
  48. data/test/test_moving_files.rb +111 -0
  49. data/test/test_permission_methods.rb +22 -0
  50. data/test/test_root_path.rb +9 -0
  51. data/test/test_stat_methods.rb +17 -0
  52. data/test/test_timestamping.rb +74 -0
  53. data/test/test_utils_bytesize.rb +71 -0
  54. data/test/test_utils_succession.rb +30 -0
  55. data/test/test_watchers.rb +196 -0
  56. metadata +59 -13
  57. /data/lib/fun_with/files/core_extensions/{false.rb → false_class.rb} +0 -0
  58. /data/lib/fun_with/files/core_extensions/{nil.rb → nil_class.rb} +0 -0
@@ -0,0 +1,196 @@
1
+ require 'helper'
2
+
3
+ class TestWatchers < FunWith::Files::TestCase
4
+ context "testing Watcher as it benevolently watches over the files placed under its care" do
5
+ setup do
6
+ tmpdir # assigns @tmpdir a freshly created temp directory
7
+ self.watch @tmpdir
8
+ end
9
+
10
+ teardown do
11
+ @tmpdir.rm
12
+ end
13
+
14
+ should "watch an empty directory as a subdirectory and a file are added" do
15
+ @tmpdir.touch_dir :lethe do |d|
16
+ file = d.join( "forgotten_file.txt" )
17
+ file.write( "someone help me remember this" )
18
+
19
+ get_changes do
20
+ assert_changes :created, d, file
21
+ end
22
+
23
+ file.append( "\nbecause I don't trust my brain to keep track of things" )
24
+
25
+ get_changes(1) do
26
+ assert_changes :modified, file
27
+ end
28
+
29
+ d.rm
30
+
31
+ get_changes do
32
+ assert_changes :deleted, d, file
33
+ end
34
+ end
35
+ end
36
+
37
+ should "watch an empty directory as a bunch of changes happen" do
38
+ @tmpdir.touch_dir( :battles ) do |d0|
39
+ @tmpdir.touch_dir( :bunker_hill ) do |d1|
40
+ file0 = d1.join( "troop_movements.csv" )
41
+ file0.write( "My dearest Sarah,\n\tI fear this may be the last time I write to you. Our forces are outnumbered." )
42
+
43
+ get_changes do
44
+ assert_changes :created, d0, d1, file0
45
+ end
46
+
47
+ file0.append "Supplies are scarce and the horses have lost their patience with us."
48
+
49
+ get_changes(1) do
50
+ assert_changes :modified, file0
51
+ end
52
+
53
+ d1.rm
54
+
55
+ get_changes(2) do
56
+ assert_changes :deleted, d1, file0
57
+ end
58
+ end
59
+
60
+ d0.rm
61
+
62
+ get_changes(1) do
63
+ assert_changes :deleted, d0
64
+ end
65
+ end
66
+ end
67
+
68
+ should "watch for a file that doesn't exist yet" do
69
+ @tmpdir.touch_dir( "web_app" ) do |d|
70
+ watch( d.join( "restart.txt" ) )
71
+
72
+ get_changes(0)
73
+
74
+ restart_file = d.touch( "restart.txt" )
75
+
76
+ get_changes(1) do
77
+ assert_changes :created, restart_file
78
+ end
79
+
80
+ restart_file.rm
81
+
82
+ get_changes(1) do
83
+ assert_changes :deleted, restart_file
84
+ end
85
+
86
+ get_changes(0)
87
+ end
88
+ end
89
+
90
+ should "build out a filesystem using DirectoryBuilder" do
91
+ @tmpdir.touch_dir( :ebook ) do |ebook|
92
+ watch ebook
93
+
94
+ DirectoryBuilder.create( ebook ) do |builder|
95
+ builder.dir( :html ) do
96
+ builder.file "title_page.xhtml", "Make sure we get some neato art to go here."
97
+ builder.file "chapter1.xhtml", "Besta times, worsta times, y'know?"
98
+ builder.file "chapter2.xhtml", "I see a magpie perched on the roof."
99
+ end
100
+
101
+ builder.dir( :css ) do
102
+ builder.file "main.css", "p{ background-color: painfully-pink}"
103
+ builder.file "title_page.css", "body{ width: 80% }"
104
+ end
105
+
106
+ builder.dir( :images ) do
107
+ builder.file "cover.png", "We shoulda hired a graphic designer"
108
+ end
109
+ end
110
+
111
+ html_dir = ebook / :html
112
+
113
+ images_dir = ebook / :images
114
+ cover_file = images_dir / "cover.png"
115
+
116
+ get_changes(9) do
117
+ assert_changes :created,
118
+ # ebook, # already existed when the watcher started
119
+ html_dir,
120
+ html_dir / "title_page.xhtml",
121
+ ebook / :css,
122
+ ebook / :css / "main.css",
123
+ images_dir,
124
+ cover_file
125
+ end
126
+
127
+ cover_file.append ", Trevor worked out okay last time, can we use him again?"
128
+
129
+ # debugger
130
+
131
+ get_changes(2) do
132
+ assert_changes :modified, cover_file, images_dir, html_dir
133
+ end
134
+
135
+ images_dir.rm
136
+
137
+ get_changes(2) do
138
+ assert_changes :deleted, images_dir, cover_file, html_dir
139
+ end
140
+ end
141
+ end
142
+
143
+ should "only notice changes that aren't excluded by filters" do
144
+
145
+ @tmpdir.touch_dir( :application_code ) do |code|
146
+ watch( code )
147
+
148
+ @watcher.filter( notice: /\.cpp$/, ignore: /main.cpp$/ )
149
+
150
+ f0 = code.touch( "main.cpp" )
151
+ f1 = code.touch( "counter.cpp" )
152
+
153
+ get_changes( count: 1 ) do
154
+ assert_changes :added, f1
155
+ end
156
+ end
157
+ end
158
+ end
159
+
160
+ def watch( *paths )
161
+ @watcher = Watcher.watch( *paths ).sleep_interval( 0.01 )
162
+ end
163
+
164
+ def get_changes( count: nil, expected: nil, &block )
165
+ @changes = @watcher.update
166
+ yield if block_given?
167
+ assert_change_count( count ) unless count.nil?
168
+ assert_change_set( expected ) unless expected.nil?
169
+ end
170
+
171
+ def assert_changes( status, *paths )
172
+ assert_kind_of Hash, @changes
173
+
174
+ oopsies = {}
175
+
176
+ for path in paths
177
+ path_to_report = path.relative_path_from(@tmpdir).to_s
178
+
179
+ if @changes.has_key?( path )
180
+ oopsies[path_to_report] = :change_not_reported
181
+ elsif status != @changes[path]
182
+ oopsies[path_to_report] = { :expected => status, :actual => @changes[path] }
183
+ end
184
+
185
+ unless oopsies.fwf_blank?
186
+ assert false, "Unexpected:" + oopsies.inspect
187
+ end
188
+ end
189
+ end
190
+
191
+ def assert_change_count( i )
192
+ assert defined?( @changes )
193
+ assert_kind_of Hash, @changes
194
+ assert_length i, @changes
195
+ end
196
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fun_with_files
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryce Anderson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-26 00:00:00.000000000 Z
11
+ date: 2024-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xdg
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2'
19
+ version: '7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2'
26
+ version: '7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: debug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: fun_with_testing
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -31,6 +45,9 @@ dependencies:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
47
  version: '0.0'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 0.0.7
34
51
  type: :development
35
52
  prerelease: false
36
53
  version_requirements: !ruby/object:Gem::Requirement
@@ -38,6 +55,9 @@ dependencies:
38
55
  - - "~>"
39
56
  - !ruby/object:Gem::Version
40
57
  version: '0.0'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.0.7
41
61
  description: |2
42
62
  A more intuitive syntax for performing a variety of file actions. Examples:
43
63
  "/".fwf_filepath.join('usr', 'bin', 'bash').touch
@@ -56,15 +76,18 @@ extensions: []
56
76
  extra_rdoc_files:
57
77
  - CHANGELOG.markdown
58
78
  - LICENSE.txt
59
- - README.rdoc
79
+ - README.markdown
60
80
  files:
81
+ - "./lib/fun_with/files/bootstrapper.rb"
61
82
  - "./lib/fun_with/files/core_extensions/array.rb"
62
- - "./lib/fun_with/files/core_extensions/false.rb"
83
+ - "./lib/fun_with/files/core_extensions/false_class.rb"
63
84
  - "./lib/fun_with/files/core_extensions/file.rb"
64
85
  - "./lib/fun_with/files/core_extensions/hash.rb"
65
- - "./lib/fun_with/files/core_extensions/nil.rb"
86
+ - "./lib/fun_with/files/core_extensions/nil_class.rb"
66
87
  - "./lib/fun_with/files/core_extensions/object.rb"
88
+ - "./lib/fun_with/files/core_extensions/set.rb"
67
89
  - "./lib/fun_with/files/core_extensions/string.rb"
90
+ - "./lib/fun_with/files/core_extensions/true_class.rb"
68
91
  - "./lib/fun_with/files/digest_methods.rb"
69
92
  - "./lib/fun_with/files/directory_builder.rb"
70
93
  - "./lib/fun_with/files/downloader.rb"
@@ -78,10 +101,24 @@ files:
78
101
  - "./lib/fun_with/files/gem_api.rb"
79
102
  - "./lib/fun_with/files/pathname_extensions.rb"
80
103
  - "./lib/fun_with/files/remote_path.rb"
104
+ - "./lib/fun_with/files/requirements/manager.rb"
81
105
  - "./lib/fun_with/files/root_path.rb"
106
+ - "./lib/fun_with/files/stat_methods.rb"
82
107
  - "./lib/fun_with/files/string_behavior.rb"
83
108
  - "./lib/fun_with/files/string_extensions.rb"
109
+ - "./lib/fun_with/files/utils/byte_size.rb"
110
+ - "./lib/fun_with/files/utils/opts.rb"
111
+ - "./lib/fun_with/files/utils/succession.rb"
112
+ - "./lib/fun_with/files/utils/timestamp.rb"
113
+ - "./lib/fun_with/files/utils/timestamp_format.rb"
114
+ - "./lib/fun_with/files/watcher.rb"
115
+ - "./lib/fun_with/files/watchers/directory_watcher.rb"
116
+ - "./lib/fun_with/files/watchers/file_watcher.rb"
117
+ - "./lib/fun_with/files/watchers/missing_watcher.rb"
118
+ - "./lib/fun_with/files/watchers/node_watcher.rb"
84
119
  - "./lib/fun_with/files/xdg_extensions.rb"
120
+ - "./lib/fun_with/testing/assertions/fun_with_files.rb"
121
+ - "./lib/fun_with/testing/test_case_extensions.rb"
85
122
  - "./lib/fun_with_files.rb"
86
123
  - "./test/data/empty.txt"
87
124
  - "./test/data/grep1.txt"
@@ -102,25 +139,35 @@ files:
102
139
  - "./test/test_descent.rb"
103
140
  - "./test/test_digest.rb"
104
141
  - "./test/test_directory_builder.rb"
142
+ - "./test/test_extension_methods.rb"
105
143
  - "./test/test_file_manipulation.rb"
106
144
  - "./test/test_file_path.rb"
145
+ - "./test/test_file_requirements.rb"
107
146
  - "./test/test_fun_with_files.rb"
147
+ - "./test/test_fwf_assertions.rb"
108
148
  - "./test/test_globbing.rb"
109
149
  - "./test/test_loading.rb"
150
+ - "./test/test_moving_files.rb"
151
+ - "./test/test_permission_methods.rb"
110
152
  - "./test/test_root_path.rb"
153
+ - "./test/test_stat_methods.rb"
111
154
  - "./test/test_symlinking.rb"
155
+ - "./test/test_timestamping.rb"
112
156
  - "./test/test_touching.rb"
157
+ - "./test/test_utils_bytesize.rb"
158
+ - "./test/test_utils_succession.rb"
159
+ - "./test/test_watchers.rb"
113
160
  - CHANGELOG.markdown
114
161
  - Gemfile
115
162
  - LICENSE.txt
116
- - README.rdoc
163
+ - README.markdown
117
164
  - Rakefile
118
165
  - VERSION
119
166
  homepage: http://github.com/darthschmoo/fun_with_files
120
167
  licenses:
121
168
  - MIT
122
169
  metadata: {}
123
- post_install_message:
170
+ post_install_message:
124
171
  rdoc_options: []
125
172
  require_paths:
126
173
  - lib
@@ -135,9 +182,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
182
  - !ruby/object:Gem::Version
136
183
  version: '0'
137
184
  requirements: []
138
- rubyforge_project:
139
- rubygems_version: 2.4.6
140
- signing_key:
185
+ rubygems_version: 3.5.6
186
+ signing_key:
141
187
  specification_version: 4
142
188
  summary: A mashup of several File, FileUtils, and Dir class functions, with a peppy,
143
189
  fun-loving syntax