bagit 0.4.3 → 0.4.5

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
- SHA1:
3
- metadata.gz: 110811464b7bda7fe4a731155a75b09a4bfedb37
4
- data.tar.gz: bd81624253f0d2faff9a80bc58579e18512bc577
2
+ SHA256:
3
+ metadata.gz: e7fadd34fdac2ef57b5f9dd0746566eab445503621052ceba3106519e3961cbe
4
+ data.tar.gz: 9e80ad8ca552eac4267620e420b3467cefa46cf88955b94697b6e0dfda060ccb
5
5
  SHA512:
6
- metadata.gz: 3754fafd47c4e53a58c7b802ac4761194577dc751ed124fd41179199b009707b169ff36bb144061a94c3494414a40ca47964257871e5d622371efd0c4f99359f
7
- data.tar.gz: 10d1c42ed581a0f53018dbca881d9f4adb023d12e229fd6a7ed2c5a190b426e91b11b7ea417ef613b31f7fe6775dce09e71b362cc37205bf457fad91ac821929
6
+ metadata.gz: 390236a9a4aa9cf50374d016b5fe14f11ec56c6430cdf6e36ec6160a5ceb95abb49b5c17733ad1fe1b598209bd9c1c9bcf8b14f356fb3d6bd6fabd2f5de91252
7
+ data.tar.gz: ff17dd90c78f4c9ba25ca49d2952ca0b87078a27756368f2948dadbd5f4318a5afa43b1569190fefabfa554812c902e6df5e26358b31bf91d2490db032742d94
data/.gitignore CHANGED
@@ -8,4 +8,5 @@ vendor
8
8
  Gemfile.lock
9
9
  .bundle
10
10
  .project
11
- .idea
11
+ .idea
12
+ coverage
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
2
4
 
3
5
  gemspec
data/Rakefile CHANGED
@@ -1,22 +1,19 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
1
+ # frozen_string_literal: true
2
+
3
+ require "rubygems"
4
+ require "bundler/setup"
3
5
  Bundler.setup(:default, :development, :test)
4
6
 
5
- require 'rake'
6
- require 'rdoc/task'
7
- require 'rspec/core/rake_task'
8
- require 'rubocop/rake_task'
7
+ require "rake"
8
+ require "rdoc/task"
9
+ require "rspec/core/rake_task"
10
+ require "standard/rake"
9
11
 
10
12
  Bundler::GemHelper.install_tasks
11
13
 
12
- desc 'Run rubocop'
13
- task :rubocop do
14
- RuboCop::RakeTask.new
15
- end
16
-
17
14
  RSpec::Core::RakeTask.new do |t|
18
- t.pattern = 'spec/**/*_spec.rb'
15
+ t.pattern = "spec/**/*_spec.rb"
19
16
  t.rspec_opts = %w[--format documentation --color]
20
17
  end
21
18
 
22
- task default: [:rubocop, :spec]
19
+ task default: [:standard, :spec]
data/bagit.gemspec CHANGED
@@ -1,33 +1,34 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'bagit/version'
5
+ require "bagit/version"
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "bagit"
8
- spec.version = BagIt::VERSION
9
- spec.summary = "BagIt package generation and validation"
8
+ spec.name = "bagit"
9
+ spec.version = BagIt::VERSION
10
+ spec.summary = "BagIt package generation and validation"
10
11
  spec.description = "Ruby Library and Command Line tools for bagit"
11
- spec.email = "jamie@jamielittle.org"
12
- spec.homepage = 'http://github.com/tipr/bagit'
13
- spec.authors = ["Tom Johnson, Francesco Lazzarino, Jamie Little"]
14
- spec.license = "MIT"
12
+ spec.email = "jamie@jamielittle.org"
13
+ spec.homepage = "http://github.com/tipr/bagit"
14
+ spec.authors = ["Tom Johnson, Francesco Lazzarino, Jamie Little"]
15
+ spec.license = "MIT"
15
16
 
16
- spec.required_ruby_version = '~> 2.0'
17
+ spec.required_ruby_version = ">= 2.0", "< 3.2"
17
18
 
18
- spec.add_dependency 'validatable', '~> 1.6'
19
- spec.add_dependency 'docopt', '~> 0.5.0'
19
+ spec.add_dependency "validatable", "~> 1.6"
20
+ spec.add_dependency "docopt", "~> 0.5.0"
20
21
 
21
- spec.add_development_dependency 'bixby'
22
- spec.add_development_dependency 'bundler'
23
- spec.add_development_dependency 'coveralls'
24
- spec.add_development_dependency 'pry'
25
- spec.add_development_dependency 'pry-byebug'
26
- spec.add_development_dependency 'rake', '~> 10.4'
27
- spec.add_development_dependency 'rspec', '~> 3'
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "coveralls"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "pry-byebug"
26
+ spec.add_development_dependency "rake", ">= 12.3.3"
27
+ spec.add_development_dependency "rspec", "~> 3"
28
+ spec.add_development_dependency "standard"
28
29
 
29
- spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
30
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
31
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
30
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
31
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
32
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
32
33
  spec.require_paths = ["lib"]
33
34
  end
data/bin/bagit CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bagit'
4
5
  require 'docopt'
5
6
  require 'logger'
6
- require 'pry'
7
7
  logger = Logger.new(STDOUT)
8
8
 
9
9
  doc = <<DOCOPT
@@ -84,43 +84,33 @@ begin
84
84
  # TODO: implement delete for data and tag files; remove for tag files.
85
85
 
86
86
  # handle add/delete bag data files
87
- unless opts['-f'].nil?
88
- # TODO: add files in nested directories
89
- opts['-f'].each do |datafile|
90
- begin
91
- if opts['add'] || opts['new']
92
- bag.add_file(File.basename(datafile), datafile)
93
- elsif opts['delete']
94
- bag.remove_file(File.basename(datafile))
95
- end
96
- rescue StandardError => e
97
- logger.error("Failed operation on bag file: #{e.message}")
98
- end
87
+ opts['-f']&.each do |datafile|
88
+ if opts['add'] || opts['new']
89
+ bag.add_file(File.basename(datafile), datafile)
90
+ elsif opts['delete']
91
+ bag.remove_file(File.basename(datafile))
99
92
  end
93
+ rescue StandardError => e
94
+ logger.error("Failed operation on bag file: #{e.message}")
100
95
  end
101
96
 
102
97
  # handle adding tag files
103
- unless opts['-t'].nil?
104
- # TODO: add files in nested directories
105
- opts['-t'].each do |tagfile|
106
- begin
107
- if opts['add'] || opts['new']
108
- # if it does, try to manifest it
109
- if File.exist?(File.join(bag.bag_dir, File.basename(tagfile)))
110
- bag.add_tag_file(tagfile)
111
- # otherwise, add it
112
- else
113
- bag.add_tag_file(File.basename(tagfile), tagfile)
114
- end
115
- elsif opts['delete']
116
- bag.delete_tag_file(File.basename(tagfile))
117
- elsif opts['remove']
118
- bag.remove_tag_file(File.basename(tagfile))
119
- end
120
- rescue StandardError => e
121
- logger.error("Failed operation on tag file: #{e.message}".red)
98
+ opts['-t']&.each do |tagfile|
99
+ if opts['add'] || opts['new']
100
+ # if it does, try to manifest it
101
+ if File.exist?(File.join(bag.bag_dir, File.basename(tagfile)))
102
+ bag.add_tag_file(tagfile)
103
+ # otherwise, add it
104
+ else
105
+ bag.add_tag_file(File.basename(tagfile), tagfile)
122
106
  end
107
+ elsif opts['delete']
108
+ bag.delete_tag_file(File.basename(tagfile))
109
+ elsif opts['remove']
110
+ bag.remove_tag_file(File.basename(tagfile))
123
111
  end
112
+ rescue StandardError => e
113
+ logger.error("Failed operation on tag file: #{e.message}".red)
124
114
  end
125
115
 
126
116
  # if we haven't quit yet, we need to re-manifest
data/lib/bagit/bag.rb CHANGED
@@ -1,19 +1,21 @@
1
- require 'bagit/fetch'
2
- require 'bagit/file'
3
- require 'bagit/info'
4
- require 'bagit/manifest'
5
- require 'bagit/string'
6
- require 'bagit/valid'
1
+ # frozen_string_literal: true
2
+
3
+ require "bagit/fetch"
4
+ require "bagit/file"
5
+ require "bagit/info"
6
+ require "bagit/manifest"
7
+ require "bagit/string"
8
+ require "bagit/valid"
7
9
 
8
10
  module BagIt
9
11
  # Represents the state of a bag on a filesystem
10
12
  class Bag
11
13
  attr_reader :bag_dir
12
14
 
13
- include Validity # Validity functionality
14
- include Info # bagit & bag info functionality
15
- include Manifest # manifest related functionality
16
- include Fetch # fetch related functionality
15
+ include Validity # Validity functionality
16
+ include Info # bagit & bag info functionality
17
+ include Manifest # manifest related functionality
18
+ include Fetch # fetch related functionality
17
19
 
18
20
  # Make a new Bag based at path
19
21
  def initialize(path, info = {}, _create = false)
@@ -30,12 +32,12 @@ module BagIt
30
32
 
31
33
  # Return the path to the data directory
32
34
  def data_dir
33
- File.join @bag_dir, 'data'
35
+ File.join @bag_dir, "data"
34
36
  end
35
37
 
36
38
  # Return the paths to each bag file relative to bag_dir
37
39
  def bag_files
38
- Dir[File.join(data_dir, '**', '*')].select { |f| File.file? f }
40
+ Dir[File.join(data_dir, "**", "*")].select { |f| File.file? f }
39
41
  end
40
42
 
41
43
  # Return the paths to each tag file relative to bag_dir
@@ -43,7 +45,7 @@ module BagIt
43
45
  files = []
44
46
  if tagmanifest_files != []
45
47
  File.open(tagmanifest_files.first) do |f|
46
- f.each_line { |line| files << File.join(@bag_dir, line.split(' ')[1]) }
48
+ f.each_line { |line| files << File.join(@bag_dir, line.split(" ")[1]) }
47
49
  end
48
50
  end
49
51
  files
@@ -56,10 +58,10 @@ module BagIt
56
58
  FileUtils.mkdir_p File.dirname(path)
57
59
 
58
60
  f = if src_path.nil?
59
- File.open(path, 'w') { |io| yield io }
60
- else
61
- FileUtils.cp src_path, path
62
- end
61
+ File.open(path, "w") { |io| yield io }
62
+ else
63
+ FileUtils.cp src_path, path
64
+ end
63
65
  write_bag_info
64
66
  f
65
67
  end
@@ -86,7 +88,7 @@ module BagIt
86
88
 
87
89
  # Get all bag file paths relative to the data dir
88
90
  def paths
89
- bag_files.collect { |f| f.sub(data_dir + '/', '') }
91
+ bag_files.collect { |f| f.sub(data_dir + "/", "") }
90
92
  end
91
93
 
92
94
  # Get the Oxum for the payload files
@@ -96,7 +98,7 @@ module BagIt
96
98
  # TODO: filesystem quirks? Are we getting the stream size or the size on disk?
97
99
  bytes += File.size(f)
98
100
  end
99
- bytes.to_s + '.' + bag_files.count.to_s
101
+ bytes.to_s + "." + bag_files.count.to_s
100
102
  end
101
103
 
102
104
  # Remove all empty directory trees from the bag
data/lib/bagit/fetch.rb CHANGED
@@ -1,25 +1,27 @@
1
- require 'open-uri'
1
+ # frozen_string_literal: true
2
+
3
+ require "open-uri"
2
4
 
3
5
  module BagIt
4
6
  module Fetch
5
7
  def fetch_txt_file
6
- File.join @bag_dir, 'fetch.txt'
8
+ File.join @bag_dir, "fetch.txt"
7
9
  end
8
10
 
9
11
  def add_remote_file(url, path, size, sha1, md5)
10
- open(fetch_txt_file, 'a') { |io| io.puts "#{url} #{size || '-'} #{path}" }
11
- open(manifest_file('sha1'), 'a') { |io| io.puts "#{sha1} #{File.join 'data', path}" }
12
- open(manifest_file('md5'), 'a') { |io| io.puts "#{md5} #{File.join 'data', path}" }
12
+ File.open(fetch_txt_file, "a") { |io| io.puts "#{url} #{size || "-"} #{path}" }
13
+ File.open(manifest_file("sha1"), "a") { |io| io.puts "#{sha1} #{File.join "data", path}" }
14
+ File.open(manifest_file("md5"), "a") { |io| io.puts "#{md5} #{File.join "data", path}" }
13
15
  end
14
16
 
15
17
  # feth all remote files
16
18
  def fetch!
17
- open(fetch_txt_file) do |io|
19
+ File.open(fetch_txt_file) do |io|
18
20
  io.readlines.each do |line|
19
21
  (url, _length, path) = line.chomp.split(/\s+/, 3)
20
22
 
21
23
  add_file(path) do |file_io|
22
- file_io.write open(url)
24
+ file_io.write URI.open(url)
23
25
  end
24
26
  end
25
27
  end
@@ -29,7 +31,7 @@ module BagIt
29
31
  end
30
32
 
31
33
  def rename_old_fetch_txt(fetch_txt_file)
32
- Dir["#{fetch_txt_file}.?*"].sort.reverse.each do |f|
34
+ Dir["#{fetch_txt_file}.?*"].sort.reverse_each do |f|
33
35
  if f =~ /fetch.txt.(\d+)$/
34
36
  new_f = File.join File.dirname(f), "fetch.txt.#{Regexp.last_match(1).to_i + 1}"
35
37
  FileUtils.mv f, new_f
data/lib/bagit/file.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class File
2
4
  # Clean out all the empty dirs
3
5
  def self.clean(file_name)
data/lib/bagit/info.rb CHANGED
@@ -1,27 +1,29 @@
1
- require 'set'
1
+ # frozen_string_literal: true
2
+
3
+ require "set"
2
4
 
3
5
  module BagIt
4
6
  module Info
5
7
  @@bag_info_headers = {
6
- agent: 'Bag-Software-Agent',
7
- org: 'Source-Organization',
8
- org_addr: 'Organization-Address',
9
- contact_name: 'Contact-Name',
10
- contact_phone: 'Contact-Phone',
11
- contact_email: 'Contact-Email',
12
- ext_desc: 'External-Description',
13
- ext_id: 'External-Identifier',
14
- size: 'Bag-Size',
15
- group_id: 'Bag-Group-Identifier',
16
- group_count: 'Bag-Count',
17
- sender_id: 'Internal-Sender-Identifier',
18
- int_desc: 'Internal-Sender-Description',
19
- date: 'Bagging-Date',
20
- oxum: 'Payload-Oxum'
8
+ agent: "Bag-Software-Agent",
9
+ org: "Source-Organization",
10
+ org_addr: "Organization-Address",
11
+ contact_name: "Contact-Name",
12
+ contact_phone: "Contact-Phone",
13
+ contact_email: "Contact-Email",
14
+ ext_desc: "External-Description",
15
+ ext_id: "External-Identifier",
16
+ size: "Bag-Size",
17
+ group_id: "Bag-Group-Identifier",
18
+ group_count: "Bag-Count",
19
+ sender_id: "Internal-Sender-Identifier",
20
+ int_desc: "Internal-Sender-Description",
21
+ date: "Bagging-Date",
22
+ oxum: "Payload-Oxum"
21
23
  }
22
24
 
23
25
  def bag_info_txt_file
24
- File.join bag_dir, 'bag-info.txt'
26
+ File.join bag_dir, "bag-info.txt"
25
27
  end
26
28
 
27
29
  def bag_info
@@ -33,13 +35,13 @@ module BagIt
33
35
  def write_bag_info(hash = {})
34
36
  hash = bag_info.merge(hash)
35
37
  hash[@@bag_info_headers[:agent]] = "BagIt Ruby Gem (https://github.com/tipr/bagit)" if hash[@@bag_info_headers[:agent]].nil?
36
- hash[@@bag_info_headers[:date]] = Date.today.strftime('%Y-%m-%d') if hash[@@bag_info_headers[:date]].nil?
38
+ hash[@@bag_info_headers[:date]] = Date.today.strftime("%Y-%m-%d") if hash[@@bag_info_headers[:date]].nil?
37
39
  hash[@@bag_info_headers[:oxum]] = payload_oxum
38
40
  write_info_file bag_info_txt_file, hash
39
41
  end
40
42
 
41
43
  def bagit_txt_file
42
- File.join bag_dir, 'bagit.txt'
44
+ File.join bag_dir, "bagit.txt"
43
45
  end
44
46
 
45
47
  def bagit
@@ -51,44 +53,44 @@ module BagIt
51
53
  end
52
54
 
53
55
  def update_bag_date
54
- hash["Bagging-Date"] = Date.today.strftime('%Y-%m-%d')
56
+ hash["Bagging-Date"] = Date.today.strftime("%Y-%m-%d")
55
57
  write_bag_info(hash)
56
58
  end
57
59
 
58
60
  protected
59
61
 
60
- def read_info_file(file)
61
- File.open(file) do |io|
62
- entries = io.read.split(/\n(?=[^\s])/)
62
+ def read_info_file(file)
63
+ File.open(file) do |io|
64
+ entries = io.read.split(/\n(?=[^\s])/)
63
65
 
64
- entries.inject({}) do |hash, line|
65
- name, value = line.chomp.split(/\s*:\s*/, 2)
66
- hash.merge(name => value)
67
- end
66
+ entries.inject({}) do |hash, line|
67
+ name, value = line.chomp.split(/\s*:\s*/, 2)
68
+ hash.merge(name => value)
68
69
  end
69
70
  end
71
+ end
70
72
 
71
- def write_info_file(file, hash)
72
- dups = hash.keys.inject(Set.new) do |acc, key|
73
- a = hash.keys.grep(/#{key}/i)
74
- acc + (a.size > 1 ? a : [])
75
- end
76
-
77
- raise "Multiple labels (#{dups.to_a.join ', '}) in #{file}" unless dups.empty?
73
+ def write_info_file(file, hash)
74
+ dups = hash.keys.inject(Set.new) { |acc, key|
75
+ a = hash.keys.grep(/#{key}/i)
76
+ acc + (a.size > 1 ? a : [])
77
+ }
78
78
 
79
- File.open(file, 'w') do |io|
80
- hash.each do |name, value|
81
- simple_entry = "#{name}: #{value.gsub(/\s+/, ' ')}"
79
+ raise "Multiple labels (#{dups.to_a.join ", "}) in #{file}" unless dups.empty?
82
80
 
83
- entry = if simple_entry.length > 79
84
- simple_entry.wrap(77).indent(2)
85
- else
86
- simple_entry
87
- end
81
+ File.open(file, "w") do |io|
82
+ hash.each do |name, value|
83
+ simple_entry = "#{name}: #{value.gsub(/\s+/, " ")}"
88
84
 
89
- io.puts entry
85
+ entry = if simple_entry.length > 79
86
+ simple_entry.wrap(77).indent(2)
87
+ else
88
+ simple_entry
90
89
  end
90
+
91
+ io.puts entry
91
92
  end
92
93
  end
94
+ end
93
95
  end
94
96
  end
@@ -1,21 +1,23 @@
1
- require 'pathname'
2
- require 'digest/sha1'
3
- require 'digest/md5'
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+ require "digest/sha1"
5
+ require "digest/md5"
4
6
 
5
7
  module BagIt
6
8
  # Requires response to bag_dir, tag_files, bag_files
7
9
  module Manifest
8
10
  def encode_filename(s)
9
- s = s.gsub(/\r/, '%0D')
10
- s = s.gsub(/\n/, '%0A')
11
+ s = s.gsub(/\r/, "%0D")
12
+ s = s.gsub(/\n/, "%0A")
11
13
  s
12
14
  end
13
15
 
14
16
  # All tag files that are bag manifest files (manifest-[algorithm].txt)
15
17
  def manifest_files
16
- files = Dir[File.join(@bag_dir, '*')].select do |f|
18
+ files = Dir[File.join(@bag_dir, "*")].select { |f|
17
19
  File.file?(f) && File.basename(f) =~ /^manifest-.*.txt$/
18
- end
20
+ }
19
21
  files
20
22
  end
21
23
 
@@ -25,7 +27,7 @@ module BagIt
25
27
  end
26
28
 
27
29
  # Generate manifest files for all the bag files
28
- def manifest!(algo: 'default')
30
+ def manifest!(algo: "default")
29
31
  # nuke all the existing manifest files
30
32
  manifest_files.each { |f| FileUtils.rm f }
31
33
 
@@ -40,15 +42,15 @@ module BagIt
40
42
 
41
43
  def write_checksum(checksum_algo:, relative_path:, file:)
42
44
  case checksum_algo
43
- when 'sha1'
45
+ when "sha1"
44
46
  write_sha1(file, relative_path)
45
- when 'md5'
47
+ when "md5"
46
48
  write_md5(file, relative_path)
47
- when 'sha256'
49
+ when "sha256"
48
50
  write_sha256(file, relative_path)
49
- when 'sha512'
51
+ when "sha512"
50
52
  write_sha256(file, relative_path)
51
- when 'default'
53
+ when "default"
52
54
  write_sha1(file, relative_path)
53
55
  write_md5(file, relative_path)
54
56
  end
@@ -56,29 +58,29 @@ module BagIt
56
58
 
57
59
  def write_sha1(f, rel_path)
58
60
  sha1 = Digest::SHA1.file f
59
- File.open(manifest_file(:sha1), 'a') { |io| io.puts "#{sha1} #{rel_path}" }
61
+ File.open(manifest_file(:sha1), "a") { |io| io.puts "#{sha1} #{rel_path}" }
60
62
  end
61
63
 
62
64
  def write_md5(f, rel_path)
63
65
  md5 = Digest::MD5.file f
64
- File.open(manifest_file(:md5), 'a') { |io| io.puts "#{md5} #{rel_path}" }
66
+ File.open(manifest_file(:md5), "a") { |io| io.puts "#{md5} #{rel_path}" }
65
67
  end
66
68
 
67
69
  def write_sha256(f, rel_path)
68
70
  sha256 = Digest::SHA256.file f
69
- File.open(manifest_file(:sha256), 'a') { |io| io.puts "#{sha256} #{rel_path}" }
71
+ File.open(manifest_file(:sha256), "a") { |io| io.puts "#{sha256} #{rel_path}" }
70
72
  end
71
73
 
72
74
  def write_sha512(f, rel_path)
73
75
  sha512 = Digest::SHA512.file f
74
- File.open(manifest_file(:sha512), 'a') { |io| io.puts "#{sha512} #{rel_path}" }
76
+ File.open(manifest_file(:sha512), "a") { |io| io.puts "#{sha512} #{rel_path}" }
75
77
  end
76
78
 
77
79
  # All tag files that are bag manifest files (tagmanifest-[algorithm].txt)
78
80
  def tagmanifest_files
79
- files = Dir[File.join(@bag_dir, '*')].select do |f|
81
+ files = Dir[File.join(@bag_dir, "*")].select { |f|
80
82
  File.file?(f) && File.basename(f) =~ /^tagmanifest-.*.txt$/
81
- end
83
+ }
82
84
  files
83
85
  end
84
86
 
@@ -120,7 +122,7 @@ module BagIt
120
122
 
121
123
  # write file
122
124
  if src_path.nil?
123
- File.open(f, 'w') { |io| yield io }
125
+ File.open(f, "w") { |io| yield io }
124
126
  else
125
127
  FileUtils.cp src_path, f
126
128
  end
@@ -137,11 +139,11 @@ module BagIt
137
139
 
138
140
  # sha1
139
141
  sha1 = Digest::SHA1.hexdigest data
140
- File.open(tagmanifest_file(:sha1), 'a') { |io| io.puts "#{sha1} #{rel_path}" }
142
+ File.open(tagmanifest_file(:sha1), "a") { |io| io.puts "#{sha1} #{rel_path}" }
141
143
 
142
144
  # md5
143
145
  md5 = Digest::MD5.hexdigest data
144
- File.open(tagmanifest_file(:md5), 'a') { |io| io.puts "#{md5} #{rel_path}" }
146
+ File.open(tagmanifest_file(:md5), "a") { |io| io.puts "#{md5} #{rel_path}" }
145
147
  tag_files
146
148
  end
147
149
 
@@ -173,7 +175,7 @@ module BagIt
173
175
  Digest::MD5
174
176
  else
175
177
  :unknown
176
- end
178
+ end
177
179
 
178
180
  # check it, an unknown algorithm is always true
179
181
  if algo == :unknown
data/lib/bagit/string.rb CHANGED
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Some mixed in functionality for String
2
4
  class String
3
5
  # Wrap a string to lines of a specified width. All existing newlines
4
6
  # are not guaranteed to be preserved
5
7
  def wrap(width)
6
- s = gsub(/\s+/, ' ').strip
8
+ s = gsub(/\s+/, " ").strip
7
9
 
8
10
  if s.length > width
9
11
  s[0...width] + '\n' + s[width..-1].wrap(width)
@@ -14,7 +16,7 @@ class String
14
16
 
15
17
  # Indent each line of a string by n spaces
16
18
  def indent(n)
17
- indent = ' ' * n
19
+ indent = " " * n
18
20
  gsub '\n', "\n#{indent}"
19
21
  end
20
22