libis-tools 1.0.2 → 1.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5e609222120f658fb18e1594ed1f87f0c35bde28
4
- data.tar.gz: 66d3563d04e59fd324a593754a74947b1c3a722f
2
+ SHA256:
3
+ metadata.gz: 90860bd5c61913c592d7dd212e9ac49cde403217295a2abebe96bc15413a8421
4
+ data.tar.gz: 0037ce1b2ddf54ff80862648c6a596398c6326e88a399148d2df7f4c81a4f0fd
5
5
  SHA512:
6
- metadata.gz: ef95ab98cc37ab82f24e92f1db943cd92eef3276964c5ee3c2591aa1575dda048bd01c2d6117a230726f6a7d735d1fca8d0591c0c256c206e868b57663782eec
7
- data.tar.gz: ab8ffbcec667aa8f6d618f2f5c3cbc5295a46bea69038f7c3e4616e465c3f01044b2cc22bddf1963f3dac96695135b773048bb46d4eb41a3570654a405450b67
6
+ metadata.gz: 98b63d9c943f7eaf01014ade5c3a1ec94f659c1b8920198d6705a074f4f76d440911fc3b0c7298a178c1a41f52d7b7d3f2b6f1b4a4e9aea02a748f8f85a02763
7
+ data.tar.gz: 4b712432c22a54e44939d076aff84bf1d1628bdfb99efdf7dbb9c1f9e90597ac98e62331767e2f1f2e7c00dcd3849d72998fb6100fc468afce137682db352394
@@ -262,13 +262,13 @@ module Libis
262
262
  next if file_name =~ /^\.\.?$/
263
263
  entry = File.join(File.absolute_path(base_dir), file_name)
264
264
  unless File.file?(entry)
265
- puts "Skipping directory #{entry}." unless @report
265
+ prompt.say "Skipping directory #{entry}." unless @report
266
266
  write_report(entry, '', '', 'Directory - skipped.')
267
267
  count[:skipped_dir] += 1
268
268
  next
269
269
  end
270
270
  unless file_name =~ parse_regex
271
- puts "Skipping file #{file_name}. File name does not match expression." unless @report
271
+ prompt.say "Skipping file #{file_name}. File name does not match expression." unless @report
272
272
  write_report(entry, '', '', 'Mismatch - skipped.')
273
273
  count[:unmatched_file] += 1
274
274
  next
@@ -278,7 +278,7 @@ module Libis
278
278
  target_dir = File.dirname(target)
279
279
  target_dir = File.join(base_dir, target_dir) unless target_dir[0] == '/'
280
280
  unless target_dir_list.include?(target_dir)
281
- puts "-> Create directory '#{target_dir}'" unless @report
281
+ prompt.say "-> Create directory '#{target_dir}'" unless @report
282
282
  FileUtils.mkpath(target_dir) unless dummy_operation
283
283
  target_dir_list << target_dir
284
284
  end
@@ -289,7 +289,7 @@ module Libis
289
289
  if compare_entry(entry, target_path)
290
290
  remark = 'Duplicate - skipped.'
291
291
  count[:duplicate] += 1
292
- $stderr.puts "Duplicate file entry: #{entry}." unless @report
292
+ prompt.error "Duplicate file entry: #{entry}." unless @report
293
293
  else
294
294
  # puts "source: #{File.mtime(entry)} #{'%11s' % Filesize.new(File.size(entry)).pretty} #{entry}"
295
295
  # puts "target: #{File.mtime(target_path)} #{'%11s' % Filesize.new(File.size(target_path)).pretty} #{target_path}"
@@ -299,7 +299,7 @@ module Libis
299
299
  count[:update] += 1
300
300
  else
301
301
  remark = 'Duplicate - rejected.'
302
- $stderr.puts "ERROR: #{entry} exists with different content." unless @report
302
+ prompt.error "ERROR: #{entry} exists with different content." unless @report
303
303
  count[:reject] += 1
304
304
  end
305
305
  end
@@ -308,7 +308,7 @@ module Libis
308
308
  count[:move] += 1
309
309
  end
310
310
  if action
311
- puts "-> #{file_operation} '#{file_name}' to '#{target}'" unless @report
311
+ prompt.say "-> #{file_operation} '#{file_name}' to '#{target}'" unless @report
312
312
  case file_operation
313
313
  when 'move'
314
314
  FileUtils.move(entry, File.join(target_dir, target_file), force: true)
@@ -0,0 +1,15 @@
1
+
2
+ # Extension class for Array
3
+ class Array
4
+
5
+ # Removes all empty entries
6
+ def cleanup
7
+ self.delete_if { |v| v.nil? || (v.respond_to?(:empty?) ? v.empty? : false) }
8
+ end unless method_defined? :cleanup
9
+
10
+ # Removes all empty entries recursively in the array and each Hash in it
11
+ def recursive_cleanup
12
+ cleanup.each { |v| v.recursive_cleanup if Array === v || Hash === v }
13
+ end unless method_defined? :recursive_cleanup
14
+
15
+ end
@@ -10,11 +10,8 @@ class Hash
10
10
 
11
11
  # Removes all hash entries for which value.empty? is true. Performed recursively.
12
12
  def recursive_cleanup
13
- delete_proc = Proc.new do |_, v|
14
- v.delete_if(&delete_proc) if v.kind_of?(Hash)
15
- v.nil? || (v.respond_to?(:empty?) ? v.empty? : false)
16
- end
17
- self.delete_if &delete_proc
13
+ cleanup
14
+ each { |_, v| v.recursive_cleanup if Array === v || Hash === v }
18
15
  end unless method_defined? :recursive_cleanup
19
16
 
20
17
  # Merges two hashes, but does so recursively.
@@ -66,7 +63,7 @@ class Hash
66
63
  end unless method_defined? :key_strings_to_symbols!
67
64
 
68
65
  # Return new Hash with all keys converted to symbols.
69
- # @param [Hash] opts valid options are:
66
+ # @param [Hash] options valid options are:
70
67
  # * recursive : perform operation recursively
71
68
  # * upcase : convert all keys to upper case
72
69
  # * downcase : convert all keys to lower case
@@ -0,0 +1,8 @@
1
+ # Symbol monkey patch to allow map(&:method) to take arguments. Allows: [2,3].map(&:+.(10)) # => [12,13]
2
+ # See: https://stackoverflow.com/questions/23695653/can-you-supply-arguments-to-the-mapmethod-syntax-in-ruby
3
+ # for more information,
4
+ class Symbol
5
+ def call(*args, &block)
6
+ ->(caller, *rest) { caller.public_send(self, *rest, *args, &block) }
7
+ end
8
+ end
@@ -1,5 +1,5 @@
1
1
  module Libis
2
2
  module Tools
3
- VERSION = '1.0.2'
3
+ VERSION = '1.0.3'
4
4
  end
5
5
  end
@@ -30,7 +30,7 @@ describe 'Command' do
30
30
  result = Libis::Tools::Command.run('ls', '-1')
31
31
 
32
32
  output = result[:out]
33
- expect(output.size).to eq (entries.size)
33
+ expect(output.size).to eq entries.size
34
34
  expect(output.sort).to match entries
35
35
  expect(result[:err]).to eq []
36
36
  expect(result[:status]).to eq 0
@@ -42,7 +42,7 @@ describe 'Command' do
42
42
  result = Libis::Tools::Command.run('ls', '-1', '-a', '-p')
43
43
 
44
44
  output = result[:out]
45
- expect(output.size).to eq (entries.size + 2)
45
+ expect(output.size).to eq entries.size + 2
46
46
  expect(output[0]).to eq './'
47
47
  expect(output[1]).to eq '../'
48
48
  expect(output[2..-1].sort).to match entries
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libis-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kris Dekeyser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-01 00:00:00.000000000 Z
11
+ date: 2019-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -332,6 +332,7 @@ files:
332
332
  - lib/libis/tools/config_file.rb
333
333
  - lib/libis/tools/csv.rb
334
334
  - lib/libis/tools/deep_struct.rb
335
+ - lib/libis/tools/extend/array.rb
335
336
  - lib/libis/tools/extend/empty.rb
336
337
  - lib/libis/tools/extend/hash.rb
337
338
  - lib/libis/tools/extend/kernel.rb
@@ -339,6 +340,7 @@ files:
339
340
  - lib/libis/tools/extend/roo.rb
340
341
  - lib/libis/tools/extend/string.rb
341
342
  - lib/libis/tools/extend/struct.rb
343
+ - lib/libis/tools/extend/symbol.rb
342
344
  - lib/libis/tools/logger.rb
343
345
  - lib/libis/tools/mets_dnx.rb
344
346
  - lib/libis/tools/mets_file.rb
@@ -398,8 +400,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
398
400
  - !ruby/object:Gem::Version
399
401
  version: '0'
400
402
  requirements: []
401
- rubyforge_project:
402
- rubygems_version: 2.5.1
403
+ rubygems_version: 3.0.3
403
404
  signing_key:
404
405
  specification_version: 4
405
406
  summary: LIBIS toolbox.