lib/ronin/config.rb in ronin-1.4.0 vs lib/ronin/config.rb in ronin-1.4.1
- old
+ new
@@ -15,41 +15,45 @@
#
# You should have received a copy of the GNU General Public License
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
#
-require 'env'
require 'data_paths'
require 'fileutils'
module Ronin
#
# Configuration information for Ronin.
#
+ # @api semipublic
+ #
module Config
include DataPaths
extend DataPaths::Finders
# The users home directory
- HOME = Env.home
+ HOME = Gem.user_home
# Ronin home directory
- PATH = HOME.join('.ronin')
+ PATH = File.join(HOME,'.ronin')
# Configuration files directory
- CONFIG_DIR = PATH.join('config')
+ CONFIG_DIR = File.join(PATH,'config')
# Directory which repositories are installed into
- REPOS_DIR = PATH.join('repos')
+ REPOS_DIR = File.join(PATH,'repos')
# Temporary file directory
- TMP_DIR = PATH.join('tmp')
+ TMP_DIR = File.join(PATH,'tmp')
- PATH.mkdir unless PATH.directory?
- CONFIG_DIR.mkdir unless PATH.directory?
- TMP_DIR.mkdir unless TMP_DIR.directory?
+ # Directories which contain binaries
+ BIN_DIRS = ENV.fetch('PATH','').split(File::PATH_SEPARATOR)
+ [PATH, CONFIG_DIR, TMP_DIR].each do |dir|
+ FileUtils.mkdir(dir) unless File.directory?(dir)
+ end
+
#
# Loads the Ronin configuration file.
#
# @param [Symbol, String, nil] name
# The optional name of the file to load within {CONFIG_DIR}.
@@ -63,35 +67,36 @@
# # => true
#
# @api semipublic
#
def Config.load(name=nil)
- path = if name
- CONFIG_DIR.join("#{name}.rb").expand_path
- else
- PATH.join('config.rb')
- end
+ dir, file = if name
+ [CONFIG_DIR, "#{name}.rb"]
+ else
+ [PATH, 'config.rb']
+ end
- require path if path.file?
+ path = File.expand_path(File.join(dir,file))
+ require path if File.file?(path)
end
#
# Auto-creates a directory within {TMP_DIR}.
#
# @param [String] sub_path
# The sub-path within {TMP_DIR}.
#
- # @return [Pathname]
+ # @return [String]
# The full path within {TMP_DIR}.
#
# @api semipublic
#
def Config.tmp_dir(sub_path=nil)
if sub_path
sub_path = File.expand_path(File.join('',sub_path))
- path = TMP_DIR.join(sub_path)
+ path = File.join(TMP_DIR,sub_path)
- path.mkpath unless path.exist?
+ FileUtils.mkdir_p(path) unless File.exist?(path)
return path
end
return TMP_DIR
end