| Class | Merb::BootLoader::Dependencies |
| In: |
merb-core/lib/merb-core/bootloader.rb
|
| Parent: | Merb::BootLoader |
Loads json or json_pure and requires it.
nil
:api: private
# File merb-core/lib/merb-core/bootloader.rb, line 415
415: def self.enable_json_gem
416: gem "json"
417: require "json/ext"
418: rescue LoadError
419: gem "json_pure"
420: require "json/pure"
421: end
Load each dependency that has been declared so far.
nil
:api: private
# File merb-core/lib/merb-core/bootloader.rb, line 404
404: def self.load_dependencies
405: dependencies.each { |dependency| Kernel.load_dependency(dependency, nil) }
406: nil
407: 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, 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.
nil
:api: plugin
# File merb-core/lib/merb-core/bootloader.rb, line 382
382: def self.run
383: set_encoding
384: # this is crucial: load init file with all the preferences
385: # then environment init file, then start enabling specific
386: # components, load dependencies and update logger.
387: unless Merb::disabled?(:initfile)
388: load_initfile
389: load_env_config
390: end
391: expand_ruby_path
392: enable_json_gem unless Merb::disabled?(:json)
393: load_dependencies
394: update_logger
395: nil
396: end
Default encoding to UTF8 if it has not already been set to something else.
nil
:api: private
# File merb-core/lib/merb-core/bootloader.rb, line 452
452: def self.set_encoding
453: unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("1.9")
454: $KCODE = 'UTF8' if $KCODE == 'NONE' || $KCODE.blank?
455: end
456:
457: nil
458: end
Resets the logger and sets the log_stream to Merb::Config[:log_file] if one is specified, falling back to STDOUT.
nil
:api: private
# File merb-core/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: raise "log file should be a string, got: #{Merb::Config[:log_file].inspect}" unless Merb::Config[:log_file].is_a?(String)
436: STDOUT.puts "Logging to file at #{Merb::Config[:log_file]}" unless Merb.testing?
437: Merb::Config[:log_stream] = File.open(Merb::Config[:log_file], "a")
438: # but if it's not given, fallback to log stream or stdout
439: else
440: Merb::Config[:log_stream] ||= STDOUT
441: end
442:
443: nil
444: end
Determines the path for the environment configuration file
| String: | The path to the config file for the environment |
:api: private
# File merb-core/lib/merb-core/bootloader.rb, line 468
468: def self.env_config
469: Merb.dir_for(:config) / "environments" / (Merb.environment + ".rb")
470: end
Checks to see whether or not an environment configuration exists
| Boolean: | Whether or not the environment configuration file exists. |
:api: private
# File merb-core/lib/merb-core/bootloader.rb, line 478
478: def self.env_config?
479: Merb.environment && File.exist?(env_config)
480: end
Expands Ruby path with framework directories (for models, lib, etc). Only run once.
nil
:api: private
# File merb-core/lib/merb-core/bootloader.rb, line 537
537: def self.expand_ruby_path
538: # Add models, controllers, helpers and lib to the load path
539: unless @ran
540: Merb.logger.info "Expanding RUBY_PATH..." if Merb::Config[:verbose]
541:
542: $LOAD_PATH.unshift Merb.dir_for(:model)
543: $LOAD_PATH.unshift Merb.dir_for(:controller)
544: $LOAD_PATH.unshift Merb.dir_for(:lib)
545: $LOAD_PATH.unshift Merb.dir_for(:helper)
546: end
547:
548: @ran = true
549: nil
550: end
Determines the init file to use, if any. By default Merb uses init.rb from application config directory.
nil
:api: private
# File merb-core/lib/merb-core/bootloader.rb, line 503
503: def self.initfile
504: if Merb::Config[:init_file]
505: Merb::Config[:init_file].chomp(".rb") + ".rb"
506: else
507: Merb.dir_for(:config) / "init.rb"
508: end
509: end
Loads the environment configuration file, if it is present
nil
:api: private
# File merb-core/lib/merb-core/bootloader.rb, line 488
488: def self.load_env_config
489: if env_config?
490: STDOUT.puts "Loading #{env_config}" unless Merb.testing?
491: load(env_config)
492: end
493: nil
494: end
Loads the init file, should one exist
nil
:api: private
# File merb-core/lib/merb-core/bootloader.rb, line 517
517: def self.load_initfile
518: return nil if Merb.const_defined?("INIT_RB_LOADED")
519: if File.exists?(initfile)
520: STDOUT.puts "Loading init file from #{initfile}" unless Merb.testing?
521: load(initfile)
522: Merb.const_set("INIT_RB_LOADED", true)
523: elsif !Merb.testing?
524: Merb.fatal! "You are not in a Merb application, or you are in " \
525: "a flat application and have not specified the init file. If you " \
526: "are trying to create a new merb application, use merb-gen app."
527: end
528: nil
529: end