Module: Oolite
- Defined in:
- lib/oolite/console.rb,
lib/oolite.rb,
lib/oolite/trade.rb,
lib/oolite/market.rb,
lib/oolite/csv_doc.rb,
lib/oolite/version.rb,
lib/oolite/save_file.rb,
lib/oolite/market_file.rb,
lib/oolite/system_data.rb,
lib/oolite/systems_data.rb
Overview
- 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
Defined Under Namespace
Modules: Console Classes: CSVDoc, Configuration, Market, MarketFile, SaveFile, SystemData, SystemsData, Trade
Constant Summary collapse
- CONFIG_FILE_NAME =
'.oolite'
- VERSION =
"0.0.4"
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Class Method Summary collapse
-
.configure {|configuration| ... } ⇒ Object
Setup oolite configuration.
-
.find_config_path ⇒ Object
Walk up the directory tree from current working dir (pwd) till a file named .oolite is found.
-
.load_configuration(path = nil) ⇒ Object
Load the configuration from disk.
-
.save_configuration(path = nil) ⇒ Object
Write configuration to disk.
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
16 17 18 |
# File 'lib/oolite.rb', line 16 def configuration @configuration end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
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.
32 33 34 35 36 37 38 39 |
# 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 |
.find_config_path ⇒ Object
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.
48 49 50 51 52 53 54 |
# 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_configuration(path = nil) ⇒ Object
Load the configuration from disk
Returns true if config file found and loaded, false otherwise.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# 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 |
.save_configuration(path = nil) ⇒ Object
Write configuration to disk
Writes to current working dir (pwd) if path is nil
Returns path of emitted file
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# 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). File.write(path, YAML.dump(configuration)) path end |