module Oolite
- File
-
console.rb
- Purpose
-
Console
Module includes helper methods related to console IO - Author
-
Jeff McAffee 05/22/2015
- Copyright
-
Copyright © 2015, kTech Systems LLC. All rights reserved.
- Website
- File
-
csv_doc.rb
- Purpose
-
CSVDoc
class for emitting formatted CSV documents - Author
-
Jeff McAffee 05/19/2015
- Copyright
-
Copyright © 2015, kTech Systems LLC. All rights reserved.
- Website
- File
-
system_data.rb
- Purpose
-
SystemData
stores info about a single system (ie. economy, government, etc) - Author
-
Jeff McAffee 05/22/2015
- Copyright
-
Copyright © 2015, kTech Systems LLC. All rights reserved.
- Website
- File
-
systems_data.rb
- Purpose
-
SystemsData
stores info about systems (ie. economy, government, etc) - Author
-
Jeff McAffee 05/22/2015
- Copyright
-
Copyright © 2015, kTech Systems LLC. All rights reserved.
- Website
Constants
- CONFIG_FILE_NAME
- VERSION
Attributes
Public Class Methods
Setup oolite configuration
Attempts to find and load a configuration file the first time it’s requested. If a config file cannot be found in the current directory tree (moving towards trunk, not the leaves), the user’s home directory will be searched. If still not found, a default configuration object is created.
If a block is provided, the configuration object is yielded to the block after the configuration is loaded/created.
# File lib/oolite.rb, line 32 def self.configure if self.configuration.nil? unless self.load_configuration self.configuration = Configuration.new end end yield(configuration) if block_given? end
Walk up the directory tree from current working dir (pwd) till a file named .oolite is found
Returns file path if found, nil if not.
# File lib/oolite.rb, line 48 def self.find_config_path path = Pathname(Pathname.pwd).ascend{|d| h=d+CONFIG_FILE_NAME; break h if h.file?} if path.nil? && (Pathname(ENV['HOME']) + CONFIG_FILE_NAME).exist? path = Pathname(ENV['HOME']) + CONFIG_FILE_NAME end path end
Load the configuration from disk
Returns true if config file found and loaded, false otherwise.
# File lib/oolite.rb, line 91 def self.load_configuration(path = nil) # If no path provided, see if we can find one in the dir tree. if path.nil? path = find_config_path end return false if path.nil? return false unless Pathname(path).exist? File.open(path, 'r') do |f| self.configuration = YAML.load(f) puts "configuration loaded from #{path}" if $debug end true end
Write configuration to disk
Writes to current working dir (pwd) if path is nil
Returns path of emitted file
# File lib/oolite.rb, line 64 def self.save_configuration(path = nil) # If no path provided, see if we can find one in the dir tree. if path.nil? path = find_config_path end # Still no path? Use the current working dir. if path.nil? path = Pathname.pwd end unless path.to_s.end_with?('/' + CONFIG_FILE_NAME) path = Pathname(path) + CONFIG_FILE_NAME end path = Pathname(path).expand_path File.write(path, YAML.dump(configuration)) path end