Class: Merb::BootLoader::Dependencies

Inherits:
Merb::BootLoader show all
Defined in:
lib/merb-core/bootloader.rb

Class Method Summary collapse

Methods inherited from Merb::BootLoader

after, after_app_loads, before, before_app_loads, before_master_shutdown, before_worker_shutdown, default_framework, finished?, inherited, move_klass

Class Method Details

.enable_json_gemObject

Loads json or json_pure and requires it.

Returns

nil

:api: private



415
416
417
418
419
420
421
# File 'lib/merb-core/bootloader.rb', line 415

def self.enable_json_gem
  gem "json"
  require "json/ext"
rescue LoadError
  gem "json_pure"
  require "json/pure"
end

.load_dependenciesObject

Load each dependency that has been declared so far.

Returns

nil

:api: private



404
405
406
407
# File 'lib/merb-core/bootloader.rb', line 404

def self.load_dependencies
  dependencies.each { |dependency| Kernel.load_dependency(dependency, nil) }
  nil
end

.runObject

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, which register the list of necessary dependencies and any after_app_loads hooks.

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



382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/merb-core/bootloader.rb', line 382

def self.run
  set_encoding
  # this is crucial: load init file with all the preferences
  # then environment init file, then start enabling specific
  # components, load dependencies and update logger.
  unless Merb::disabled?(:initfile)
    load_initfile
    load_env_config
  end
  expand_ruby_path
  enable_json_gem unless Merb::disabled?(:json)
  load_dependencies
  update_logger
  nil
end

.set_encodingObject

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

Returns

nil

:api: private



452
453
454
455
456
457
458
# File 'lib/merb-core/bootloader.rb', line 452

def self.set_encoding
  unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("1.9")
    $KCODE = 'UTF8' if $KCODE == 'NONE' || $KCODE.blank?
  end
  
  nil
end

.update_loggerObject

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

Returns

nil

:api: private



430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# 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]
    raise "log file should be a string, got: #{Merb::Config[:log_file].inspect}" unless Merb::Config[:log_file].is_a?(String)
    STDOUT.puts "Logging to file at #{Merb::Config[:log_file]}" unless Merb.testing?
    Merb::Config[:log_stream] = File.open(Merb::Config[:log_file], "a")
  # but if it's not given, fallback to log stream or stdout
  else
    Merb::Config[:log_stream] ||= STDOUT
  end

  nil
end