From 5687622be735a5d112508811a49df05cac555145 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Thu, 25 Jan 2024 02:41:14 -0800 Subject: [PATCH] Switched to using `require_relative` to improve load-times (closes #93). --- lib/nmap.rb | 6 +++--- lib/nmap/xml.rb | 14 +++++++------- lib/nmap/xml/cpe.rb | 2 +- lib/nmap/xml/host.rb | 24 ++++++++++++------------ lib/nmap/xml/host_script.rb | 2 +- lib/nmap/xml/ip_id_sequence.rb | 2 +- lib/nmap/xml/os.rb | 4 ++-- lib/nmap/xml/os_class.rb | 2 +- lib/nmap/xml/port.rb | 4 ++-- lib/nmap/xml/postscript.rb | 2 +- lib/nmap/xml/prescript.rb | 2 +- lib/nmap/xml/scripts.rb | 2 +- lib/nmap/xml/service.rb | 2 +- lib/nmap/xml/tcp_sequence.rb | 4 ++-- lib/nmap/xml/tcp_ts_sequence.rb | 2 +- lib/nmap/xml/traceroute.rb | 2 +- ruby-nmap.gemspec | 5 +---- 17 files changed, 39 insertions(+), 42 deletions(-) diff --git a/lib/nmap.rb b/lib/nmap.rb index e2ecf76..44931a4 100644 --- a/lib/nmap.rb +++ b/lib/nmap.rb @@ -1,3 +1,3 @@ -require 'nmap/program' -require 'nmap/xml' -require 'nmap/version' +require_relative 'nmap/program' +require_relative 'nmap/xml' +require_relative 'nmap/version' diff --git a/lib/nmap/xml.rb b/lib/nmap/xml.rb index 8938de7..71c963b 100644 --- a/lib/nmap/xml.rb +++ b/lib/nmap/xml.rb @@ -1,10 +1,10 @@ -require 'nmap/xml/scanner' -require 'nmap/xml/scan_task' -require 'nmap/xml/scan' -require 'nmap/xml/host' -require 'nmap/xml/run_stat' -require 'nmap/xml/prescript' -require 'nmap/xml/postscript' +require_relative 'xml/scanner' +require_relative 'xml/scan_task' +require_relative 'xml/scan' +require_relative 'xml/host' +require_relative 'xml/run_stat' +require_relative 'xml/prescript' +require_relative 'xml/postscript' require 'nokogiri' diff --git a/lib/nmap/xml/cpe.rb b/lib/nmap/xml/cpe.rb index a6c196c..3d1e2ac 100644 --- a/lib/nmap/xml/cpe.rb +++ b/lib/nmap/xml/cpe.rb @@ -1,4 +1,4 @@ -require 'nmap/xml/cpe/url' +require_relative 'cpe/url' module Nmap class XML diff --git a/lib/nmap/xml/host.rb b/lib/nmap/xml/host.rb index 8cbfae8..4fa1785 100644 --- a/lib/nmap/xml/host.rb +++ b/lib/nmap/xml/host.rb @@ -1,14 +1,14 @@ -require 'nmap/xml/status' -require 'nmap/xml/address' -require 'nmap/xml/hostname' -require 'nmap/xml/os' -require 'nmap/xml/port' -require 'nmap/xml/ip_id_sequence' -require 'nmap/xml/tcp_sequence' -require 'nmap/xml/tcp_ts_sequence' -require 'nmap/xml/uptime' -require 'nmap/xml/traceroute' -require 'nmap/xml/host_script' +require_relative 'status' +require_relative 'address' +require_relative 'hostname' +require_relative 'os' +require_relative 'port' +require_relative 'ip_id_sequence' +require_relative 'tcp_sequence' +require_relative 'tcp_ts_sequence' +require_relative 'uptime' +require_relative 'traceroute' +require_relative 'host_script' require 'nokogiri' require 'time' @@ -258,7 +258,7 @@ def os # @yield [uptime] # If a block is given, it will be passed the resulting object # - # @yieldparam [Uptime] + # @yieldparam [Uptime] # Uptime value. # # @return [Uptime] diff --git a/lib/nmap/xml/host_script.rb b/lib/nmap/xml/host_script.rb index f7e0ec7..2de2bb5 100644 --- a/lib/nmap/xml/host_script.rb +++ b/lib/nmap/xml/host_script.rb @@ -1,4 +1,4 @@ -require 'nmap/xml/scripts' +require_relative 'scripts' module Nmap class XML diff --git a/lib/nmap/xml/ip_id_sequence.rb b/lib/nmap/xml/ip_id_sequence.rb index b38b082..0c7f291 100644 --- a/lib/nmap/xml/ip_id_sequence.rb +++ b/lib/nmap/xml/ip_id_sequence.rb @@ -1,4 +1,4 @@ -require 'nmap/xml/sequence' +require_relative 'sequence' module Nmap class XML diff --git a/lib/nmap/xml/os.rb b/lib/nmap/xml/os.rb index 59e68f0..bed7093 100644 --- a/lib/nmap/xml/os.rb +++ b/lib/nmap/xml/os.rb @@ -1,5 +1,5 @@ -require 'nmap/xml/os_class' -require 'nmap/xml/os_match' +require_relative 'os_class' +require_relative 'os_match' module Nmap class XML diff --git a/lib/nmap/xml/os_class.rb b/lib/nmap/xml/os_class.rb index b9745cf..1d4ce80 100644 --- a/lib/nmap/xml/os_class.rb +++ b/lib/nmap/xml/os_class.rb @@ -1,4 +1,4 @@ -require 'nmap/xml/cpe' +require_relative 'cpe' module Nmap class XML diff --git a/lib/nmap/xml/port.rb b/lib/nmap/xml/port.rb index 1dd70f2..b69a23f 100644 --- a/lib/nmap/xml/port.rb +++ b/lib/nmap/xml/port.rb @@ -1,5 +1,5 @@ -require 'nmap/xml/service' -require 'nmap/xml/scripts' +require_relative 'service' +require_relative 'scripts' module Nmap class XML diff --git a/lib/nmap/xml/postscript.rb b/lib/nmap/xml/postscript.rb index a51ebba..8f455c2 100644 --- a/lib/nmap/xml/postscript.rb +++ b/lib/nmap/xml/postscript.rb @@ -1,4 +1,4 @@ -require 'nmap/xml/scripts' +require_relative 'scripts' module Nmap class XML diff --git a/lib/nmap/xml/prescript.rb b/lib/nmap/xml/prescript.rb index cba02a3..f9bd1f1 100644 --- a/lib/nmap/xml/prescript.rb +++ b/lib/nmap/xml/prescript.rb @@ -1,4 +1,4 @@ -require 'nmap/xml/scripts' +require_relative 'scripts' module Nmap class XML diff --git a/lib/nmap/xml/scripts.rb b/lib/nmap/xml/scripts.rb index 41741ef..5cc1fe2 100644 --- a/lib/nmap/xml/scripts.rb +++ b/lib/nmap/xml/scripts.rb @@ -1,4 +1,4 @@ -require 'nmap/xml/script' +require_relative 'script' module Nmap class XML diff --git a/lib/nmap/xml/service.rb b/lib/nmap/xml/service.rb index ec70c85..f23d9c5 100644 --- a/lib/nmap/xml/service.rb +++ b/lib/nmap/xml/service.rb @@ -1,4 +1,4 @@ -require 'nmap/xml/cpe' +require_relative 'cpe' module Nmap class XML diff --git a/lib/nmap/xml/tcp_sequence.rb b/lib/nmap/xml/tcp_sequence.rb index a0bd5ee..caaffbf 100644 --- a/lib/nmap/xml/tcp_sequence.rb +++ b/lib/nmap/xml/tcp_sequence.rb @@ -1,4 +1,4 @@ -require 'nmap/xml/sequence' +require_relative 'sequence' module Nmap class XML @@ -14,7 +14,7 @@ class TcpSequence < Sequence # The difficulty index from nmap # # @since 0.5.0 - # + # def index @index ||= if (index_string = @node['index']) index_string.to_i diff --git a/lib/nmap/xml/tcp_ts_sequence.rb b/lib/nmap/xml/tcp_ts_sequence.rb index 444c6e4..0c2279e 100644 --- a/lib/nmap/xml/tcp_ts_sequence.rb +++ b/lib/nmap/xml/tcp_ts_sequence.rb @@ -1,4 +1,4 @@ -require 'nmap/xml/sequence' +require_relative 'sequence' module Nmap class XML diff --git a/lib/nmap/xml/traceroute.rb b/lib/nmap/xml/traceroute.rb index 274acb5..3dbeec1 100644 --- a/lib/nmap/xml/traceroute.rb +++ b/lib/nmap/xml/traceroute.rb @@ -1,4 +1,4 @@ -require 'nmap/xml/hop' +require_relative 'hop' module Nmap class XML diff --git a/ruby-nmap.gemspec b/ruby-nmap.gemspec index 64e2f66..c0ad9d6 100644 --- a/ruby-nmap.gemspec +++ b/ruby-nmap.gemspec @@ -7,10 +7,7 @@ Gem::Specification.new do |gem| gem.name = gemspec.fetch('name') gem.version = gemspec.fetch('version') do - lib_dir = File.join(File.dirname(__FILE__),'lib') - $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir) - - require 'nmap/version' + require_relative 'lib/nmap/version' Nmap::VERSION end