| 1 |
require 'logger' |
|---|
| 2 |
require 'set' |
|---|
| 3 |
require 'pathname' |
|---|
| 4 |
|
|---|
| 5 |
$LOAD_PATH.unshift File.dirname(__FILE__) |
|---|
| 6 |
require 'railties_path' |
|---|
| 7 |
require 'rails/version' |
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV) |
|---|
| 11 |
|
|---|
| 12 |
module Rails |
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
class Initializer |
|---|
| 30 |
|
|---|
| 31 |
attr_reader :configuration |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
attr_reader :loaded_plugins |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
def self.run(command = :process, configuration = Configuration.new) |
|---|
| 45 |
yield configuration if block_given? |
|---|
| 46 |
initializer = new configuration |
|---|
| 47 |
initializer.send(command) |
|---|
| 48 |
initializer |
|---|
| 49 |
end |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
def initialize(configuration) |
|---|
| 54 |
@configuration = configuration |
|---|
| 55 |
@loaded_plugins = [] |
|---|
| 56 |
end |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
def process |
|---|
| 83 |
check_ruby_version |
|---|
| 84 |
set_load_path |
|---|
| 85 |
set_connection_adapters |
|---|
| 86 |
|
|---|
| 87 |
require_frameworks |
|---|
| 88 |
set_autoload_paths |
|---|
| 89 |
load_environment |
|---|
| 90 |
|
|---|
| 91 |
initialize_encoding |
|---|
| 92 |
initialize_database |
|---|
| 93 |
initialize_logger |
|---|
| 94 |
initialize_framework_logging |
|---|
| 95 |
initialize_framework_views |
|---|
| 96 |
initialize_dependency_mechanism |
|---|
| 97 |
initialize_breakpoints |
|---|
| 98 |
initialize_whiny_nils |
|---|
| 99 |
initialize_temporary_directories |
|---|
| 100 |
initialize_framework_settings |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
load_environment |
|---|
| 106 |
|
|---|
| 107 |
add_support_load_paths |
|---|
| 108 |
|
|---|
| 109 |
load_plugins |
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
load_observers |
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
initialize_routing |
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
after_initialize |
|---|
| 119 |
end |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
def check_ruby_version |
|---|
| 125 |
require 'ruby_version_check' |
|---|
| 126 |
end |
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
def set_load_path |
|---|
| 131 |
load_paths = configuration.load_paths + configuration.framework_paths |
|---|
| 132 |
load_paths.reverse_each { |dir| $LOAD_PATH.unshift(dir) if File.directory?(dir) } |
|---|
| 133 |
$LOAD_PATH.uniq! |
|---|
| 134 |
end |
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
def set_autoload_paths |
|---|
| 139 |
Dependencies.load_paths = configuration.load_paths.uniq |
|---|
| 140 |
Dependencies.load_once_paths = configuration.load_once_paths.uniq |
|---|
| 141 |
|
|---|
| 142 |
extra = Dependencies.load_once_paths - Dependencies.load_paths |
|---|
| 143 |
unless extra.empty? |
|---|
| 144 |
abort <<-end_error |
|---|
| 145 |
load_once_paths must be a subset of the load_paths. |
|---|
| 146 |
Extra items in load_once_paths: |
|---|
| 147 |
end_error |
|---|
| 148 |
end |
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
configuration.load_once_paths.freeze |
|---|
| 152 |
end |
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
def set_connection_adapters |
|---|
| 159 |
Object.const_set("RAILS_CONNECTION_ADAPTERS", configuration.connection_adapters) if configuration.connection_adapters |
|---|
| 160 |
end |
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
def require_frameworks |
|---|
| 166 |
configuration.frameworks.each { |framework| require(framework.to_s) } |
|---|
| 167 |
end |
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
def add_support_load_paths |
|---|
| 171 |
end |
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
def load_plugins |
|---|
| 187 |
if configuration.plugins.nil? |
|---|
| 188 |
|
|---|
| 189 |
find_plugins(configuration.plugin_paths).sort.each { |path| load_plugin path } |
|---|
| 190 |
elsif !configuration.plugins.empty? |
|---|
| 191 |
|
|---|
| 192 |
plugin_paths = find_plugins(configuration.plugin_paths) |
|---|
| 193 |
configuration.plugins.each do |name| |
|---|
| 194 |
path = plugin_paths.find { |p| File.basename(p) == name } |
|---|
| 195 |
raise(LoadError, "Cannot find the plugin '#{name}'!") if path.nil? |
|---|
| 196 |
load_plugin path |
|---|
| 197 |
end |
|---|
| 198 |
end |
|---|
| 199 |
$LOAD_PATH.uniq! |
|---|
| 200 |
end |
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
def load_environment |
|---|
| 205 |
silence_warnings do |
|---|
| 206 |
config = configuration |
|---|
| 207 |
constants = self.class.constants |
|---|
| 208 |
|
|---|
| 209 |
eval(IO.read(configuration.environment_path), binding, configuration.environment_path) |
|---|
| 210 |
|
|---|
| 211 |
(self.class.constants - constants).each do |const| |
|---|
| 212 |
Object.const_set(const, self.class.const_get(const)) |
|---|
| 213 |
end |
|---|
| 214 |
end |
|---|
| 215 |
end |
|---|
| 216 |
|
|---|
| 217 |
def load_observers |
|---|
| 218 |
ActiveRecord::Base.instantiate_observers |
|---|
| 219 |
end |
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
def initialize_encoding |
|---|
| 225 |
$KCODE='u' |
|---|
| 226 |
end |
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
def initialize_database |
|---|
| 233 |
return unless configuration.frameworks.include?(:active_record) |
|---|
| 234 |
ActiveRecord::Base.configurations = configuration.database_configuration |
|---|
| 235 |
ActiveRecord::Base.establish_connection |
|---|
| 236 |
end |
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
def initialize_logger |
|---|
| 247 |
|
|---|
| 248 |
return if defined?(RAILS_DEFAULT_LOGGER) |
|---|
| 249 |
|
|---|
| 250 |
unless logger = configuration.logger |
|---|
| 251 |
begin |
|---|
| 252 |
logger = Logger.new(configuration.log_path) |
|---|
| 253 |
logger.level = Logger.const_get(configuration.log_level.to_s.upcase) |
|---|
| 254 |
rescue StandardError |
|---|
| 255 |
logger = Logger.new(STDERR) |
|---|
| 256 |
logger.level = Logger::WARN |
|---|
| 257 |
logger.warn( |
|---|
| 258 |
"Rails Error: Unable to access log file. Please ensure that #{configuration.log_path} exists and is chmod 0666. " + |
|---|
| 259 |
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed." |
|---|
| 260 |
) |
|---|
| 261 |
end |
|---|
| 262 |
end |
|---|
| 263 |
|
|---|
| 264 |
silence_warnings { Object.const_set "RAILS_DEFAULT_LOGGER", logger } |
|---|
| 265 |
end |
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 |
|
|---|
| 271 |
def initialize_framework_logging |
|---|
| 272 |
for framework in ([ :active_record, :action_controller, :action_mailer ] & configuration.frameworks) |
|---|
| 273 |
framework.to_s.camelize.constantize.const_get("Base").logger ||= RAILS_DEFAULT_LOGGER |
|---|
| 274 |
end |
|---|
| 275 |
end |
|---|
| 276 |
|
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 |
def initialize_framework_views |
|---|
| 282 |
for framework in ([ :action_controller, :action_mailer ] & configuration.frameworks) |
|---|
| 283 |
framework.to_s.camelize.constantize.const_get("Base").template_root ||= configuration.view_path |
|---|
| 284 |
end |
|---|
| 285 |
end |
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
|
|---|
| 289 |
|
|---|
| 290 |
def initialize_routing |
|---|
| 291 |
return unless configuration.frameworks.include?(:action_controller) |
|---|
| 292 |
ActionController::Routing.controller_paths = configuration.controller_paths |
|---|
| 293 |
ActionController::Routing::Routes.reload |
|---|
| 294 |
end |
|---|
| 295 |
|
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
def initialize_dependency_mechanism |
|---|
| 299 |
Dependencies.mechanism = configuration.cache_classes ? :require : :load |
|---|
| 300 |
end |
|---|
| 301 |
|
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 |
def initialize_breakpoints |
|---|
| 305 |
silence_warnings { Object.const_set("BREAKPOINT_SERVER_PORT", 42531) if configuration.breakpoint_server } |
|---|
| 306 |
end |
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 |
def initialize_whiny_nils |
|---|
| 311 |
require('active_support/whiny_nil') if configuration.whiny_nils |
|---|
| 312 |
end |
|---|
| 313 |
|
|---|
| 314 |
def initialize_temporary_directories |
|---|
| 315 |
if configuration.frameworks.include?(:action_controller) |
|---|
| 316 |
session_path = "#{configuration.root_path}/tmp/sessions/" |
|---|
| 317 |
ActionController::Base.session_options[:tmpdir] = File.exist?(session_path) ? session_path : Dir::tmpdir |
|---|
| 318 |
|
|---|
| 319 |
cache_path = "#{configuration.root_path}/tmp/cache/" |
|---|
| 320 |
if File.exist?(cache_path) |
|---|
| 321 |
ActionController::Base.fragment_cache_store = :file_store, cache_path |
|---|
| 322 |
end |
|---|
| 323 |
end |
|---|
| 324 |
end |
|---|
| 325 |
|
|---|
| 326 |
|
|---|
| 327 |
|
|---|
| 328 |
|
|---|
| 329 |
def initialize_framework_settings |
|---|
| 330 |
configuration.frameworks.each do |framework| |
|---|
| 331 |
base_class = framework.to_s.camelize.constantize.const_get("Base") |
|---|
| 332 |
|
|---|
| 333 |
configuration.send(framework).each do |setting, value| |
|---|
| 334 |
base_class.send("#{setting}=", value) |
|---|
| 335 |
end |
|---|
| 336 |
end |
|---|
| 337 |
end |
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 340 |
def after_initialize |
|---|
| 341 |
configuration.after_initialize_block.call if configuration.after_initialize_block |
|---|
| 342 |
end |
|---|
| 343 |
|
|---|
| 344 |
protected |
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
def find_plugins(*base_paths) |
|---|
| 350 |
base_paths.flatten.inject([]) do |plugins, base_path| |
|---|
| 351 |
Dir.glob(File.join(base_path, '*')).each do |path| |
|---|
| 352 |
if plugin_path?(path) |
|---|
| 353 |
plugins << path if plugin_enabled?(path) |
|---|
| 354 |
elsif File.directory?(path) |
|---|
| 355 |
plugins += find_plugins(path) |
|---|
| 356 |
end |
|---|
| 357 |
end |
|---|
| 358 |
plugins |
|---|
| 359 |
end |
|---|
| 360 |
end |
|---|
| 361 |
|
|---|
| 362 |
def plugin_path?(path) |
|---|
| 363 |
File.directory?(path) and (File.directory?(File.join(path, 'lib')) or File.file?(File.join(path, 'init.rb'))) |
|---|
| 364 |
end |
|---|
| 365 |
|
|---|
| 366 |
def plugin_enabled?(path) |
|---|
| 367 |
configuration.plugins.nil? || configuration.plugins.include?(File.basename(path)) |
|---|
| 368 |
end |
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 |
|
|---|
| 375 |
|
|---|
| 376 |
|
|---|
| 377 |
|
|---|
| 378 |
|
|---|
| 379 |
def load_plugin(directory) |
|---|
| 380 |
name = File.basename(directory) |
|---|
| 381 |
return false if loaded_plugins.include?(name) |
|---|
| 382 |
|
|---|
| 383 |
|
|---|
| 384 |
raise LoadError, "No such plugin: #{directory}" unless plugin_path?(directory) |
|---|
| 385 |
|
|---|
| 386 |
lib_path = File.join(directory, 'lib') |
|---|
| 387 |
init_path = File.join(directory, 'init.rb') |
|---|
| 388 |
has_lib = File.directory?(lib_path) |
|---|
| 389 |
has_init = File.file?(init_path) |
|---|
| 390 |
|
|---|
| 391 |
|
|---|
| 392 |
|
|---|
| 393 |
if has_lib |
|---|
| 394 |
application_lib_index = $LOAD_PATH.index(File.join(RAILS_ROOT, "lib")) || 0 |
|---|
| 395 |
$LOAD_PATH.insert(application_lib_index + 1, lib_path) |
|---|
| 396 |
Dependencies.load_paths << lib_path |
|---|
| 397 |
Dependencies.load_once_paths << lib_path |
|---|
| 398 |
end |
|---|
| 399 |
|
|---|
| 400 |
|
|---|
| 401 |
config = configuration |
|---|
| 402 |
|
|---|
| 403 |
|
|---|
| 404 |
loaded_plugins << name |
|---|
| 405 |
|
|---|
| 406 |
|
|---|
| 407 |
silence_warnings { eval(IO.read(init_path), binding, init_path) } if has_init |
|---|
| 408 |
|
|---|
| 409 |
true |
|---|
| 410 |
end |
|---|
| 411 |
end |
|---|
| 412 |
|
|---|
| 413 |
|
|---|
| 414 |
|
|---|
| 415 |
|
|---|
| 416 |
|
|---|
| 417 |
|
|---|
| 418 |
|
|---|
| 419 |
|
|---|
| 420 |
|
|---|
| 421 |
|
|---|
| 422 |
class Configuration |
|---|
| 423 |
|
|---|
| 424 |
attr_reader :root_path |
|---|
| 425 |
|
|---|
| 426 |
|
|---|
| 427 |
attr_accessor :action_controller |
|---|
| 428 |
|
|---|
| 429 |
|
|---|
| 430 |
attr_accessor :action_mailer |
|---|
| 431 |
|
|---|
| 432 |
|
|---|
| 433 |
attr_accessor :action_view |
|---|
| 434 |
|
|---|
| 435 |
|
|---|
| 436 |
attr_accessor :action_web_service |
|---|
| 437 |
|
|---|
| 438 |
|
|---|
| 439 |
attr_accessor :active_record |
|---|
| 440 |
|
|---|
| 441 |
|
|---|
| 442 |
attr_accessor :breakpoint_server |
|---|
| 443 |
|
|---|
| 444 |
|
|---|
| 445 |
|
|---|
| 446 |
attr_accessor :cache_classes |
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
attr_accessor :connection_adapters |
|---|
| 452 |
|
|---|
| 453 |
|
|---|
| 454 |
|
|---|
| 455 |
attr_accessor :controller_paths |
|---|
| 456 |
|
|---|
| 457 |
|
|---|
| 458 |
|
|---|
| 459 |
attr_accessor :database_configuration_file |
|---|
| 460 |
|
|---|
| 461 |
|
|---|
| 462 |
|
|---|
| 463 |
|
|---|
| 464 |
|
|---|
| 465 |
attr_accessor :frameworks |
|---|
| 466 |
|
|---|
| 467 |
|
|---|
| 468 |
|
|---|
| 469 |
attr_accessor :load_paths |
|---|
| 470 |
|
|---|
| 471 |
|
|---|
| 472 |
|
|---|
| 473 |
attr_accessor :load_once_paths |
|---|
| 474 |
|
|---|
| 475 |
|
|---|
| 476 |
|
|---|
| 477 |
|
|---|
| 478 |
attr_accessor :log_level |
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 |
|
|---|
| 482 |
attr_accessor :log_path |
|---|
| 483 |
|
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 |
|
|---|
| 487 |
|
|---|
| 488 |
attr_accessor :logger |
|---|
| 489 |
|
|---|
| 490 |
|
|---|
| 491 |
attr_accessor :view_path |
|---|
| 492 |
|
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 |
attr_accessor :whiny_nils |
|---|
| 496 |
|
|---|
| 497 |
|
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 |
attr_accessor :plugins |
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 |
|
|---|
| 504 |
attr_accessor :plugin_paths |
|---|
| 505 |
|
|---|
| 506 |
|
|---|
| 507 |
|
|---|
| 508 |
def initialize |
|---|
| 509 |
set_root_path! |
|---|
| 510 |
|
|---|
| 511 |
self.frameworks = default_frameworks |
|---|
| 512 |
self.load_paths = default_load_paths |
|---|
| 513 |
self.load_once_paths = default_load_once_paths |
|---|
| 514 |
self.log_path = default_log_path |
|---|
| 515 |
self.log_level = default_log_level |
|---|
| 516 |
self.view_path = default_view_path |
|---|
| 517 |
self.controller_paths = default_controller_paths |
|---|
| 518 |
self.cache_classes = default_cache_classes |
|---|
| 519 |
self.breakpoint_server = default_breakpoint_server |
|---|
| 520 |
self.whiny_nils = default_whiny_nils |
|---|
| 521 |
self.plugins = default_plugins |
|---|
| 522 |
self.plugin_paths = default_plugin_paths |
|---|
| 523 |
self.database_configuration_file = default_database_configuration_file |
|---|
| 524 |
|
|---|
| 525 |
for framework in default_frameworks |
|---|
| 526 |
self.send("#{framework}=", Rails::OrderedOptions.new) |
|---|
| 527 |
end |
|---|
| 528 |
end |
|---|
| 529 |
|
|---|
| 530 |
|
|---|
| 531 |
def set_root_path! |
|---|
| 532 |
raise 'RAILS_ROOT is not set' unless defined?(::RAILS_ROOT) |
|---|
| 533 |
raise 'RAILS_ROOT is not a directory' unless File.directory?(::RAILS_ROOT) |
|---|
| 534 |
|
|---|
| 535 |
@root_path = |
|---|
| 536 |
|
|---|
| 537 |
|
|---|
| 538 |
if RUBY_PLATFORM =~ /(:?mswin|mingw)/ |
|---|
| 539 |
File.expand_path(::RAILS_ROOT) |
|---|
| 540 |
|
|---|
| 541 |
|
|---|
| 542 |
else |
|---|
| 543 |
Pathname.new(::RAILS_ROOT).realpath.to_s |
|---|
| 544 |
end |
|---|
| 545 |
end |
|---|
| 546 |
|
|---|
| 547 |
|
|---|
| 548 |
|
|---|
| 549 |
|
|---|
| 550 |
def database_configuration |
|---|
| 551 |
YAML::load(ERB.new(IO.read(database_configuration_file)).result) |
|---|
| 552 |
end |
|---|
| 553 |
|
|---|
| 554 |
|
|---|
| 555 |
|
|---|
| 556 |
def environment_path |
|---|
| 557 |
"#{root_path}/config/environments/#{environment}.rb" |
|---|
| 558 |
end |
|---|
| 559 |
|
|---|
| 560 |
|
|---|
| 561 |
|
|---|
| 562 |
def environment |
|---|
| 563 |
::RAILS_ENV |
|---|
| 564 |
end |
|---|
| 565 |
|
|---|
| 566 |
|
|---|
| 567 |
|
|---|
| 568 |
|
|---|
| 569 |
def after_initialize(&after_initialize_block) |
|---|
| 570 |
@after_initialize_block = after_initialize_block |
|---|
| 571 |
end |
|---|
| 572 |
|
|---|
| 573 |
|
|---|
| 574 |
def after_initialize_block |
|---|
| 575 |
@after_initialize_block |
|---|
| 576 |
end |
|---|
| 577 |
|
|---|
| 578 |
|
|---|
| 579 |
|
|---|
| 580 |
|
|---|
| 581 |
|
|---|
| 582 |
def to_prepare(&callback) |
|---|
| 583 |
require 'dispatcher' unless defined?(::Dispatcher) |
|---|
| 584 |
Dispatcher.to_prepare(&callback) |
|---|
| 585 |
end |
|---|
| 586 |
|
|---|
| 587 |
def builtin_directories |
|---|
| 588 |
|
|---|
| 589 |
(environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : [] |
|---|
| 590 |
end |
|---|
| 591 |
|
|---|
| 592 |
def framework_paths |
|---|
| 593 |
|
|---|
| 594 |
%w( |
|---|
| 595 |
railties |
|---|
| 596 |
railties/lib |
|---|
| 597 |
actionpack/lib |
|---|
| 598 |
activesupport/lib |
|---|
| 599 |
activerecord/lib |
|---|
| 600 |
actionmailer/lib |
|---|
| 601 |
actionwebservice/lib |
|---|
| 602 |
).map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) } |
|---|
| 603 |
end |
|---|
| 604 |
|
|---|
| 605 |
private |
|---|
| 606 |
def framework_root_path |
|---|
| 607 |
defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root_path}/vendor/rails" |
|---|
| 608 |
end |
|---|
| 609 |
|
|---|
| 610 |
def default_frameworks |
|---|
| 611 |
[ :active_record, :action_controller, :action_view, :action_mailer, :action_web_service ] |
|---|
| 612 |
end |
|---|
| 613 |
|
|---|
| 614 |
def default_load_paths |
|---|
| 615 |
paths = ["#{root_path}/test/mocks/#{environment}"] |
|---|
| 616 |
|
|---|
| 617 |
|
|---|
| 618 |
paths.concat(Dir["#{root_path}/app/controllers/"]) |
|---|
| 619 |
|
|---|
| 620 |
|
|---|
| 621 |
paths.concat(Dir["#{root_path}/components/[_a-z]*"]) |
|---|
| 622 |
|
|---|
| 623 |
|
|---|
| 624 |
paths.concat %w( |
|---|
| 625 |
app |
|---|
| 626 |
app/models |
|---|
| 627 |
app/controllers |
|---|
| 628 |
app/helpers |
|---|
| 629 |
app/services |
|---|
| 630 |
app/apis |
|---|
| 631 |
components |
|---|
| 632 |
config |
|---|
| 633 |
lib |
|---|
| 634 |
  |
|---|