lib/ronin/config.rb in ronin-1.0.0.pre4 vs lib/ronin/config.rb in ronin-1.0.0.rc1
- old
+ new
@@ -15,77 +15,78 @@
#
# 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.
+ #
module Config
include DataPaths
# The users home directory
- HOME = File.expand_path(ENV['HOME'] || ENV['HOMEPATH'])
+ HOME = Env.home
# Ronin home directory
- PATH = File.join(HOME,'.ronin')
+ PATH = HOME.join('.ronin')
# Configuration files directory
- CONFIG_DIR = File.join(PATH,'config')
+ CONFIG_DIR = PATH.join('config')
# Directory which repositories are installed into
- REPOS_DIR = File.join(PATH,'repos')
+ REPOS_DIR = PATH.join('repos')
# Temporary file directory
- TMP_DIR = File.join(PATH,'tmp')
+ TMP_DIR = PATH.join('tmp')
- # Directory for storing files for campaigns
- CAMPAIGNS_DIR = File.join(PATH,'campaigns')
-
- FileUtils.mkdir(PATH) unless File.directory?(PATH)
- FileUtils.mkdir(CONFIG_DIR) unless File.directory?(PATH)
- FileUtils.mkdir(TMP_DIR) unless File.directory?(TMP_DIR)
- FileUtils.mkdir(CAMPAIGNS_DIR) unless File.directory?(CAMPAIGNS_DIR)
+ PATH.mkdir unless PATH.directory?
+ CONFIG_DIR.mkdir unless PATH.directory?
+ TMP_DIR.mkdir unless TMP_DIR.directory?
#
# Loads the Ronin configuration file.
#
# @param [Symbol, String, nil] name
- # The optional name of the file to load within +CONFIG_DIR+.
+ # The optional name of the file to load within {CONFIG_DIR}.
#
- # @example Load the config file at `~/.ronin/config/ronin.rb`
+ # @example Load the config file at `~/.ronin/config.rb`
# Config.load
# # => true
#
- # @example Load a specific config file in `~/.ronin/config/`
+ # @example Load the config file at `~/.ronin/config/sql.rb`
# Config.load :sql
# # => true
#
- def Config.load(name=:ronin)
- path = File.expand_path(File.join(CONFIG_DIR,name.to_s))
+ def Config.load(name=nil)
+ path = if name
+ CONFIG_DIR.join("#{name}.rb").expand_path
+ else
+ PATH.join('config.rb')
+ end
- require path if File.file?(path)
+ require path if path.file?
end
#
# Auto-creates a directory within {TMP_DIR}.
#
# @param [String] sub_path
# The sub-path within {TMP_DIR}.
#
- # @return [String]
+ # @return [Pathname]
# The full path within {TMP_DIR}.
#
def Config.tmp_dir(sub_path=nil)
if sub_path
sub_path = File.expand_path(File.join('',sub_path))
- path = File.join(TMP_DIR,sub_path)
+ path = TMP_DIR.join(sub_path)
- unless File.exist?(path)
- FileUtils.mkdir_p(path)
- end
-
+ path.mkpath unless path.exist?
return path
end
return TMP_DIR
end