Skip to content

Commit 90e6ae1

Browse files
committed
Fix rubyzip 3.x extract API and resolve all rubocop offenses
Update DataSource to use rubyzip 3.x keyword argument API for extract. Move dev dependencies from gemspec to Gemfile, use add_dependency, sort alphabetically. Fix version.rake: replace block constants with methods, replace eval with const_get, use File.write, rename predicate method, and simplify unreachable loop.
1 parent 581d774 commit 90e6ae1

4 files changed

Lines changed: 44 additions & 39 deletions

File tree

Gemfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,13 @@ source 'https://rubygems.org'
44
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
55

66
gemspec
7+
8+
group :development do
9+
gem 'bundler'
10+
gem 'pry-nav', '~> 0.2'
11+
gem 'rake', '~> 13.0'
12+
gem 'rspec', '~> 3.7'
13+
gem 'rubocop'
14+
gem 'ruby-prof', '~> 0.17'
15+
gem 'simplecov', '~> 0.16'
16+
end

free_zipcode_data.gemspec

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,11 @@ Gem::Specification.new do |spec|
2323
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
2424
spec.require_paths = ['lib']
2525

26-
spec.add_development_dependency 'bundler'
27-
spec.add_development_dependency 'pry-nav', '~> 0.2'
28-
spec.add_development_dependency 'rake', '~> 13.0'
29-
spec.add_development_dependency 'rspec', '~> 3.7'
30-
spec.add_development_dependency 'rubocop'
31-
spec.add_development_dependency 'ruby-prof', '~> 0.17'
32-
spec.add_development_dependency 'simplecov', '~> 0.16'
33-
34-
spec.add_runtime_dependency 'csv'
35-
spec.add_runtime_dependency 'colored', '~> 1.2'
36-
spec.add_runtime_dependency 'kiba', '~> 4.0'
37-
spec.add_runtime_dependency 'optimist', '~> 3.0'
38-
spec.add_runtime_dependency 'ruby-progressbar', '~> 1.9'
39-
spec.add_runtime_dependency 'rubyzip', '>= 1.2.2'
40-
spec.add_runtime_dependency 'sqlite3', '~> 1.3'
26+
spec.add_dependency 'colored', '~> 1.2'
27+
spec.add_dependency 'csv'
28+
spec.add_dependency 'kiba', '~> 4.0'
29+
spec.add_dependency 'optimist', '~> 3.0'
30+
spec.add_dependency 'ruby-progressbar', '~> 1.9'
31+
spec.add_dependency 'rubyzip', '>= 1.2.2'
32+
spec.add_dependency 'sqlite3', '~> 1.3'
4133
end

lib/free_zipcode_data/data_source.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ def unzipped_datafile
5656
if options[:clobber]
5757
Zip.on_exists_proc = true
5858
Logger.instance.verbose("Extracting: #{zipfile}...")
59-
entry.extract(country_file)
59+
entry.extract(destination_directory: options.work_dir)
6060
end
6161
else
6262
Logger.instance.verbose("Extracting: #{zipfile}...")
63-
entry.extract(country_file)
63+
entry.extract(destination_directory: options.work_dir)
6464
end
6565
break
6666
end

lib/tasks/version.rake

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ require 'fileutils'
66

77
# rubocop:disable Metrics/BlockLength
88
namespace :version do
9-
PROJECT_ROOT = File.expand_path(FileUtils.pwd).freeze
10-
PROJECT_NAME = ENV['PROJECT_NAME'] || File.basename(PROJECT_ROOT)
119

1210
desc 'Write changes to the CHANGELOG'
1311
task :changes do
@@ -23,7 +21,7 @@ namespace :version do
2321

2422
desc 'Increment the patch version and write changes to the changelog'
2523
task :bump_patch do
26-
exit unless check_branch_and_warn
24+
exit unless check_branch_and_warn?
2725
major, minor, patch = read_version
2826
patch = patch.to_i + 1
2927
write_version_file([major, minor, patch])
@@ -36,7 +34,7 @@ namespace :version do
3634

3735
desc 'Increment the minor version and write changes to the changelog'
3836
task :bump_minor do
39-
exit unless check_branch_and_warn
37+
exit unless check_branch_and_warn?
4038
major, minor, _patch = read_version
4139
minor = minor.to_i + 1
4240
patch = 0
@@ -47,7 +45,7 @@ namespace :version do
4745

4846
desc 'Increment the major version and write changes to the changelog'
4947
task :bump_major do
50-
exit unless check_branch_and_warn
48+
exit unless check_branch_and_warn?
5149
major, _minor, _patch = read_version
5250
major = major.to_i + 1
5351
minor = 0
@@ -59,27 +57,35 @@ namespace :version do
5957

6058
private
6159

60+
def project_root
61+
@project_root ||= File.expand_path(FileUtils.pwd).freeze
62+
end
63+
64+
def project_name
65+
@project_name ||= ENV['PROJECT_NAME'] || File.basename(project_root)
66+
end
67+
6268
def version_file_path
63-
split = PROJECT_NAME.split('-')
64-
"#{PROJECT_ROOT}/lib/#{split.join('/')}/version.rb"
69+
split = project_name.split('-')
70+
"#{project_root}/lib/#{split.join('/')}/version.rb"
6571
end
6672

6773
def module_name
68-
case PROJECT_NAME
74+
case project_name
6975
when /-/
70-
PROJECT_NAME.split('-').map(&:capitalize).join('::')
76+
project_name.split('-').map(&:capitalize).join('::')
7177
when /_/
72-
PROJECT_NAME.split('_').map(&:capitalize).join
78+
project_name.split('_').map(&:capitalize).join
7379
else
74-
PROJECT_NAME.capitalize
80+
project_name.capitalize
7581
end
7682
end
7783

7884
def read_version
7985
silence_warnings do
8086
load version_file_path
8187
end
82-
text = eval("#{module_name}::VERSION")
88+
text = module_name.split('::').inject(Object) { |mod, name| mod.const_get(name) }::VERSION
8389
text.split('.')
8490
end
8591

@@ -104,15 +110,13 @@ namespace :version do
104110
regex = /^\*\*Version: [0-9.]+\*\*$/i
105111
return nil unless readme =~ regex
106112

107-
File.open('README.md', 'w') do |f|
108-
f.write(readme.gsub(regex, "**Version: #{version_string}**"))
109-
end
113+
File.write('README.md', readme.gsub(regex, "**Version: #{version_string}**"))
110114
end
111115

112116
def changelog
113117
return @changelog_path if @changelog_path
114118

115-
@changelog_path = File.join(PROJECT_ROOT, 'CHANGELOG')
119+
@changelog_path = File.join(project_root, 'CHANGELOG')
116120
FileUtils.touch(@changelog_path)
117121
@changelog_path
118122
end
@@ -159,16 +163,15 @@ namespace :version do
159163
STRING
160164
end
161165

162-
def check_branch_and_warn
166+
def check_branch_and_warn?
163167
return true unless current_branch == 'master'
164168

165169
puts(branch_warning_message)
166-
while (line = $stdin.gets.chomp)
167-
return true if line =~ /[yY]/
170+
line = $stdin.gets.chomp
171+
return true if line =~ /[yY]/
168172

169-
puts 'Aborting version bump.'
170-
return false
171-
end
173+
puts 'Aborting version bump.'
174+
false
172175
end
173176

174177
def launch_editor(file)

0 commit comments

Comments
 (0)