Class: Autumn::Genesis
- Inherits:
-
Object
- Object
- Autumn::Genesis
- Defined in:
- lib/autumn/genesis.rb
Overview
Oversight class responsible for initializing the Autumn environment. To boot the Autumn environment start all configured leaves, you make an instance of this class and run the boot! method. Leaves will each run in their own thread, monitored by an oversight thread spawned by this class.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
The Speciator singleton.
Instance Method Summary collapse
-
#boot!(invoke = true) ⇒ Object
Bootstraps the Autumn environment, and begins the stems’ execution threads if
invoke
is set to true. -
#init_system_logger ⇒ Object
Initializes the system-level logger.
-
#initialize ⇒ Genesis
constructor
Creates a new instance that can be used to boot Autumn.
-
#invoke_foliater(invoke = true) ⇒ Object
Invokes the Foliater.load method.
-
#load_daemon_info ⇒ Object
Instantiates Daemons from YAML files in resources/daemons.
-
#load_databases ⇒ Object
Creates connections to databases using the DataMapper gem.
-
#load_global_settings ⇒ Object
Loads the settings in the global.yml file.
-
#load_libraries ⇒ Object
Loads Autumn library objects.
-
#load_season_settings ⇒ Object
Loads the settings for the current season in its season.yml file.
-
#load_shared_code ⇒ Object
Loads Ruby code in the shared directory.
Constructor Details
Instance Attribute Details
#config ⇒ Object (readonly)
The Speciator singleton.
26 27 28 |
# File 'lib/autumn/genesis.rb', line 26 def config @config end |
Instance Method Details
#boot!(invoke = true) ⇒ Object
Bootstraps the Autumn environment, and begins the stems’ execution threads if invoke
is set to true.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/autumn/genesis.rb', line 37 def boot!(invoke=true) load_global_settings load_season_settings load_libraries init_system_logger load_daemon_info load_shared_code load_databases invoke_foliater(invoke) end |
#init_system_logger ⇒ Object
Initializes the system-level logger.
PREREQS: load_libraries
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/autumn/genesis.rb', line 96 def init_system_logger config.global :logfile => Logger.new(log_name, config.global(:log_history) || 10, 1024*1024) begin config.global(:logfile).level = Logger.const_get(config.season(:logging).upcase) rescue NameError puts "The level #{config.season(:logging).inspect} was not understood; the log level has been raised to INFO." config.global(:logfile).level = Logger::INFO end config.global :system_logger => LogFacade.new(config.global(:logfile), 'N/A', 'System') @logger = config.global(:system_logger) end |
#invoke_foliater(invoke = true) ⇒ Object
Invokes the Foliater.load method. Spawns a new thread to oversee the stems’ threads. This thread will exit when all leaves have terminated. Stems will not be started if invoke
is set to false.
PREREQS: load_databases, load_season_settings, load_libraries, init_system_logger
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/autumn/genesis.rb', line 153 def invoke_foliater(invoke=true) begin begin stem_config = YAML.load(File.open("#{@season_dir}/stems.yml", 'r')) rescue Errno::ENOENT raise "Couldn't find stems.yml file for season #{config.global :season}" end begin leaf_config = YAML.load(File.open("#{@season_dir}/leaves.yml", 'r')) rescue Errno::ENOENT # build a default leaf config leaf_config = Hash.new Dir.entries("leaves").each do |dir| next if not File.directory? "leaves/#{dir}" or dir[0,1] == '.' leaf_name = dir.camelcase leaf_config[leaf_name] = { 'class' => leaf_name } end end Foliater.instance.load stem_config, leaf_config, invoke if invoke then # suspend execution of the master thread until all stems are dead while Foliater.instance.alive? Thread.stop end end rescue @logger.fatal $! end end |
#load_daemon_info ⇒ Object
Instantiates Daemons from YAML files in resources/daemons. The daemons are named after their YAML files.
PREREQS: load_libraries
113 114 115 116 117 118 |
# File 'lib/autumn/genesis.rb', line 113 def load_daemon_info Dir.glob("#{::Autumn::ROOT}/autumn/resources/daemons/*.yml").each do |yml_file| yml = YAML.load(File.open(yml_file, 'r')) Daemon.new File.basename(yml_file, '.yml'), yml end end |
#load_databases ⇒ Object
Creates connections to databases using the DataMapper gem.
PREREQS: load_season_settings
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/autumn/genesis.rb', line 130 def load_databases db_file = "#{@season_dir}/database.yml" if not File.exist? db_file then $NO_DATABASE = true return end require 'dm-core' require 'autumn/datamapper_hacks' dbconfig = YAML.load(File.open(db_file, 'r')) dbconfig.rekey(&:to_sym).each do |db, config| DataMapper.setup(db, config.kind_of?(Hash) ? config.rekey(&:to_sym) : config) end end |
#load_global_settings ⇒ Object
Loads the settings in the global.yml file.
PREREQS: None
52 53 54 55 56 57 58 59 60 |
# File 'lib/autumn/genesis.rb', line 52 def load_global_settings begin config.global YAML.load(File.open("#{AL_ROOT}/config/global.yml")) rescue SystemCallError raise "Couldn't find your global.yml file." end config.global :root => AL_ROOT config.global :season => ENV['SEASON'] if ENV['SEASON'] end |
#load_libraries ⇒ Object
Loads Autumn library objects.
PREREQS: load_global_settings
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/autumn/genesis.rb', line 80 def load_libraries require 'autumn/inheritable_attributes' require 'autumn/daemon' require 'autumn/stem_facade' require 'autumn/ctcp' require 'autumn/stem' require 'autumn/leaf' require 'autumn/channel_leaf' require 'autumn/foliater' require 'autumn/log_facade' end |
#load_season_settings ⇒ Object
Loads the settings for the current season in its season.yml file.
PREREQS: load_global_settings
66 67 68 69 70 71 72 73 74 |
# File 'lib/autumn/genesis.rb', line 66 def load_season_settings @season_dir = "#{AL_ROOT}/config/seasons/#{config.global :season}" raise "The current season doesn't have a directory." unless File.directory? @season_dir begin config.season YAML.load(File.open("#{@season_dir}/season.yml")) rescue # season.yml is optional end end |
#load_shared_code ⇒ Object
Loads Ruby code in the shared directory.
122 123 124 |
# File 'lib/autumn/genesis.rb', line 122 def load_shared_code Dir.glob("#{AL_ROOT}/shared/**/*.rb").each { |lib| load lib } end |