class RuGUI::Initializer

Attributes

configuration[R]

The configuration for this application.

gems_dependencies_loaded[R]

Whether or not all the gem dependencies have been met

Public Class Methods

new(configuration) click to toggle source

Create a new Initializer instance that references the given Configuration instance.

# File lib/rugui/initializer.rb, line 33
def initialize(configuration)
  @configuration = configuration
end
run(command = :process, configuration = Configuration.new) { |configuration| ... } click to toggle source

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.

# 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

Public Instance Methods

add_gem_load_paths() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/rugui/initializer.rb, line 145
def finish_initialization_process_log
  logger.info "RuGUI application configurations loaded." unless silence_logs?
end
load_environment() click to toggle source

Loads the environment specified by Configuration#environment_path, which is typically one of development, or production.

# 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() click to toggle source
# File lib/rugui/initializer.rb, line 153
def load_framework_adapter
  require "rugui/framework_adapters/#{RuGUI.configuration.framework_adapter}"
end
load_gems() click to toggle source
# 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() click to toggle source
# File lib/rugui/initializer.rb, line 137
def load_logger
  RuGUILogger.logger
end
load_plugins() click to toggle source
# File lib/rugui/initializer.rb, line 97
def load_plugins
  plugin_loader.load_plugins
end
plugin_loader() click to toggle source
# File lib/rugui/initializer.rb, line 149
def plugin_loader
  @plugin_loader || RuGUI::Plugin::Loader.new(self, configuration)
end
process() click to toggle source

Sequentially step through all of the available initialization routines, in order (view execution order in source).

# 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() click to toggle source

Set the paths from which RuGUI will automatically load source files.

# File lib/rugui/initializer.rb, line 75
def set_autoload_paths
  ActiveSupport::Dependencies.autoload_paths = configuration.load_paths.uniq
end
set_load_path() click to toggle source

Set the $LOAD_PATH based on the value of Configuration#load_paths. Duplicates are removed.

# 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() click to toggle source
# 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

Private Instance Methods

silence_logs?() click to toggle source
# File lib/rugui/initializer.rb, line 158
def silence_logs?
  @@processed or $gems_build_rake_task or $gems_rake_task
end