Fix Naming/BlockParameterName cop.
This commit is contained in:
parent
8d91d001fd
commit
846e704048
|
@ -38,19 +38,6 @@ Naming/AccessorMethodName:
|
||||||
- 'lib/zip/streamable_stream.rb'
|
- 'lib/zip/streamable_stream.rb'
|
||||||
- 'test/file_permissions_test.rb'
|
- 'test/file_permissions_test.rb'
|
||||||
|
|
||||||
# Offense count: 18
|
|
||||||
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
|
|
||||||
Naming/BlockParameterName:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/zip/file.rb'
|
|
||||||
- 'lib/zip/filesystem.rb'
|
|
||||||
- 'samples/zipfind.rb'
|
|
||||||
- 'test/central_directory_test.rb'
|
|
||||||
- 'test/file_extract_directory_test.rb'
|
|
||||||
- 'test/file_extract_test.rb'
|
|
||||||
- 'test/output_stream_test.rb'
|
|
||||||
- 'test/test_helper.rb'
|
|
||||||
|
|
||||||
# Offense count: 140
|
# Offense count: 140
|
||||||
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
|
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
|
||||||
# AllowedNames: io, id, to, by, on, in, at, ip, db, os
|
# AllowedNames: io, id, to, by, on, in, at, ip, db, os
|
||||||
|
|
|
@ -169,8 +169,8 @@ module Zip
|
||||||
# local entry headers (which contain the same information as the
|
# local entry headers (which contain the same information as the
|
||||||
# central directory).
|
# central directory).
|
||||||
def foreach(aZipFileName, &block)
|
def foreach(aZipFileName, &block)
|
||||||
::Zip::File.open(aZipFileName) do |zipFile|
|
::Zip::File.open(aZipFileName) do |zip_file|
|
||||||
zipFile.each(&block)
|
zip_file.each(&block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -265,8 +265,8 @@ module Zip
|
||||||
end
|
end
|
||||||
|
|
||||||
def chown(ownerInt, groupInt, *filenames)
|
def chown(ownerInt, groupInt, *filenames)
|
||||||
filenames.each do |fileName|
|
filenames.each do |filename|
|
||||||
e = get_entry(fileName)
|
e = get_entry(filename)
|
||||||
e.extra.create('IUnix') unless e.extra.member?('IUnix')
|
e.extra.create('IUnix') unless e.extra.member?('IUnix')
|
||||||
e.extra['IUnix'].uid = ownerInt
|
e.extra['IUnix'].uid = ownerInt
|
||||||
e.extra['IUnix'].gid = groupInt
|
e.extra['IUnix'].gid = groupInt
|
||||||
|
@ -275,8 +275,8 @@ module Zip
|
||||||
end
|
end
|
||||||
|
|
||||||
def chmod(modeInt, *filenames)
|
def chmod(modeInt, *filenames)
|
||||||
filenames.each do |fileName|
|
filenames.each do |filename|
|
||||||
e = get_entry(fileName)
|
e = get_entry(filename)
|
||||||
e.fstype = 3 # force convertion filesystem type to unix
|
e.fstype = 3 # force convertion filesystem type to unix
|
||||||
e.unix_perms = modeInt
|
e.unix_perms = modeInt
|
||||||
e.external_file_attributes = modeInt << 16
|
e.external_file_attributes = modeInt << 16
|
||||||
|
@ -314,8 +314,8 @@ module Zip
|
||||||
end
|
end
|
||||||
|
|
||||||
def utime(modifiedTime, *fileNames)
|
def utime(modifiedTime, *fileNames)
|
||||||
fileNames.each do |fileName|
|
fileNames.each do |filename|
|
||||||
get_entry(fileName).time = modifiedTime
|
get_entry(filename).time = modifiedTime
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -406,12 +406,12 @@ module Zip
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete(*args)
|
def delete(*args)
|
||||||
args.each do |fileName|
|
args.each do |filename|
|
||||||
if directory?(fileName)
|
if directory?(filename)
|
||||||
raise Errno::EISDIR, "Is a directory - \"#{fileName}\""
|
raise Errno::EISDIR, "Is a directory - \"#{filename}\""
|
||||||
end
|
end
|
||||||
|
|
||||||
@mappedZip.remove(fileName)
|
@mappedZip.remove(filename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -488,8 +488,8 @@ module Zip
|
||||||
path << '/' unless path.end_with?('/')
|
path << '/' unless path.end_with?('/')
|
||||||
path = Regexp.escape(path)
|
path = Regexp.escape(path)
|
||||||
subDirEntriesRegex = Regexp.new("^#{path}([^/]+)$")
|
subDirEntriesRegex = Regexp.new("^#{path}([^/]+)$")
|
||||||
@mappedZip.each do |fileName|
|
@mappedZip.each do |filename|
|
||||||
match = subDirEntriesRegex.match(fileName)
|
match = subDirEntriesRegex.match(filename)
|
||||||
yield(match[1]) unless match.nil?
|
yield(match[1]) unless match.nil?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,13 +10,13 @@ require 'find'
|
||||||
module Zip
|
module Zip
|
||||||
module ZipFind
|
module ZipFind
|
||||||
def self.find(path, zipFilePattern = /\.zip$/i)
|
def self.find(path, zipFilePattern = /\.zip$/i)
|
||||||
Find.find(path) do |fileName|
|
Find.find(path) do |filename|
|
||||||
yield(fileName)
|
yield(filename)
|
||||||
next unless zipFilePattern.match(fileName) && File.file?(fileName)
|
next unless zipFilePattern.match(filename) && File.file?(filename)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Zip::File.foreach(fileName) do |zipEntry|
|
Zip::File.foreach(filename) do |entry|
|
||||||
yield(fileName + File::SEPARATOR + zipEntry.to_s)
|
yield(filename + File::SEPARATOR + entry.to_s)
|
||||||
end
|
end
|
||||||
rescue Errno::EACCES => e
|
rescue Errno::EACCES => e
|
||||||
puts e
|
puts e
|
||||||
|
@ -25,8 +25,8 @@ module Zip
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_file(path, fileNamePattern, zipFilePattern = /\.zip$/i)
|
def self.find_file(path, fileNamePattern, zipFilePattern = /\.zip$/i)
|
||||||
find(path, zipFilePattern) do |fileName|
|
find(path, zipFilePattern) do |filename|
|
||||||
yield(fileName) if fileNamePattern.match(fileName)
|
yield(filename) if fileNamePattern.match(filename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -42,8 +42,8 @@ if $PROGRAM_NAME == __FILE__
|
||||||
check_args(args)
|
check_args(args)
|
||||||
Zip::ZipFind.find_file(args[PATH_ARG_INDEX],
|
Zip::ZipFind.find_file(args[PATH_ARG_INDEX],
|
||||||
args[FILENAME_PATTERN_ARG_INDEX],
|
args[FILENAME_PATTERN_ARG_INDEX],
|
||||||
args[ZIPFILE_PATTERN_ARG_INDEX]) do |fileName|
|
args[ZIPFILE_PATTERN_ARG_INDEX]) do |filename|
|
||||||
report_entry_found fileName
|
report_entry_found filename
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,21 +6,21 @@ class ZipCentralDirectoryTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_read_from_stream
|
def test_read_from_stream
|
||||||
::File.open(TestZipFile::TEST_ZIP2.zip_name, 'rb') do |zipFile|
|
::File.open(TestZipFile::TEST_ZIP2.zip_name, 'rb') do |zip_file|
|
||||||
cdir = ::Zip::CentralDirectory.read_from_stream(zipFile)
|
cdir = ::Zip::CentralDirectory.read_from_stream(zip_file)
|
||||||
|
|
||||||
assert_equal(TestZipFile::TEST_ZIP2.entry_names.size, cdir.size)
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names.size, cdir.size)
|
||||||
assert(cdir.entries.sort.compare_enumerables(TestZipFile::TEST_ZIP2.entry_names.sort) do |cdirEntry, testEntryName|
|
assert(cdir.entries.sort.compare_enumerables(TestZipFile::TEST_ZIP2.entry_names.sort) do |cdir_entry, test_entry_name|
|
||||||
cdirEntry.name == testEntryName
|
cdir_entry.name == test_entry_name
|
||||||
end)
|
end)
|
||||||
assert_equal(TestZipFile::TEST_ZIP2.comment, cdir.comment)
|
assert_equal(TestZipFile::TEST_ZIP2.comment, cdir.comment)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_read_from_invalid_stream
|
def test_read_from_invalid_stream
|
||||||
File.open('test/data/file2.txt', 'rb') do |zipFile|
|
File.open('test/data/file2.txt', 'rb') do |zip_file|
|
||||||
cdir = ::Zip::CentralDirectory.new
|
cdir = ::Zip::CentralDirectory.new
|
||||||
cdir.read_from_stream(zipFile)
|
cdir.read_from_stream(zip_file)
|
||||||
end
|
end
|
||||||
raise 'ZipError expected!'
|
raise 'ZipError expected!'
|
||||||
rescue ::Zip::Error
|
rescue ::Zip::Error
|
||||||
|
|
|
@ -42,9 +42,9 @@ class ZipFileExtractDirectoryTest < MiniTest::Test
|
||||||
def test_extract_directory_exists_as_file_overwrite
|
def test_extract_directory_exists_as_file_overwrite
|
||||||
File.open(TEST_OUT_NAME, 'w') { |f| f.puts 'something' }
|
File.open(TEST_OUT_NAME, 'w') { |f| f.puts 'something' }
|
||||||
gotCalled = false
|
gotCalled = false
|
||||||
extract_test_dir do |entry, destPath|
|
extract_test_dir do |entry, dest_path|
|
||||||
gotCalled = true
|
gotCalled = true
|
||||||
assert_equal(TEST_OUT_NAME, destPath)
|
assert_equal(TEST_OUT_NAME, dest_path)
|
||||||
assert(entry.directory?)
|
assert(entry.directory?)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
|
@ -53,9 +53,9 @@ class ZipFileExtractTest < MiniTest::Test
|
||||||
|
|
||||||
gotCalledCorrectly = false
|
gotCalledCorrectly = false
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||||
zf.extract(zf.entries.first, EXTRACTED_FILENAME) do |entry, extractLoc|
|
zf.extract(zf.entries.first, EXTRACTED_FILENAME) do |entry, extract_loc|
|
||||||
gotCalledCorrectly = zf.entries.first == entry &&
|
gotCalledCorrectly = zf.entries.first == entry &&
|
||||||
extractLoc == EXTRACTED_FILENAME
|
extract_loc == EXTRACTED_FILENAME
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -121,9 +121,9 @@ class ZipOutputStreamTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_test_zip(zos)
|
def write_test_zip(zos)
|
||||||
TEST_ZIP.entry_names.each do |entryName|
|
TEST_ZIP.entry_names.each do |entry_name|
|
||||||
zos.put_next_entry(entryName)
|
zos.put_next_entry(entry_name)
|
||||||
File.open(entryName, 'rb') { |f| zos.write(f.read) }
|
File.open(entry_name, 'rb') { |f| zos.write(f.read) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -119,8 +119,8 @@ module AssertEntry
|
||||||
|
|
||||||
def assert_stream_contents(zis, testZipFile)
|
def assert_stream_contents(zis, testZipFile)
|
||||||
assert(!zis.nil?)
|
assert(!zis.nil?)
|
||||||
testZipFile.entry_names.each do |entryName|
|
testZipFile.entry_names.each do |entry_name|
|
||||||
assert_next_entry(entryName, zis)
|
assert_next_entry(entry_name, zis)
|
||||||
end
|
end
|
||||||
assert_nil(zis.get_next_entry)
|
assert_nil(zis.get_next_entry)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue