class Merb::BootLoader::Dependencies
Public Class Methods
Requires json or json_pure.
Returns¶ ↑
nil
:api: private
# File lib/merb-core/bootloader.rb, line 414 def self.enable_json_gem require "json" rescue LoadError Merb.logger.error! "You have enabled JSON but don't have json " "installed or don't have dependency in the Gemfile. " "Add \"gem 'json', '>= 1.1.7'\" or " "\"gem 'json_pure', '>= 1.1.7'\" to your Gemfile." end
Try to load the gem environment file (set via Merb::Config) defaults to ./gems/environment
Load each the dependencies defined in the Merb::Config using the bundler gem's Bundler::require_env
Falls back to rubygems if no bundler environment exists
Returns¶ ↑
nil
:api: private
# File lib/merb-core/bootloader.rb, line 398 def self.load_dependencies begin Bundler.require(:default, Merb.environment.to_sym) rescue Bundler::GemfileNotFound Merb.logger.error! "No Gemfile found! If you're generating new app with merb-gen " "this is fine, otherwise run: bundle init to create Gemfile" end nil end
Load the init_file specified in Merb::Config or if not specified, the init.rb file from the Merb configuration directory, and any environment files and any after_app_loads hooks.
Dependencies are loaded via Bunlder and managed in the Gemfile manifest. By default manifest for Bundler is in the root directory of the app and is called Gemfile. All dependencies MUST be definied there because all dependency hangling was removed from Merb.
Deprecated (1.0.x)¶ ↑
Dependencies can hook into the bootloader process itself by using before or after insertion methods. Since these are loaded from this bootloader (Dependencies), they can only adapt the bootloaders that haven't been loaded up until this point.
Returns¶ ↑
nil
:api: plugin
# File lib/merb-core/bootloader.rb, line 373 def self.run set_encoding load_dependencies unless Merb::disabled?(:initfile) load_initfile load_env_config end expand_ruby_path enable_json_gem unless Merb::disabled?(:json) update_logger nil end
Resets the logger and sets the log_stream to Merb::Config if one is specified, falling back to STDOUT.
Returns¶ ↑
nil
:api: private
# File lib/merb-core/bootloader.rb, line 430 def self.update_logger Merb.reset_logger! # If log file is given, use it and not log stream we have. if Merb::Config[:log_file] log_file = Merb::Config[:log_file] raise "log file should be a string, got: #{log_file.inspect}" unless log_file.is_a?(String) STDOUT.puts "Logging to file at #{log_file}" unless Merb.testing? # try to create log directory (if it doesnt exist) log_directory = File.dirname(log_file) FileUtils.mkdir_p(log_directory) unless File.exists?(log_directory) Merb::Config[:log_stream] = File.open(log_file, "a") # but if it's not given, fallback to log stream or stdout else Merb::Config[:log_stream] ||= STDOUT end nil end
Private Class Methods
Expands Ruby path with framework directories (for models, lib, etc). Only run once.
Returns¶ ↑
nil
:api: private
# File lib/merb-core/bootloader.rb, line 545 def self.expand_ruby_path # Add models, controllers, helpers and lib to the load path unless @ran Merb.logger.info "Expanding RUBY_PATH..." if Merb::Config[:verbose] $LOAD_PATH.unshift Merb.dir_for(:model) $LOAD_PATH.unshift Merb.dir_for(:controller) $LOAD_PATH.unshift Merb.dir_for(:lib) $LOAD_PATH.unshift Merb.dir_for(:helper) end @ran = true nil end
Determines the init file to use, if any. By default Merb uses init.rb from application config directory.
Returns¶ ↑
nil
:api: private
# File lib/merb-core/bootloader.rb, line 510 def self.initfile if Merb::Config[:init_file] Merb::Config[:init_file].chomp(".rb") + ".rb" else Merb.dir_for(:config) / "init.rb" end end
Loads the environment configuration file, if it is present
Returns¶ ↑
nil
:api: private
# File lib/merb-core/bootloader.rb, line 494 def self.load_env_config if env_config? env_config_path = relative_to_merb_path(env_config) STDOUT.puts "Loading #{env_config_path}" unless Merb.testing? load(env_config) end nil end
Loads the init file, should one exist
Returns¶ ↑
nil
:api: private
# File lib/merb-core/bootloader.rb, line 524 def self.load_initfile return nil if Merb.const_defined?("INIT_RB_LOADED") if File.exists?(initfile) initfile_path = relative_to_merb_path(initfile) STDOUT.puts "Loading init file from #{initfile_path}" unless Merb.testing? load(initfile) Merb.const_set("INIT_RB_LOADED", true) elsif !Merb.testing? Merb.fatal! "You are not in a Merb application, or you are in " "a flat application and have not specified the init file. If you " "are trying to create a new merb application, use merb-gen app." end nil end
Converts an absolute path to an path relative to Merbs root, if the path is in the Merb root dir. Otherwise it will return the absolute path.
Returns¶ ↑
- String
-
Relative path or absolute
:api: private
# File lib/merb-core/bootloader.rb, line 568 def self.relative_to_merb_path(path) absolute_path = File.expand_path(path) merb_root = File.expand_path(Merb.root) if absolute_path.slice(0, merb_root.length) == merb_root '.' + absolute_path.slice(merb_root.length..-1) else absolute_path end end