posix-fileutils 0.1.15 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YWI5OWRjY2Q5N2IxZDczYTFkN2U1OTJmNDc1NTQ0ZDI4MjIyOWQyZQ==
4
+ ZmU2NzhiMzYyN2Y4Zjg5MTI2ZDdhODI3YzJhODU4YTkzYTlmYzc4NA==
5
5
  data.tar.gz: !binary |-
6
- NmY5ODMzNTIyODM0MTc4ZDAwZmUwY2Q1MWEwNDA0ZjI3MWZhYzg5Ng==
6
+ ZmM1MWFiMWZjZmI2MTkwMjQzYThmYzc2ZGQxOTFhOWViNDRlNGY1Yg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjkyMjY1Y2Q0MWNhOTRlNjJhYjk2ZjUyNjM2NDJkMjZlZDJjNDFlNjRiMmEy
10
- Yjg5NTU5OTI2NzM0MThjNWZjYjZiODhjYzk5MGUwN2FiYzM5Mzg2MTJjMTBi
11
- MjNmZTIzM2UzN2ZiOTM1YTA5YTBjNTYxNjJiZDY3ZmI1OTQ1Mjc=
9
+ ZmU4ODU5NzYwMzE4MzI0MWY2N2VmMDRkZmRlMGZjZmYxNjM1YTc4YTA4MjQ1
10
+ ZmM4NjMyZjQ0OWU4NjY1MzRlMmZlMTdiZTBkYzYwM2E1Y2UzM2MzMzgxZTI1
11
+ NmJlNWYwNTAxNzliMGRiOWRiODE1YjVhNmE1MGEyYzFlMjliNTE=
12
12
  data.tar.gz: !binary |-
13
- Njc0MzkwY2M1ZWZhYWE1OWM3MzdiM2ZkMDc2YTdjMTc3OTA4YTAzZTdlNDFi
14
- ZjVlNTFhNTdjMzFlYWU5ZDI4MzlhOTRlZmFiMGIwOTY1ZjEwNDZjNjM0NmUz
15
- N2IyZmE1MGY0NjdmM2RkMmU1N2IwMTZlOTIyZTM4MmYwN2MzYzk=
13
+ YzdlMGViNGJlZDBiMGI3OWM4ZGFhZDA3OGZmNjhjZWU5ODAyZGUyMDBjYWRl
14
+ ZDFiZDAzODQ4Yjk4NjQ4YzAzYWRiNmE1NjM2YjljMmJmMGQ2ZjNmODlkMTFk
15
+ OWM2MzQ3OTEwNjc5YjI4NTUyNDg5ZGI1MTAwODBjYTk4NmMyODI=
@@ -130,8 +130,10 @@ module Fs
130
130
  end
131
131
 
132
132
  def self.parse_list_args list, *opts
133
+ opts = opts.to_set
134
+
133
135
  if list.a?
134
- return [[],[]] if list.count == 0
136
+ return [[],[].to_set] if list.count == 0
135
137
 
136
138
  list.map! do |elem| Pathname.new elem.to_s unless elem.kind_of? Pathname end
137
139
 
@@ -177,7 +179,7 @@ module Fs
177
179
  Kernel.system "rm #{opts.to_s}#{list.to_s}"
178
180
  end
179
181
 
180
- def self.mkdir list, *opts
182
+ def self.mkdir list, *opts, &block
181
183
  opts = opts.to_set
182
184
 
183
185
  list, opts = parse_list_args list, *opts
@@ -192,7 +194,34 @@ module Fs
192
194
  end
193
195
  end
194
196
 
195
- Kernel.system "mkdir #{opts.to_s}#{list.to_s}"
197
+ res = Kernel.system "mkdir #{opts.to_s}#{list.to_s}"
198
+
199
+ return res if res != true
200
+
201
+ raise ArgumentError, 'Only in case single directory creating passing block is permitted' if list.a? && block
202
+
203
+ if block
204
+ err = nil
205
+
206
+ cwd = Fs.pwd
207
+ old_defopts = @defopts.clone
208
+ Fs.cd list, *(opts&@popts[:mkdir])
209
+
210
+ @defopts += opts
211
+
212
+ begin
213
+ yield
214
+ rescue => e
215
+ err = e
216
+ end
217
+
218
+ Fs.cd Pathname.new(list).absolute? ? cwd : cwd.relative_path_from(self.pwd), *(opts&@popts[:mkdir])
219
+ @defopts = old_defopts
220
+
221
+ raise err if e
222
+ end
223
+
224
+ true
196
225
  end
197
226
 
198
227
  def self.touch list, *opts
@@ -208,7 +237,7 @@ module Fs
208
237
  res
209
238
  end
210
239
 
211
- def self.cd list, *opts
240
+ def self.cd list, *opts, &block
212
241
  opts = opts.to_set
213
242
 
214
243
  list, opts = parse_list_args list, *opts
@@ -218,8 +247,28 @@ module Fs
218
247
 
219
248
  return false unless list.directory?
220
249
 
250
+ cwd = self.pwd
251
+ old_defopts = @defopts.clone
252
+
253
+ @defopts += opts
254
+
221
255
  FileUtils.cd list.to_s, opts.include?(:v) ? {:verbose => true} : {:verbose => false}
222
256
 
257
+ if block
258
+ err = nil
259
+
260
+ begin
261
+ yield
262
+ rescue => e
263
+ err = e
264
+ end
265
+
266
+ self.cd Pathname.new(list).absolute? ? cwd : cwd.relative_path_from(self.pwd), *opts
267
+ @defopts = old_defopts
268
+
269
+ raise err if err
270
+ end
271
+
223
272
  true
224
273
  end
225
274
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: posix-fileutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - A. Levenkov