Skip to content

Commit bbb2b65

Browse files
committed
Switch to standardrb for linting
1 parent 015fe29 commit bbb2b65

19 files changed

+247
-276
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ vendor
88
Gemfile.lock
99
.bundle
1010
.project
11-
.idea
11+
.idea
12+
coverage

.rubocop.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

3-
source 'https://rubygems.org'
3+
source "https://rubygems.org"
44

55
gemspec

Rakefile

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
# frozen_string_literal: true
22

3-
require 'rubygems'
4-
require 'bundler/setup'
3+
require "rubygems"
4+
require "bundler/setup"
55
Bundler.setup(:default, :development, :test)
66

7-
require 'rake'
8-
require 'rdoc/task'
9-
require 'rspec/core/rake_task'
10-
require 'rubocop/rake_task'
7+
require "rake"
8+
require "rdoc/task"
9+
require "rspec/core/rake_task"
10+
require "standard/rake"
1111

1212
Bundler::GemHelper.install_tasks
1313

14-
desc 'Run rubocop'
15-
task rubocop: :environment do
16-
RuboCop::RakeTask.new
17-
end
18-
1914
RSpec::Core::RakeTask.new do |t|
20-
t.pattern = 'spec/**/*_spec.rb'
15+
t.pattern = "spec/**/*_spec.rb"
2116
t.rspec_opts = %w[--format documentation --color]
2217
end
2318

24-
task default: [:rubocop, :spec]
19+
task default: [:standard, :spec]

bagit.gemspec

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
1-
# coding: utf-8
21
# frozen_string_literal: true
32

4-
lib = File.expand_path('../lib', __FILE__)
3+
lib = File.expand_path("../lib", __FILE__)
54
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6-
require 'bagit/version'
5+
require "bagit/version"
76

87
Gem::Specification.new do |spec|
9-
spec.name = "bagit"
10-
spec.version = BagIt::VERSION
11-
spec.summary = "BagIt package generation and validation"
8+
spec.name = "bagit"
9+
spec.version = BagIt::VERSION
10+
spec.summary = "BagIt package generation and validation"
1211
spec.description = "Ruby Library and Command Line tools for bagit"
13-
spec.email = "[email protected]"
14-
spec.homepage = 'http://github.com/tipr/bagit'
15-
spec.authors = ["Tom Johnson, Francesco Lazzarino, Jamie Little"]
16-
spec.license = "MIT"
12+
spec.email = "[email protected]"
13+
spec.homepage = "http://github.com/tipr/bagit"
14+
spec.authors = ["Tom Johnson, Francesco Lazzarino, Jamie Little"]
15+
spec.license = "MIT"
1716

18-
spec.required_ruby_version = '~> 2.0'
17+
spec.required_ruby_version = "~> 2.0"
1918

20-
spec.add_dependency 'validatable', '~> 1.6'
21-
spec.add_dependency 'docopt', '~> 0.5.0'
19+
spec.add_dependency "validatable", "~> 1.6"
20+
spec.add_dependency "docopt", "~> 0.5.0"
2221

23-
spec.add_development_dependency 'bixby'
24-
spec.add_development_dependency 'bundler'
25-
spec.add_development_dependency 'coveralls'
26-
spec.add_development_dependency 'pry'
27-
spec.add_development_dependency 'pry-byebug'
28-
spec.add_development_dependency 'rake', '>= 12.3.3'
29-
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"
3029

31-
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
32-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
33-
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)/})
3433
spec.require_paths = ["lib"]
3534
end

lib/bagit.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
# Functionality conforms to the BagIt Spec v0.96:
66
# http://www.cdlib.org/inside/diglib/bagit/bagitspec.html
77

8-
require 'bagit/bag'
9-
require 'bagit/version'
10-
require 'fileutils'
11-
require 'date'
12-
require 'logger'
8+
require "bagit/bag"
9+
require "bagit/version"
10+
require "fileutils"
11+
require "date"
12+
require "logger"
1313
module BagIt
1414
# The version of the BagIt specification the code is conforming to.
15-
SPEC_VERSION = '0.97'
15+
SPEC_VERSION = "0.97"
1616
end

lib/bagit/bag.rb

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# frozen_string_literal: true
22

3-
require 'bagit/fetch'
4-
require 'bagit/file'
5-
require 'bagit/info'
6-
require 'bagit/manifest'
7-
require 'bagit/string'
8-
require 'bagit/valid'
3+
require "bagit/fetch"
4+
require "bagit/file"
5+
require "bagit/info"
6+
require "bagit/manifest"
7+
require "bagit/string"
8+
require "bagit/valid"
99

1010
module BagIt
1111
# Represents the state of a bag on a filesystem
1212
class Bag
1313
attr_reader :bag_dir
1414

15-
include Validity # Validity functionality
16-
include Info # bagit & bag info functionality
17-
include Manifest # manifest related functionality
18-
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
1919

2020
# Make a new Bag based at path
2121
def initialize(path, info = {}, _create = false)
@@ -32,20 +32,20 @@ def initialize(path, info = {}, _create = false)
3232

3333
# Return the path to the data directory
3434
def data_dir
35-
File.join @bag_dir, 'data'
35+
File.join @bag_dir, "data"
3636
end
3737

3838
# Return the paths to each bag file relative to bag_dir
3939
def bag_files
40-
Dir[File.join(data_dir, '**', '*')].select { |f| File.file? f }
40+
Dir[File.join(data_dir, "**", "*")].select { |f| File.file? f }
4141
end
4242

4343
# Return the paths to each tag file relative to bag_dir
4444
def tag_files
4545
files = []
4646
if tagmanifest_files != []
4747
File.open(tagmanifest_files.first) do |f|
48-
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]) }
4949
end
5050
end
5151
files
@@ -58,10 +58,10 @@ def add_file(relative_path, src_path = nil)
5858
FileUtils.mkdir_p File.dirname(path)
5959

6060
f = if src_path.nil?
61-
File.open(path, 'w') { |io| yield io }
62-
else
63-
FileUtils.cp src_path, path
64-
end
61+
File.open(path, "w") { |io| yield io }
62+
else
63+
FileUtils.cp src_path, path
64+
end
6565
write_bag_info
6666
f
6767
end
@@ -88,7 +88,7 @@ def empty?
8888

8989
# Get all bag file paths relative to the data dir
9090
def paths
91-
bag_files.collect { |f| f.sub(data_dir + '/', '') }
91+
bag_files.collect { |f| f.sub(data_dir + "/", "") }
9292
end
9393

9494
# Get the Oxum for the payload files
@@ -98,7 +98,7 @@ def payload_oxum
9898
# TODO: filesystem quirks? Are we getting the stream size or the size on disk?
9999
bytes += File.size(f)
100100
end
101-
bytes.to_s + '.' + bag_files.count.to_s
101+
bytes.to_s + "." + bag_files.count.to_s
102102
end
103103

104104
# Remove all empty directory trees from the bag

lib/bagit/fetch.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
# frozen_string_literal: true
22

3-
require 'open-uri'
3+
require "open-uri"
44

55
module BagIt
66
module Fetch
77
def fetch_txt_file
8-
File.join @bag_dir, 'fetch.txt'
8+
File.join @bag_dir, "fetch.txt"
99
end
1010

1111
def add_remote_file(url, path, size, sha1, md5)
12-
open(fetch_txt_file, 'a') { |io| io.puts "#{url} #{size || '-'} #{path}" }
13-
open(manifest_file('sha1'), 'a') { |io| io.puts "#{sha1} #{File.join 'data', path}" }
14-
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}" }
1515
end
1616

1717
# feth all remote files
1818
def fetch!
19-
open(fetch_txt_file) do |io|
19+
File.open(fetch_txt_file) do |io|
2020
io.readlines.each do |line|
2121
(url, _length, path) = line.chomp.split(/\s+/, 3)
2222

2323
add_file(path) do |file_io|
24-
file_io.write open(url)
24+
file_io.write URI.open(url)
2525
end
2626
end
2727
end

lib/bagit/info.rb

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
# frozen_string_literal: true
22

3-
require 'set'
3+
require "set"
44

55
module BagIt
66
module Info
77
@@bag_info_headers = {
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'
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"
2323
}
2424

2525
def bag_info_txt_file
26-
File.join bag_dir, 'bag-info.txt'
26+
File.join bag_dir, "bag-info.txt"
2727
end
2828

2929
def bag_info
@@ -35,13 +35,13 @@ def bag_info
3535
def write_bag_info(hash = {})
3636
hash = bag_info.merge(hash)
3737
hash[@@bag_info_headers[:agent]] = "BagIt Ruby Gem (https://github.com/tipr/bagit)" if hash[@@bag_info_headers[:agent]].nil?
38-
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?
3939
hash[@@bag_info_headers[:oxum]] = payload_oxum
4040
write_info_file bag_info_txt_file, hash
4141
end
4242

4343
def bagit_txt_file
44-
File.join bag_dir, 'bagit.txt'
44+
File.join bag_dir, "bagit.txt"
4545
end
4646

4747
def bagit
@@ -53,7 +53,7 @@ def write_bagit(hash)
5353
end
5454

5555
def update_bag_date
56-
hash["Bagging-Date"] = Date.today.strftime('%Y-%m-%d')
56+
hash["Bagging-Date"] = Date.today.strftime("%Y-%m-%d")
5757
write_bag_info(hash)
5858
end
5959

@@ -71,22 +71,22 @@ def read_info_file(file)
7171
end
7272

7373
def write_info_file(file, hash)
74-
dups = hash.keys.inject(Set.new) do |acc, key|
74+
dups = hash.keys.inject(Set.new) { |acc, key|
7575
a = hash.keys.grep(/#{key}/i)
7676
acc + (a.size > 1 ? a : [])
77-
end
77+
}
7878

79-
raise "Multiple labels (#{dups.to_a.join ', '}) in #{file}" unless dups.empty?
79+
raise "Multiple labels (#{dups.to_a.join ", "}) in #{file}" unless dups.empty?
8080

81-
File.open(file, 'w') do |io|
81+
File.open(file, "w") do |io|
8282
hash.each do |name, value|
83-
simple_entry = "#{name}: #{value.gsub(/\s+/, ' ')}"
83+
simple_entry = "#{name}: #{value.gsub(/\s+/, " ")}"
8484

8585
entry = if simple_entry.length > 79
86-
simple_entry.wrap(77).indent(2)
87-
else
88-
simple_entry
89-
end
86+
simple_entry.wrap(77).indent(2)
87+
else
88+
simple_entry
89+
end
9090

9191
io.puts entry
9292
end

0 commit comments

Comments
 (0)