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!