Class Index [+]

Quicksearch

Merb::BootLoader::Dependencies

Public Class Methods

enable_json_gem() click to toggle source

Requires json or json_pure.

Returns

nil

:api: private

     # File lib/merb-core/bootloader.rb, line 414
414:   def self.enable_json_gem
415:     require "json"
416:     rescue LoadError
417:         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."
418:   end
load_dependencies() click to toggle source

Try to load the gem environment file (set via Merb::Config[:gemenv]) defaults to ./gems/environment

Load each the dependencies defined in the Merb::Config[:gemfile] 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
398:   def self.load_dependencies
399:     begin
400:       Bundler.require(:default, Merb.environment.to_sym)
401:     rescue Bundler::GemfileNotFound
402:       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"
403:     end
404:     nil
405:   end
run() click to toggle source

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
373:   def self.run
374:     set_encoding
375:     load_dependencies
376:     unless Merb::disabled?(:initfile)
377:       load_initfile
378:       load_env_config
379:     end
380:     expand_ruby_path
381:     enable_json_gem unless Merb::disabled?(:json)
382:     update_logger
383:     nil
384:   end
set_encoding() click to toggle source

Default encoding to UTF8 if it has not already been set to something else.

Returns

nil

:api: private

     # File lib/merb-core/bootloader.rb, line 458
458:   def self.set_encoding
459:     unless RUBY_VERSION >= '1.9'
460:       $KCODE = 'UTF8' if $KCODE == 'NONE' || $KCODE.blank?
461:     end
462:     
463:     nil
464:   end
update_logger() click to toggle source

Resets the logger and sets the log_stream to Merb::Config[:log_file] if one is specified, falling back to STDOUT.

Returns

nil

:api: private

     # File lib/merb-core/bootloader.rb, line 430
430:   def self.update_logger
431:     Merb.reset_logger!
432: 
433:     # If log file is given, use it and not log stream we have.
434:     if Merb::Config[:log_file]
435:       log_file = Merb::Config[:log_file]
436:       raise "log file should be a string, got: #{log_file.inspect}" unless log_file.is_a?(String)
437:       STDOUT.puts "Logging to file at #{log_file}" unless Merb.testing?
438:       
439:       # try to create log directory (if it doesnt exist)
440:       log_directory = File.dirname(log_file)
441:       FileUtils.mkdir_p(log_directory) unless File.exists?(log_directory)
442: 
443:       Merb::Config[:log_stream] = File.open(log_file, "a")
444:     # but if it's not given, fallback to log stream or stdout
445:     else
446:       Merb::Config[:log_stream] ||= STDOUT
447:     end
448: 
449:     nil
450:   end

Private Class Methods

env_config() click to toggle source

Determines the path for the environment configuration file

Returns

String

The path to the config file for the environment

:api: private

     # File lib/merb-core/bootloader.rb, line 474
474:     def self.env_config
475:       Merb.dir_for(:config) / "environments" / (Merb.environment + ".rb")
476:     end
env_config?() click to toggle source

Checks to see whether or not an environment configuration exists

Returns

Boolean

Whether or not the environment configuration file exists.

:api: private

     # File lib/merb-core/bootloader.rb, line 484
484:     def self.env_config?
485:       Merb.environment && File.exist?(env_config)
486:     end
expand_ruby_path() click to toggle source

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
545:     def self.expand_ruby_path
546:       # Add models, controllers, helpers and lib to the load path
547:       unless @ran
548:         Merb.logger.info "Expanding RUBY_PATH..." if Merb::Config[:verbose]
549: 
550:         $LOAD_PATH.unshift Merb.dir_for(:model)
551:         $LOAD_PATH.unshift Merb.dir_for(:controller)
552:         $LOAD_PATH.unshift Merb.dir_for(:lib)
553:         $LOAD_PATH.unshift Merb.dir_for(:helper)
554:       end
555: 
556:       @ran = true
557:       nil
558:     end
initfile() click to toggle source

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
510:     def self.initfile
511:       if Merb::Config[:init_file]
512:         Merb::Config[:init_file].chomp(".rb") + ".rb"
513:       else
514:         Merb.dir_for(:config) / "init.rb"
515:       end
516:     end
load_env_config() click to toggle source

Loads the environment configuration file, if it is present

Returns

nil

:api: private

     # File lib/merb-core/bootloader.rb, line 494
494:     def self.load_env_config
495:       if env_config?
496:         env_config_path = relative_to_merb_path(env_config)
497:         STDOUT.puts "Loading #{env_config_path}" unless Merb.testing?
498:         load(env_config)
499:       end
500:       nil
501:     end
load_initfile() click to toggle source

Loads the init file, should one exist

Returns

nil

:api: private

     # File lib/merb-core/bootloader.rb, line 524
524:     def self.load_initfile
525:       return nil if Merb.const_defined?("INIT_RB_LOADED")
526:       if File.exists?(initfile)
527:         initfile_path = relative_to_merb_path(initfile)
528:         STDOUT.puts "Loading init file from #{initfile_path}" unless Merb.testing?
529:         load(initfile)
530:         Merb.const_set("INIT_RB_LOADED", true)
531:       elsif !Merb.testing?
532:         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."
533:       end
534:       nil
535:     end
relative_to_merb_path(path) click to toggle source

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
568:     def self.relative_to_merb_path(path)
569:       absolute_path = File.expand_path(path)
570:       merb_root = File.expand_path(Merb.root)
571:       if absolute_path.slice(0, merb_root.length) == merb_root
572:         '.' + absolute_path.slice(merb_root.length..1)
573:       else
574:         absolute_path
575:       end
576:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.