File: lib/generators/instance/templates/instance_boot.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Rails#7
has properties
module method: vendor_rails? #9
  module: Radiant#15
has properties
module method: boot! #17
module method: booted? #24
module method: pick_boot #28
module method: vendor? #39
module method: app? #43
module method: preinitialize #47
module method: loaded_via_gem? #51
module method: preinitializer_path #55
  class: Boot#60
inherits from
  Object ( Builtin-Module )
has properties
method: run #61
method: load_mutex #68
method: load_initializer #77
  class: VendorBoot#91
inherits from
  Boot ( Radiant )
has properties
method: load_initializer #92
method: load_error_message #97
  class: AppBoot#102
inherits from
  Boot ( Radiant )
has properties
method: load_initializer #103
method: load_error_message #108
  class: GemBoot#113
inherits from
  Boot ( Radiant )
has properties
method: load_error_message #115

Class Hierarchy

Object ( Builtin-Module )
Boot ( Radiant ) — #60
  VendorBoot    #91
  AppBoot    #102
  GemBoot    #113

Code

   1  # Don't change this file!
   2  # Configure your app in config/environment.rb and config/environments/*.rb
   3 
   4  RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
   5  RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
   6 
   7  module Rails
   8    class << self
   9      def vendor_rails?
  10        File.exist?("#{RAILS_ROOT}/vendor/rails")
  11      end
  12    end
  13  end
  14 
  15  module Radiant
  16    class << self
  17      def boot!
  18        unless booted?
  19          preinitialize
  20          pick_boot.run
  21        end
  22      end
  23 
  24      def booted?
  25        defined? Radiant::Initializer
  26      end
  27 
  28      def pick_boot
  29        case
  30        when app?
  31          AppBoot.new
  32        when vendor?
  33          VendorBoot.new
  34        else
  35          GemBoot.new
  36        end
  37      end
  38 
  39      def vendor?
  40        File.exist?("#{RAILS_ROOT}/vendor/radiant")
  41      end
  42      
  43      def app?
  44        File.exist?("#{RAILS_ROOT}/lib/radiant.rb")
  45      end
  46 
  47      def preinitialize
  48        load(preinitializer_path) if File.exist?(preinitializer_path)
  49      end
  50 
  51      def loaded_via_gem?
  52        pick_boot.is_a? GemBoot
  53      end
  54 
  55      def preinitializer_path
  56        "#{RAILS_ROOT}/config/preinitializer.rb"
  57      end
  58    end
  59 
  60    class Boot
  61      def run
  62        load_mutex
  63        load_initializer
  64      end
  65      
  66      # RubyGems from version 1.6 does not require thread but Rails depend on it
  67      # This should newer rails do automaticly
  68      def load_mutex
  69        begin
  70          require "thread" unless defined?(Mutex)
  71        rescue LoadError => e
  72          $stderr.puts %(Mutex could not be initialized. #{load_error_message})
  73          exit 1
  74        end
  75      end
  76      
  77      def load_initializer
  78        begin
  79          require 'radiant'
  80          require 'radiant/initializer'
  81        rescue LoadError => e
  82          $stderr.puts %(Radiant could not be initialized. #{load_error_message})
  83          exit 1
  84        end
  85        Radiant::Initializer.run(:set_load_path)
  86        Radiant::Initializer.run(:install_gem_spec_stubs)
  87        Rails::GemDependency.add_frozen_gem_path
  88      end
  89    end
  90 
  91    class VendorBoot < Boot
  92      def load_initializer
  93        $LOAD_PATH.unshift "#{RAILS_ROOT}/vendor/radiant/lib" 
  94        super
  95      end
  96          
  97      def load_error_message
  98        "Please verify that vendor/radiant contains a complete copy of the Radiant sources."
  99      end
 100    end
 101 
 102    class AppBoot < Boot
 103      def load_initializer
 104        $LOAD_PATH.unshift "#{RAILS_ROOT}/lib" 
 105        super
 106      end
 107 
 108      def load_error_message
 109        "Please verify that you have a complete copy of the Radiant sources."
 110      end
 111    end
 112 
 113    class GemBoot < Boot
 114      # The location and version of the radiant gem should be set in your Gemfile
 115      def load_error_message
 116        "Have you run `bundle install`?'."
 117      end
 118    end
 119  end
 120 
 121  # All that for this:
 122  Radiant.boot!