Class: RuGUI::Initializer
- Includes:
- LogSupport
- Defined in:
- lib/rugui/initializer.rb
Constant Summary collapse
- @@processed =
false
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
The configuration for this application.
-
#gems_dependencies_loaded ⇒ Object
readonly
Whether or not all the gem dependencies have been met.
Class Method Summary collapse
-
.run(command = :process, configuration = Configuration.new) {|configuration| ... } ⇒ Object
Runs the initializer.
Instance Method Summary collapse
- #add_gem_load_paths ⇒ Object
- #check_gem_dependencies ⇒ Object
- #finish_initialization_process_log ⇒ Object
-
#initialize(configuration) ⇒ Initializer
constructor
Create a new Initializer instance that references the given Configuration instance.
-
#load_environment ⇒ Object
Loads the environment specified by Configuration#environment_path, which is typically one of development, or production.
- #load_framework_adapter ⇒ Object
- #load_gems ⇒ Object
- #load_logger ⇒ Object
- #load_plugins ⇒ Object
- #plugin_loader ⇒ Object
-
#process ⇒ Object
Sequentially step through all of the available initialization routines, in order (view execution order in source).
-
#set_autoload_paths ⇒ Object
Set the paths from which RuGUI will automatically load source files.
-
#set_load_path ⇒ Object
Set the
$LOAD_PATH
based on the value of Configuration#load_paths. - #start_initialization_process_log ⇒ Object
Methods included from LogSupport
Constructor Details
#initialize(configuration) ⇒ Initializer
Create a new Initializer instance that references the given Configuration instance.
33 34 35 |
# File 'lib/rugui/initializer.rb', line 33 def initialize(configuration) @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
The configuration for this application.
9 10 11 |
# File 'lib/rugui/initializer.rb', line 9 def configuration @configuration end |
#gems_dependencies_loaded ⇒ Object (readonly)
Whether or not all the gem dependencies have been met
12 13 14 |
# File 'lib/rugui/initializer.rb', line 12 def gems_dependencies_loaded @gems_dependencies_loaded end |
Class Method Details
.run(command = :process, configuration = Configuration.new) {|configuration| ... } ⇒ Object
Runs the initializer.
It runs the process procedure by default, by this can be changed by specifying a command when calling this method. A block can be given in order to change the application configuration.
22 23 24 25 26 27 28 29 |
# File 'lib/rugui/initializer.rb', line 22 def self.run(command = :process, configuration = Configuration.new) yield configuration if block_given? initializer = new configuration RuGUI.configuration = configuration initializer.send(command) @@processed = (command == :process) ? true : false initializer end |
Instance Method Details
#add_gem_load_paths ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/rugui/initializer.rb', line 101 def add_gem_load_paths RuGUI::GemDependency.add_frozen_gem_path unless @configuration.gems.empty? require "rubygems" @configuration.gems.each { |gem| gem.add_load_paths } end end |
#check_gem_dependencies ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/rugui/initializer.rb', line 115 def check_gem_dependencies unloaded_gems = @configuration.gems.reject { |g| g.loaded? } if unloaded_gems.size > 0 @gems_dependencies_loaded = false # don't print if the gems rake tasks are being run unless $gems_rake_task abort <<-end_error Missing these required gems: #{unloaded_gems.map { |gem| "#{gem.name} #{gem.requirement}" } * "\n "} You're running: ruby #{Gem.ruby_version} at #{Gem.ruby} rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '} Run `rake gems:install` to install the missing gems. end_error end else @gems_dependencies_loaded = true end end |
#finish_initialization_process_log ⇒ Object
145 146 147 |
# File 'lib/rugui/initializer.rb', line 145 def finish_initialization_process_log logger.info "RuGUI application configurations loaded." unless silence_logs? end |
#load_environment ⇒ Object
Loads the environment specified by Configuration#environment_path, which is typically one of development, or production.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rugui/initializer.rb', line 81 def load_environment return if @environment_loaded @environment_loaded = true if File.exist?(configuration.environment_path) config = configuration constants = self.class.constants eval(IO.read(configuration.environment_path), binding, configuration.environment_path) (self.class.constants - constants).each do |const| Object.const_set(const, self.class.const_get(const)) end end end |
#load_framework_adapter ⇒ Object
153 154 155 |
# File 'lib/rugui/initializer.rb', line 153 def load_framework_adapter require "rugui/framework_adapters/#{RuGUI.configuration.framework_adapter}" end |
#load_gems ⇒ Object
109 110 111 112 113 |
# File 'lib/rugui/initializer.rb', line 109 def load_gems unless $gems_build_rake_task @configuration.gems.each { |gem| gem.load } end end |
#load_logger ⇒ Object
137 138 139 |
# File 'lib/rugui/initializer.rb', line 137 def load_logger RuGUILogger.logger end |
#load_plugins ⇒ Object
97 98 99 |
# File 'lib/rugui/initializer.rb', line 97 def load_plugins plugin_loader.load_plugins end |
#plugin_loader ⇒ Object
149 150 151 |
# File 'lib/rugui/initializer.rb', line 149 def plugin_loader @plugin_loader || RuGUI::Plugin::Loader.new(self, configuration) end |
#process ⇒ Object
Sequentially step through all of the available initialization routines, in order (view execution order in source).
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rugui/initializer.rb', line 39 def process load_environment load_logger start_initialization_process_log set_load_path add_gem_load_paths set_autoload_paths load_framework_adapter load_gems load_plugins # pick up any gems that plugins depend on add_gem_load_paths load_gems check_gem_dependencies # bail out if gems are missing - note that check_gem_dependencies will have # already called abort() unless $gems_rake_task is set return unless gems_dependencies_loaded finish_initialization_process_log end |
#set_autoload_paths ⇒ Object
Set the paths from which RuGUI will automatically load source files.
75 76 77 |
# File 'lib/rugui/initializer.rb', line 75 def set_autoload_paths ActiveSupport::Dependencies.autoload_paths = configuration.load_paths.uniq end |
#set_load_path ⇒ Object
Set the $LOAD_PATH
based on the value of Configuration#load_paths. Duplicates are removed.
68 69 70 71 72 |
# File 'lib/rugui/initializer.rb', line 68 def set_load_path load_paths = configuration.load_paths load_paths.reverse_each { |dir| $LOAD_PATH.unshift(dir) if File.directory?(dir) } $LOAD_PATH.uniq! end |
#start_initialization_process_log ⇒ Object
141 142 143 |
# File 'lib/rugui/initializer.rb', line 141 def start_initialization_process_log logger.info "Starting RuGUI application with #{configuration.environment} environment..." unless silence_logs? end |