Skip to content

Commit

Permalink
Fix Naming/MethodParameterName cop in the library code.
Browse files Browse the repository at this point in the history
  • Loading branch information
hainesr committed Feb 19, 2020
1 parent 3f28c8e commit b3a5ad9
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 228 deletions.
7 changes: 0 additions & 7 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ Naming/AccessorMethodName:
- 'lib/zip/streamable_stream.rb'
- 'test/file_permissions_test.rb'

# Offense count: 140
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: io, id, to, by, on, in, at, ip, db, os
Naming/MethodParameterName:
Exclude:
- 'lib/**/*.rb'

# Offense count: 721
# Configuration parameters: EnforcedStyle.
# SupportedStyles: snake_case, camelCase
Expand Down
18 changes: 9 additions & 9 deletions lib/zip/crypto/traditional_encryption.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def reset_keys!
end
end

def update_keys(n)
@key0 = ~Zlib.crc32(n, ~@key0)
def update_keys(num)
@key0 = ~Zlib.crc32(num, ~@key0)
@key1 = ((@key1 + (@key0 & 0xff)) * 134_775_813 + 1) & 0xffffffff
@key2 = ~Zlib.crc32((@key1 >> 24).chr, ~@key2)
end
Expand Down Expand Up @@ -63,10 +63,10 @@ def reset!

private

def encode(n)
def encode(num)
t = decrypt_byte
update_keys(n.chr)
t ^ n
update_keys(num.chr)
t ^ num
end
end

Expand All @@ -86,10 +86,10 @@ def reset!(header)

private

def decode(n)
n ^= decrypt_byte
update_keys(n.chr)
n
def decode(num)
num ^= decrypt_byte
update_keys(num.chr)
num
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions lib/zip/dos_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def self.from_time(time)
local(time.year, time.month, time.day, time.hour, time.min, time.sec)
end

def self.parse_binary_dos_format(binaryDosDate, binaryDosTime)
second = 2 * (0b11111 & binaryDosTime)
minute = (0b11111100000 & binaryDosTime) >> 5
hour = (0b1111100000000000 & binaryDosTime) >> 11
day = (0b11111 & binaryDosDate)
month = (0b111100000 & binaryDosDate) >> 5
year = ((0b1111111000000000 & binaryDosDate) >> 9) + 1980
def self.parse_binary_dos_format(bin_dos_date, bin_dos_time)
second = 2 * (0b11111 & bin_dos_time)
minute = (0b11111100000 & bin_dos_time) >> 5
hour = (0b1111100000000000 & bin_dos_time) >> 11
day = (0b11111 & bin_dos_date)
month = (0b111100000 & bin_dos_date) >> 5
year = ((0b1111111000000000 & bin_dos_date) >> 9) + 1980
begin
local(year, month, day, hour, minute, second)
end
Expand Down
14 changes: 7 additions & 7 deletions lib/zip/extra_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ def initialize(binstr = nil)
merge(binstr) if binstr
end

def extra_field_type_exist(binstr, id, len, i)
def extra_field_type_exist(binstr, id, len, index)
field_name = ID_MAP[id].name
if member?(field_name)
self[field_name].merge(binstr[i, len + 4])
self[field_name].merge(binstr[index, len + 4])
else
field_obj = ID_MAP[id].new(binstr[i, len + 4])
field_obj = ID_MAP[id].new(binstr[index, len + 4])
self[field_name] = field_obj
end
end

def extra_field_type_unknown(binstr, len, i)
def extra_field_type_unknown(binstr, len, index)
create_unknown_item unless self['Unknown']
if !len || len + 4 > binstr[i..-1].bytesize
self['Unknown'] << binstr[i..-1]
if !len || len + 4 > binstr[index..-1].bytesize
self['Unknown'] << binstr[index..-1]
return
end
self['Unknown'] << binstr[i, len + 4]
self['Unknown'] << binstr[index, len + 4]
end

def create_unknown_item
Expand Down
54 changes: 27 additions & 27 deletions lib/zip/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ def open_buffer(io, options = {})
# whereas ZipInputStream jumps through the entire archive accessing the
# local entry headers (which contain the same information as the
# central directory).
def foreach(aZipFileName, &block)
::Zip::File.open(aZipFileName) do |zip_file|
def foreach(zip_file_name, &block)
::Zip::File.open(zip_file_name) do |zip_file|
zip_file.each(&block)
end
end
Expand Down Expand Up @@ -255,8 +255,8 @@ def split(zip_file_name, segment_size = MAX_SEGMENT_SIZE, delete_zip_file = true
# Returns an input stream to the specified entry. If a block is passed
# the stream object is passed to the block and the stream is automatically
# closed afterwards just as with ruby's builtin File.open method.
def get_input_stream(entry, &aProc)
get_entry(entry).get_input_stream(&aProc)
def get_input_stream(entry, &proc)
get_entry(entry).get_input_stream(&proc)
end

# Returns an output stream to the specified entry. If entry is not an instance
Expand All @@ -267,7 +267,7 @@ def get_input_stream(entry, &aProc)
def get_output_stream(entry, permission_int = nil, comment = nil,
extra = nil, compressed_size = nil, crc = nil,
compression_method = nil, size = nil, time = nil,
&aProc)
&proc)

new_entry =
if entry.kind_of?(Entry)
Expand All @@ -282,7 +282,7 @@ def get_output_stream(entry, permission_int = nil, comment = nil,
new_entry.unix_perms = permission_int
zip_streamable_entry = StreamableStream.new(new_entry)
@entry_set << zip_streamable_entry
zip_streamable_entry.get_output_stream(&aProc)
zip_streamable_entry.get_output_stream(&proc)
end

# Returns the name of the zip archive
Expand Down Expand Up @@ -326,12 +326,12 @@ def rename(entry, new_name, &continue_on_exists_proc)
@entry_set << foundEntry
end

# Replaces the specified entry with the contents of srcPath (from
# Replaces the specified entry with the contents of src_path (from
# the file system).
def replace(entry, srcPath)
check_file(srcPath)
def replace(entry, src_path)
check_file(src_path)
remove(entry)
add(entry, srcPath)
add(entry, src_path)
end

# Extracts entry to file dest_path.
Expand Down Expand Up @@ -409,37 +409,37 @@ def get_entry(entry)
end

# Creates a directory
def mkdir(entryName, permissionInt = 0o755)
raise Errno::EEXIST, "File exists - #{entryName}" if find_entry(entryName)
def mkdir(entry_name, permission = 0o755)
raise Errno::EEXIST, "File exists - #{entry_name}" if find_entry(entry_name)

entryName = entryName.dup.to_s
entryName << '/' unless entryName.end_with?('/')
@entry_set << ::Zip::StreamableDirectory.new(@name, entryName, nil, permissionInt)
entry_name = entry_name.dup.to_s
entry_name << '/' unless entry_name.end_with?('/')
@entry_set << ::Zip::StreamableDirectory.new(@name, entry_name, nil, permission)
end

private

def directory?(newEntry, srcPath)
srcPathIsDirectory = ::File.directory?(srcPath)
if newEntry.directory? && !srcPathIsDirectory
def directory?(new_entry, src_path)
srcPathIsDirectory = ::File.directory?(src_path)
if new_entry.directory? && !srcPathIsDirectory
raise ArgumentError,
"entry name '#{newEntry}' indicates directory entry, but " \
"'#{srcPath}' is not a directory"
elsif !newEntry.directory? && srcPathIsDirectory
newEntry.name += '/'
"entry name '#{new_entry}' indicates directory entry, but " \
"'#{src_path}' is not a directory"
elsif !new_entry.directory? && srcPathIsDirectory
new_entry.name += '/'
end
newEntry.directory? && srcPathIsDirectory
new_entry.directory? && srcPathIsDirectory
end

def check_entry_exists(entryName, continue_on_exists_proc, procedureName)
def check_entry_exists(entry_name, continue_on_exists_proc, proc_name)
continue_on_exists_proc ||= proc { Zip.continue_on_exists_proc }
return unless @entry_set.include?(entryName)
return unless @entry_set.include?(entry_name)

if continue_on_exists_proc.call
remove get_entry(entryName)
remove get_entry(entry_name)
else
raise ::Zip::EntryExistsError,
procedureName + " failed. Entry #{entryName} already exists"
proc_name + " failed. Entry #{entry_name} already exists"
end
end

Expand Down
Loading

0 comments on commit b3a5ad9

Please sign in to comment.