diff options
author | José Valim <jose.valim@gmail.com> | 2009-06-27 21:27:21 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-06-27 21:27:21 +0200 |
commit | 85ff67ce4c0e95de9b855af7f7e7fbab7f7726de (patch) | |
tree | 3eb1914ed2ac7261405df22015fc4b33578bbe3c /railties/lib/rails | |
parent | e375819b76ac04bc60fd516b15bbe42c093eb547 (diff) | |
parent | 085db5e128ad4ad8fd042776722c78e194c6d0a4 (diff) | |
download | rails-85ff67ce4c0e95de9b855af7f7e7fbab7f7726de.tar.gz rails-85ff67ce4c0e95de9b855af7f7e7fbab7f7726de.tar.bz2 rails-85ff67ce4c0e95de9b855af7f7e7fbab7f7726de.zip |
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'railties/lib/rails')
-rw-r--r-- | railties/lib/rails/configuration.rb | 33 | ||||
-rw-r--r-- | railties/lib/rails/paths.rb | 120 |
2 files changed, 151 insertions, 2 deletions
diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index fdb071fc18..59132efe98 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -10,7 +10,7 @@ module Rails :log_path, :log_level, :logger, :preload_frameworks, :database_configuration_file, :cache_store, :time_zone, :view_path, :metals, :controller_paths, :routes_configuration_file, - :eager_load_paths, :dependency_loading + :eager_load_paths, :dependency_loading, :paths def initialize set_root_path! @@ -61,7 +61,36 @@ module Rails Pathname.new(RAILS_ROOT).realpath.to_s end - RAILS_ROOT.replace self.root_path + @paths = Rails::Application::Root.new(root_path) + @paths.app = "app" + @paths.app.metals = "app/metal" + @paths.app.models = "app/models" + @paths.app.controllers = "app/controllers" + @paths.app.helpers = "app/helpers" + @paths.app.services = "app/services" + @paths.lib = "lib" + @paths.vendor = "vendor" + @paths.vendor.plugins = "vendor/plugins" + @paths.cache = "tmp/cache" + @paths.config = "config" + @paths.config.locales = "config/locales" + @paths.config.environments = "config/environments" + + @paths.app.controllers.push *builtin_directories + + @paths.app.load_path! + @paths.app.metals.load_path! + @paths.app.models.eager_load! + @paths.app.controllers.eager_load! + @paths.app.helpers.eager_load! + @paths.app.services.load_path! + @paths.app.metals.eager_load! + @paths.lib.load_path! + @paths.vendor.load_path! + + @paths.config.environments.glob = "#{RAILS_ENV}.rb" + + RAILS_ROOT.replace root_path end # Enable threaded mode. Allows concurrent requests to controller actions and diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb new file mode 100644 index 0000000000..aada7d4a56 --- /dev/null +++ b/railties/lib/rails/paths.rb @@ -0,0 +1,120 @@ +require 'set' + +module Rails + class Application + module PathParent + def method_missing(id, *args) + name = id.to_s + + if name =~ /^(.*)=$/ + @children[$1] = Path.new(args.first, @root) + elsif path = @children[name] + path + else + super + end + end + end + + class Root + include PathParent + + attr_reader :path + def initialize(path) + raise unless path.is_a?(String) + + @children = {} + + # TODO: Move logic from set_root_path initializer + @path = File.expand_path(path) + @root = self + @load_once, @eager_load, @all_paths = [], [], [] + end + + def load_once + @load_once.uniq! + @load_once + end + + def eager_load + @eager_load.uniq! + @eager_load + end + + def all_paths + @all_paths.uniq! + @all_paths + end + + def load_paths + all_paths.map { |path| path.paths }.flatten + end + + def add_to_load_path + load_paths.reverse_each do |path| + $LOAD_PATH.unshift(path) if File.directory?(path) + end + end + end + + class Path + include PathParent + + attr_reader :path + attr_accessor :glob + + def initialize(path, root) + @children = {} + @root = root + @paths = [path].flatten + @glob = "**/*.rb" + end + + def push(path) + @paths.push path + end + + alias << push + + def unshift(path) + @paths.unshift path + end + + def load_once! + @load_once = true + @root.load_once.push *self.paths + end + + def load_once? + @load_once + end + + def eager_load! + @eager_load = true + @root.all_paths << self + @root.eager_load.push *self.paths + end + + def eager_load? + @eager_load + end + + def load_path! + @load_path = true + @root.all_paths << self + end + + def load_path? + @load_path + end + + def paths + @paths.map do |path| + path.index('/') == 0 ? path : File.join(@root.path, path) + end + end + + alias to_a paths + end + end +end
\ No newline at end of file |