Skip to content

Commit

Permalink
Added Rails.initialized? flag
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Jul 3, 2008
1 parent 8f640c3 commit 6c0edef
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
2 changes: 2 additions & 0 deletions railties/CHANGELOG
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,7 @@
*Edge* *Edge*


* Added Rails.initialized? flag [Josh Peek]

* Make rake test:uncommitted work with Git. [Tim Pope] * Make rake test:uncommitted work with Git. [Tim Pope]


* Added Thin support to script/server. #488 [Bob Klosinski] * Added Thin support to script/server. #488 [Bob Klosinski]
Expand Down
55 changes: 32 additions & 23 deletions railties/lib/initializer.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,27 +19,35 @@ class << self
def configuration def configuration
@@configuration @@configuration
end end

def configuration=(configuration) def configuration=(configuration)
@@configuration = configuration @@configuration = configuration
end end


def initialized?
@initialized || false
end

def initialized=(initialized)
@initialized ||= initialized
end

def logger def logger
RAILS_DEFAULT_LOGGER RAILS_DEFAULT_LOGGER
end end

def root def root
if defined?(RAILS_ROOT) if defined?(RAILS_ROOT)
RAILS_ROOT RAILS_ROOT
else else
nil nil
end end
end end

def env def env
ActiveSupport::StringInquirer.new(RAILS_ENV) ActiveSupport::StringInquirer.new(RAILS_ENV)
end end

def cache def cache
RAILS_CACHE RAILS_CACHE
end end
Expand All @@ -56,7 +64,7 @@ def public_path=(path)
@@public_path = path @@public_path = path
end end
end end

# The Initializer is responsible for processing the Rails configuration, such # The Initializer is responsible for processing the Rails configuration, such
# as setting the $LOAD_PATH, requiring the right frameworks, initializing # as setting the $LOAD_PATH, requiring the right frameworks, initializing
# logging, and more. It can be run either as a single command that'll just # logging, and more. It can be run either as a single command that'll just
Expand Down Expand Up @@ -145,7 +153,7 @@ def process
add_gem_load_paths add_gem_load_paths
load_gems load_gems
check_gem_dependencies check_gem_dependencies

load_application_initializers load_application_initializers


# the framework is now fully initialized # the framework is now fully initialized
Expand All @@ -158,8 +166,10 @@ def process
initialize_routing initialize_routing


# Observers are loaded after plugins in case Observers or observed models are modified by plugins. # Observers are loaded after plugins in case Observers or observed models are modified by plugins.

load_observers load_observers

# Flag initialized
Rails.initialized = true
end end


# Check for valid Ruby version # Check for valid Ruby version
Expand Down Expand Up @@ -297,12 +307,12 @@ def load_environment
silence_warnings do silence_warnings do
return if @environment_loaded return if @environment_loaded
@environment_loaded = true @environment_loaded = true

config = configuration config = configuration
constants = self.class.constants constants = self.class.constants

eval(IO.read(configuration.environment_path), binding, configuration.environment_path) eval(IO.read(configuration.environment_path), binding, configuration.environment_path)

(self.class.constants - constants).each do |const| (self.class.constants - constants).each do |const|
Object.const_set(const, self.class.const_get(const)) Object.const_set(const, self.class.const_get(const))
end end
Expand Down Expand Up @@ -390,7 +400,7 @@ def initialize_framework_logging
for framework in ([ :active_record, :action_controller, :action_mailer ] & configuration.frameworks) for framework in ([ :active_record, :action_controller, :action_mailer ] & configuration.frameworks)
framework.to_s.camelize.constantize.const_get("Base").logger ||= RAILS_DEFAULT_LOGGER framework.to_s.camelize.constantize.const_get("Base").logger ||= RAILS_DEFAULT_LOGGER
end end

RAILS_CACHE.logger ||= RAILS_DEFAULT_LOGGER RAILS_CACHE.logger ||= RAILS_DEFAULT_LOGGER
end end


Expand Down Expand Up @@ -486,7 +496,6 @@ def prepare_dispatcher
Dispatcher.define_dispatcher_callbacks(configuration.cache_classes) Dispatcher.define_dispatcher_callbacks(configuration.cache_classes)
Dispatcher.new(RAILS_DEFAULT_LOGGER).send :run_callbacks, :prepare_dispatch Dispatcher.new(RAILS_DEFAULT_LOGGER).send :run_callbacks, :prepare_dispatch
end end

end end


# The Configuration class holds all the parameters for the Initializer and # The Configuration class holds all the parameters for the Initializer and
Expand Down Expand Up @@ -531,7 +540,7 @@ class Configuration
# The path to the database configuration file to use. (Defaults to # The path to the database configuration file to use. (Defaults to
# <tt>config/database.yml</tt>.) # <tt>config/database.yml</tt>.)
attr_accessor :database_configuration_file attr_accessor :database_configuration_file

# The path to the routes configuration file to use. (Defaults to # The path to the routes configuration file to use. (Defaults to
# <tt>config/routes.rb</tt>.) # <tt>config/routes.rb</tt>.)
attr_accessor :routes_configuration_file attr_accessor :routes_configuration_file
Expand Down Expand Up @@ -597,7 +606,7 @@ def plugins=(plugins)
# a sub class would have access to fine grained modification of the loading behavior. See # a sub class would have access to fine grained modification of the loading behavior. See
# the implementation of Rails::Plugin::Loader for more details. # the implementation of Rails::Plugin::Loader for more details.
attr_accessor :plugin_loader attr_accessor :plugin_loader

# Enables or disables plugin reloading. You can get around this setting per plugin. # Enables or disables plugin reloading. You can get around this setting per plugin.
# If <tt>reload_plugins?</tt> is false, add this to your plugin's <tt>init.rb</tt> # If <tt>reload_plugins?</tt> is false, add this to your plugin's <tt>init.rb</tt>
# to make it reloadable: # to make it reloadable:
Expand Down Expand Up @@ -634,7 +643,7 @@ def reload_plugins?
def gem(name, options = {}) def gem(name, options = {})
@gems << Rails::GemDependency.new(name, options) @gems << Rails::GemDependency.new(name, options)
end end

# Deprecated options: # Deprecated options:
def breakpoint_server(_ = nil) def breakpoint_server(_ = nil)
$stderr.puts %( $stderr.puts %(
Expand Down Expand Up @@ -693,7 +702,7 @@ def set_root_path!
else else
Pathname.new(::RAILS_ROOT).realpath.to_s Pathname.new(::RAILS_ROOT).realpath.to_s
end end

Object.const_set(:RELATIVE_RAILS_ROOT, ::RAILS_ROOT.dup) unless defined?(::RELATIVE_RAILS_ROOT) Object.const_set(:RELATIVE_RAILS_ROOT, ::RAILS_ROOT.dup) unless defined?(::RELATIVE_RAILS_ROOT)
::RAILS_ROOT.replace @root_path ::RAILS_ROOT.replace @root_path
end end
Expand Down Expand Up @@ -734,7 +743,7 @@ def after_initialize_blocks
# #
# See Dispatcher#to_prepare. # See Dispatcher#to_prepare.
def to_prepare(&callback) def to_prepare(&callback)
after_initialize do after_initialize do
require 'dispatcher' unless defined?(::Dispatcher) require 'dispatcher' unless defined?(::Dispatcher)
Dispatcher.to_prepare(&callback) Dispatcher.to_prepare(&callback)
end end
Expand All @@ -748,11 +757,11 @@ def builtin_directories
def framework_paths def framework_paths
paths = %w(railties railties/lib activesupport/lib) paths = %w(railties railties/lib activesupport/lib)
paths << 'actionpack/lib' if frameworks.include? :action_controller or frameworks.include? :action_view paths << 'actionpack/lib' if frameworks.include? :action_controller or frameworks.include? :action_view

[:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework| [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include? framework paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include? framework
end end

paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) } paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
end end


Expand All @@ -767,7 +776,7 @@ def default_frameworks


def default_load_paths def default_load_paths
paths = [] paths = []

# Add the old mock paths only if the directories exists # Add the old mock paths only if the directories exists
paths.concat(Dir["#{root_path}/test/mocks/#{environment}"]) if File.exists?("#{root_path}/test/mocks/#{environment}") paths.concat(Dir["#{root_path}/test/mocks/#{environment}"]) if File.exists?("#{root_path}/test/mocks/#{environment}")


Expand Down Expand Up @@ -853,15 +862,15 @@ def default_plugin_locators
def default_plugin_loader def default_plugin_loader
Plugin::Loader Plugin::Loader
end end

def default_cache_store def default_cache_store
if File.exist?("#{root_path}/tmp/cache/") if File.exist?("#{root_path}/tmp/cache/")
[ :file_store, "#{root_path}/tmp/cache/" ] [ :file_store, "#{root_path}/tmp/cache/" ]
else else
:memory_store :memory_store
end end
end end

def default_gems def default_gems
[] []
end end
Expand Down

0 comments on commit 6c0edef

Please sign in to comment.