Skip to content

Commit

Permalink
Remove unused block variables in Rakefile.
Browse files Browse the repository at this point in the history
Make private singleton methods private, don't use loop for single result.

Remove useless private marker, other minor rubocop fixes.

Fix or remove useless access modifiers.

Remove useless intermediate object.
  • Loading branch information
djberg96 committed Jan 2, 2021
1 parent c00f568 commit 790ca59
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CLEAN.include('**/*.gem', '**/*.rbc', '**/*.rbx', '**/*.lock')

namespace :gem do
desc "Build the sys-filesystem gem"
task :create => [:clean] do |t|
task :create => [:clean] do
require 'rubygems/package'
spec = eval(IO.read('sys-filesystem.gemspec'))
spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
Expand All @@ -21,7 +21,7 @@ namespace :gem do
end

desc "Run the example program"
task :example do |t|
task :example do
sh "ruby -Ilib -Ilib/unix -Ilib/windows examples/example_stat.rb"
end

Expand Down
5 changes: 3 additions & 2 deletions examples/example_mount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
require 'optparse'

options = {:mount_options => []}

OptionParser.new do |opts|
opts.banner = "Usage: #$0 [-o options] [-t external_type] special node"

opts.on("-o=OPTIONS", "Set one or many mount options (comma delimited)") do |opts|
options[:mount_options] += opts.split(',')
opts.on("-o=OPTIONS", "Set one or many mount options (comma delimited)") do |cli_opts|
options[:mount_options] += cli_opts.split(',')
end

opts.on("-r", "Set readonly flag") do
Expand Down
10 changes: 5 additions & 5 deletions lib/sys/unix/sys/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class Filesystem
include Sys::Filesystem::Structs
extend Sys::Filesystem::Functions

private

# Readable versions of constant names
OPT_NAMES = {
MNT_RDONLY => 'read-only',
Expand All @@ -37,6 +35,8 @@ class Filesystem
MNT_NOATIME => 'noatime'
}.freeze

private_constant :OPT_NAMES

# File used to read mount informtion from.
if File.exist?('/etc/mtab')
MOUNT_FILE = '/etc/mtab'
Expand All @@ -48,7 +48,7 @@ class Filesystem
MOUNT_FILE = 'getmntinfo'
end

public
private_constant :MOUNT_FILE

# The error raised if any of the Filesystem methods fail.
class Error < StandardError; end
Expand Down Expand Up @@ -278,7 +278,7 @@ def self.mounts

ptr = buf.get_pointer(0)

num.times{ |i|
num.times do
mnt = Statfs.new(ptr)
obj = Sys::Filesystem::Mount.new
obj.name = mnt[:f_mntfromname].to_s
Expand Down Expand Up @@ -308,7 +308,7 @@ def self.mounts
end

ptr += Statfs.size
}
end
else
begin
if respond_to?(:setmntent, true)
Expand Down
2 changes: 0 additions & 2 deletions lib/sys/unix/sys/filesystem/constants.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module Sys
class Filesystem
module Constants
private

MNT_RDONLY = 0x00000001 # read only filesystem
MNT_SYNCHRONOUS = 0x00000002 # file system written synchronously
MNT_NOEXEC = 0x00000004 # can't exec from filesystem
Expand Down
17 changes: 8 additions & 9 deletions lib/sys/windows/sys/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,6 @@ def self.umount(mount_point)
self
end

private

# This method is used to get the boot time of the system, which is used
# for the mount_time attribute within the File.mounts method.
#
Expand All @@ -411,14 +409,14 @@ def self.get_boot_time
raise Error, e
else
query = 'select LastBootupTime from Win32_OperatingSystem'
results = wmi.ExecQuery(query)
results.each{ |ole|
time_array = Time.parse(ole.LastBootupTime.split('.').first)
return Time.mktime(*time_array)
}
ole = wmi.ExecQuery(query).ItemIndex(0)
time_array = Time.parse(ole.LastBootupTime.split('.').first)
Time.mktime(*time_array)
end
end

private_class_method :get_boot_time

# Private method that converts filesystem flags into a comma separated
# list of strings. The presentation is meant as a rough analogue to the
# way options are presented for Unix filesystems.
Expand All @@ -439,8 +437,9 @@ def self.get_options(flags)
str << " compressed" if VOLUME_IS_COMPRESSED & flags > 0

str.tr!(' ', ',')
str = str[1..-1] # Ignore the first comma
str
str[1..-1] # Ignore the first comma
end

private_class_method :get_options
end
end

0 comments on commit 790ca59

Please sign in to comment.