aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/rails-2.1.0/railties/lib/rails
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/rails-2.1.0/railties/lib/rails')
-rw-r--r--vendor/rails-2.1.0/railties/lib/rails/gem_builder.rb21
-rw-r--r--vendor/rails-2.1.0/railties/lib/rails/gem_dependency.rb124
-rw-r--r--vendor/rails-2.1.0/railties/lib/rails/mongrel_server/commands.rb342
-rw-r--r--vendor/rails-2.1.0/railties/lib/rails/mongrel_server/handler.rb55
-rw-r--r--vendor/rails-2.1.0/railties/lib/rails/plugin.rb115
-rw-r--r--vendor/rails-2.1.0/railties/lib/rails/plugin/loader.rb152
-rw-r--r--vendor/rails-2.1.0/railties/lib/rails/plugin/locator.rb99
-rw-r--r--vendor/rails-2.1.0/railties/lib/rails/version.rb9
8 files changed, 0 insertions, 917 deletions
diff --git a/vendor/rails-2.1.0/railties/lib/rails/gem_builder.rb b/vendor/rails-2.1.0/railties/lib/rails/gem_builder.rb
deleted file mode 100644
index e7e06d000..000000000
--- a/vendor/rails-2.1.0/railties/lib/rails/gem_builder.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require 'rubygems'
-require 'rubygems/installer'
-
-module Rails
-
- # this class hijacks the functionality of Gem::Installer by overloading its
- # initializer to only provide the information needed by
- # Gem::Installer#build_extensions (which happens to be what we have)
- class GemBuilder < Gem::Installer
-
- def initialize(spec, gem_dir)
- @spec = spec
- @gem_dir = gem_dir
- end
-
- # silence the underlying builder
- def say(message)
- end
-
- end
-end \ No newline at end of file
diff --git a/vendor/rails-2.1.0/railties/lib/rails/gem_dependency.rb b/vendor/rails-2.1.0/railties/lib/rails/gem_dependency.rb
deleted file mode 100644
index 9f088a18d..000000000
--- a/vendor/rails-2.1.0/railties/lib/rails/gem_dependency.rb
+++ /dev/null
@@ -1,124 +0,0 @@
-module Rails
- class GemDependency
- attr_accessor :name, :requirement, :version, :lib, :source
-
- def self.unpacked_path
- @unpacked_path ||= File.join(RAILS_ROOT, 'vendor', 'gems')
- end
-
- def initialize(name, options = {})
- require 'rubygems' unless Object.const_defined?(:Gem)
-
- if options[:requirement]
- @requirement = options[:requirement]
- elsif options[:version]
- @requirement = Gem::Requirement.create(options[:version])
- end
-
- @version = @requirement.instance_variable_get("@requirements").first.last if @requirement
- @name = name.to_s
- @lib = options[:lib]
- @source = options[:source]
- @loaded = @frozen = @load_paths_added = false
- @unpack_directory = nil
- end
-
- def add_load_paths
- return if @loaded || @load_paths_added
- unpacked_paths = Dir[File.join(self.class.unpacked_path, "#{@name}-#{@version || "*"}")]
- if unpacked_paths.empty?
- args = [@name]
- args << @requirement.to_s if @requirement
- gem *args
- else
- $LOAD_PATH.unshift File.join(unpacked_paths.first, 'lib')
- ext = File.join(unpacked_paths.first, 'ext')
- $LOAD_PATH.unshift(ext) if File.exist?(ext)
- @frozen = true
- end
- @load_paths_added = true
- rescue Gem::LoadError
- end
-
- def dependencies
- all_dependencies = specification.dependencies.map do |dependency|
- GemDependency.new(dependency.name, :requirement => dependency.version_requirements)
- end
- all_dependencies += all_dependencies.map(&:dependencies).flatten
- all_dependencies.uniq
- end
-
- def gem_dir(base_directory)
- File.join(base_directory, specification.full_name)
- end
-
- def load
- return if @loaded || @load_paths_added == false
- require(@lib || @name)
- @loaded = true
- rescue LoadError
- puts $!.to_s
- $!.backtrace.each { |b| puts b }
- end
-
- def frozen?
- @frozen
- end
-
- def loaded?
- @loaded
- end
-
- def load_paths_added?
- @load_paths_added
- end
-
- def install
- cmd = "#{gem_command} #{install_command.join(' ')}"
- puts cmd
- puts %x(#{cmd})
- end
-
- def unpack_to(directory)
- FileUtils.mkdir_p directory
- Dir.chdir directory do
- Gem::GemRunner.new.run(unpack_command)
- end
-
- # copy the gem's specification into GEMDIR/.specification so that
- # we can access information about the gem on deployment systems
- # without having the gem installed
- spec_filename = File.join(gem_dir(directory), '.specification')
- File.open(spec_filename, 'w') do |file|
- file.puts specification.to_yaml
- end
- end
-
- def ==(other)
- self.name == other.name && self.requirement == other.requirement
- end
-
-private ###################################################################
-
- def specification
- @spec ||= Gem.source_index.search(Gem::Dependency.new(@name, @requirement)).sort_by { |s| s.version }.last
- end
-
- def gem_command
- RUBY_PLATFORM =~ /win32/ ? 'gem.bat' : 'gem'
- end
-
- def install_command
- cmd = %w(install) << @name
- cmd << "--version" << %("#{@requirement.to_s}") if @requirement
- cmd << "--source" << @source if @source
- cmd
- end
-
- def unpack_command
- cmd = %w(unpack) << @name
- cmd << "--version" << "#{@requirement.to_s}" if @requirement
- cmd
- end
- end
-end \ No newline at end of file
diff --git a/vendor/rails-2.1.0/railties/lib/rails/mongrel_server/commands.rb b/vendor/rails-2.1.0/railties/lib/rails/mongrel_server/commands.rb
deleted file mode 100644
index 0a92f418a..000000000
--- a/vendor/rails-2.1.0/railties/lib/rails/mongrel_server/commands.rb
+++ /dev/null
@@ -1,342 +0,0 @@
-# Copyright (c) 2005 Zed A. Shaw
-# You can redistribute it and/or modify it under the same terms as Ruby.
-#
-# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
-# for more information.
-
-require 'optparse'
-require 'yaml'
-require 'etc'
-
-require 'mongrel'
-require 'rails/mongrel_server/handler'
-
-module Rails
- module MongrelServer
- def self.send_signal(signal, pid_file)
- pid = open(pid_file).read.to_i
- print "Sending #{signal} to Mongrel at PID #{pid}..."
- begin
- Process.kill(signal, pid)
- rescue Errno::ESRCH
- puts "Process does not exist. Not running."
- end
-
- puts "Done."
- end
-
- class RailsConfigurator < Mongrel::Configurator
- def setup_mime_types
- mime = {}
-
- if defaults[:mime_map]
- Mongrel.log("Loading additional MIME types from #{defaults[:mime_map]}")
- mime = load_mime_map(defaults[:mime_map], mime)
- end
-
- mime.each {|k,v| Mongrel::DirHandler::add_mime_type(k,v) }
- end
-
- def mount_rails(prefix)
- ENV['RAILS_ENV'] = defaults[:environment]
- ::RAILS_ENV.replace(defaults[:environment]) if defined?(::RAILS_ENV)
-
- env_location = "#{defaults[:cwd]}/config/environment"
- require env_location
-
- ActionController::AbstractRequest.relative_url_root = defaults[:prefix]
- uri prefix, :handler => Rails::MongrelServer::RailsHandler.new
- end
- end
-
- class Start < GemPlugin::Plugin "/commands"
- include Mongrel::Command::Base
-
- def configure
- options [
- ["-e", "--environment ENV", "Rails environment to run as", :@environment, ENV['RAILS_ENV'] || "development"],
- ["-d", "--daemonize", "Run daemonized in the background", :@daemon, false],
- ['-p', '--port PORT', "Which port to bind to", :@port, 3000],
- ['-a', '--address ADDR', "Address to bind to", :@address, "0.0.0.0"],
- ['-l', '--log FILE', "Where to write log messages", :@log_file, "log/mongrel.log"],
- ['-P', '--pid FILE', "Where to write the PID", :@pid_file, "tmp/pids/mongrel.pid"],
- ['-n', '--num-procs INT', "Number of processors active before clients denied", :@num_procs, 1024],
- ['-o', '--timeout TIME', "Time to wait (in seconds) before killing a stalled thread", :@timeout, 60],
- ['-t', '--throttle TIME', "Time to pause (in hundredths of a second) between accepting clients", :@throttle, 0],
- ['-m', '--mime PATH', "A YAML file that lists additional MIME types", :@mime_map, nil],
- ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, RAILS_ROOT],
- ['-r', '--root PATH', "Set the document root (default 'public')", :@docroot, "public"],
- ['-B', '--debug', "Enable debugging mode", :@debug, false],
- ['-C', '--config PATH', "Use a config file", :@config_file, nil],
- ['-S', '--script PATH', "Load the given file as an extra config script", :@config_script, nil],
- ['-G', '--generate PATH', "Generate a config file for use with -C", :@generate, nil],
- ['', '--user USER', "User to run as", :@user, nil],
- ['', '--group GROUP', "Group to run as", :@group, nil],
- ['', '--prefix PATH', "URL prefix for Rails app", :@prefix, nil],
-
- ['-b', '--binding ADDR', "Address to bind to (deprecated, use -a)", :@address, "0.0.0.0"],
- ['-u', '--debugger', "Enable debugging mode (deprecated, use -B)", :@debug, false]
- ]
- end
-
- def validate
- if @config_file
- valid_exists?(@config_file, "Config file not there: #@config_file")
- return false unless @valid
- @config_file = File.expand_path(@config_file)
- load_config
- return false unless @valid
- end
-
- @cwd = File.expand_path(@cwd)
- valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd"
-
- # Change there to start, then we'll have to come back after daemonize
- Dir.chdir(@cwd)
-
- valid?(@prefix[0] == ?/ && @prefix[-1] != ?/, "Prefix must begin with / and not end in /") if @prefix
- valid_dir? File.dirname(@log_file), "Path to log file not valid: #@log_file"
- valid_dir? File.dirname(@pid_file), "Path to pid file not valid: #@pid_file"
- valid_dir? @docroot, "Path to docroot not valid: #@docroot"
- valid_exists? @mime_map, "MIME mapping file does not exist: #@mime_map" if @mime_map
- valid_exists? @config_file, "Config file not there: #@config_file" if @config_file
- valid_dir? File.dirname(@generate), "Problem accessing directory to #@generate" if @generate
- valid_user? @user if @user
- valid_group? @group if @group
-
- return @valid
- end
-
- def run
- if @generate
- @generate = File.expand_path(@generate)
- Mongrel.log(:error, "** Writing config to \"#@generate\".")
- open(@generate, "w") {|f| f.write(settings.to_yaml) }
- Mongrel.log(:error, "** Finished. Run \"mongrel_rails start -C #@generate\" to use the config file.")
- exit 0
- end
-
- config = RailsConfigurator.new(settings) do
- defaults[:log] = $stdout if defaults[:environment] == 'development'
-
- Mongrel.log("=> Rails #{Rails.version} application starting on http://#{defaults[:host]}:#{defaults[:port]}")
-
- unless defaults[:daemon]
- Mongrel.log("=> Call with -d to detach")
- Mongrel.log("=> Ctrl-C to shutdown server")
- start_debugger if defaults[:debug]
- end
-
- if defaults[:daemon]
- if File.exist? defaults[:pid_file]
- Mongrel.log(:error, "!!! PID file #{defaults[:pid_file]} already exists. Mongrel could be running already. Check your #{defaults[:log_file]} for errors.")
- Mongrel.log(:error, "!!! Exiting with error. You must stop mongrel and clear the .pid before I'll attempt a start.")
- exit 1
- end
-
- daemonize
-
- Mongrel.log("Daemonized, any open files are closed. Look at #{defaults[:pid_file]} and #{defaults[:log_file]} for info.")
- Mongrel.log("Settings loaded from #{@config_file} (they override command line).") if @config_file
- end
-
- Mongrel.log("Starting Mongrel listening at #{defaults[:host]}:#{defaults[:port]}, further information can be found in log/mongrel-#{defaults[:host]}-#{defaults[:port]}.log")
-
- listener do
- prefix = defaults[:prefix] || '/'
-
- if defaults[:debug]
- Mongrel.log("Installing debugging prefixed filters. Look in log/mongrel_debug for the files.")
- debug(prefix)
- end
-
- setup_mime_types
- dir_handler = Mongrel::DirHandler.new(defaults[:docroot], false)
- dir_handler.passthrough_missing_files = true
-
- unless defaults[:environment] == 'production'
- Mongrel.log("Mounting DirHandler at #{prefix}...")
- uri prefix, :handler => dir_handler
- end
-
-
- Mongrel.log("Starting Rails with #{defaults[:environment]} environment...")
- Mongrel.log("Mounting Rails at #{prefix}...")
- mount_rails(prefix)
- Mongrel.log("Rails loaded.")
-
-
- Mongrel.log("Loading any Rails specific GemPlugins" )
- load_plugins
-
- if defaults[:config_script]
- Mongrel.log("Loading #{defaults[:config_script]} external config script")
- run_config(defaults[:config_script])
- end
-
- setup_signals
- end
- end
-
- config.run
- Mongrel.log("Mongrel #{Mongrel::Const::MONGREL_VERSION} available at #{@address}:#{@port}")
-
- if config.defaults[:daemon]
- config.write_pid_file
- else
- Mongrel.log("Use CTRL-C to stop.")
- tail "log/#{config.defaults[:environment]}.log"
- end
-
- config.join
-
- if config.needs_restart
- unless RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/
- cmd = "ruby #{__FILE__} start #{original_args.join(' ')}"
- Mongrel.log("Restarting with arguments: #{cmd}")
- config.stop(false, true)
- config.remove_pid_file
-
- if config.defaults[:daemon]
- system cmd
- else
- Mongrel.log(:error, "Can't restart unless in daemon mode.")
- exit 1
- end
- else
- Mongrel.log("Win32 does not support restarts. Exiting.")
- end
- end
- end
-
- def load_config
- settings = {}
- begin
- settings = YAML.load_file(@config_file)
- ensure
- Mongrel.log(:error, "** Loading settings from #{@config_file} (they override command line).") unless @daemon || settings[:daemon]
- end
-
- settings[:includes] ||= ["mongrel"]
-
- # Config file settings will override command line settings
- settings.each do |key, value|
- key = key.to_s
- if config_keys.include?(key)
- key = 'address' if key == 'host'
- self.instance_variable_set("@#{key}", value)
- else
- failure "Unknown configuration setting: #{key}"
- @valid = false
- end
- end
- end
-
- def config_keys
- @config_keys ||=
- %w(address host port cwd log_file pid_file environment docroot mime_map daemon debug includes config_script num_processors timeout throttle user group prefix)
- end
-
- def settings
- config_keys.inject({}) do |hash, key|
- value = self.instance_variable_get("@#{key}")
- key = 'host' if key == 'address'
- hash[key.to_sym] ||= value
- hash
- end
- end
-
- def start_debugger
- require_library_or_gem 'ruby-debug'
- Debugger.start
- Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings)
- Mongrel.log("=> Debugger enabled")
- rescue Exception
- Mongrel.log(:error, "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'")
- exit
- end
-
- def tail(log_file)
- cursor = File.size(log_file)
- last_checked = Time.now
- tail_thread = Thread.new do
- File.open(log_file, 'r') do |f|
- loop do
- f.seek cursor
- if f.mtime > last_checked
- last_checked = f.mtime
- contents = f.read
- cursor += contents.length
- print contents
- end
- sleep 1
- end
- end
- end
- tail_thread
- end
- end
-
- class Stop < GemPlugin::Plugin "/commands"
- include Mongrel::Command::Base
-
- def configure
- options [
- ['-c', '--chdir PATH', "Change to dir before starting (will be expanded).", :@cwd, "."],
- ['-f', '--force', "Force the shutdown (kill -9).", :@force, false],
- ['-w', '--wait SECONDS', "Wait SECONDS before forcing shutdown", :@wait, "0"],
- ['-P', '--pid FILE', "Where the PID file is located.", :@pid_file, "log/mongrel.pid"]
- ]
- end
-
- def validate
- @cwd = File.expand_path(@cwd)
- valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd"
-
- Dir.chdir @cwd
-
- valid_exists? @pid_file, "PID file #@pid_file does not exist. Not running?"
- return @valid
- end
-
- def run
- if @force
- @wait.to_i.times do |waiting|
- exit(0) if not File.exist? @pid_file
- sleep 1
- end
-
- Mongrel::send_signal("KILL", @pid_file) if File.exist? @pid_file
- else
- Mongrel::send_signal("TERM", @pid_file)
- end
- end
- end
-
-
- class Restart < GemPlugin::Plugin "/commands"
- include Mongrel::Command::Base
-
- def configure
- options [
- ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, '.'],
- ['-P', '--pid FILE', "Where the PID file is located", :@pid_file, "log/mongrel.pid"]
- ]
- end
-
- def validate
- @cwd = File.expand_path(@cwd)
- valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd"
-
- Dir.chdir @cwd
-
- valid_exists? @pid_file, "PID file #@pid_file does not exist. Not running?"
- return @valid
- end
-
- def run
- MongrelServer::send_signal("USR2", @pid_file)
- end
- end
- end
-end
diff --git a/vendor/rails-2.1.0/railties/lib/rails/mongrel_server/handler.rb b/vendor/rails-2.1.0/railties/lib/rails/mongrel_server/handler.rb
deleted file mode 100644
index a19eca725..000000000
--- a/vendor/rails-2.1.0/railties/lib/rails/mongrel_server/handler.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-# Copyright (c) 2005 Zed A. Shaw
-# You can redistribute it and/or modify it under the same terms as Ruby.
-#
-# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
-# for more information.
-
-require 'mongrel'
-require 'cgi'
-require 'action_controller/dispatcher'
-
-
-module Rails
- module MongrelServer
- # Implements a handler that can run Rails and serve files out of the
- # Rails application's public directory. This lets you run your Rails
- # application with Mongrel during development and testing, then use it
- # also in production behind a server that's better at serving the
- # static files.
- #
- # The RailsHandler takes a mime_map parameter which is a simple suffix=mimetype
- # mapping that it should add to the list of valid mime types.
- #
- # It also supports page caching directly and will try to resolve a request
- # in the following order:
- #
- # * If the requested exact PATH_INFO exists as a file then serve it.
- # * If it exists at PATH_INFO+".html" exists then serve that.
- # * Finally, construct a Mongrel::CGIWrapper and run Dispatcher.dispatch to have Rails go.
- #
- # This means that if you are using page caching it will actually work with Mongrel
- # and you should see a decent speed boost (but not as fast as if you use a static
- # server like Apache or Litespeed).
- class RailsHandler < Mongrel::HttpHandler
- # Construct a Mongrel::CGIWrapper and dispatch.
- def process(request, response)
- return if response.socket.closed?
-
- cgi = Mongrel::CGIWrapper.new(request, response)
- cgi.handler = self
- # We don't want the output to be really final until we're out of the lock
- cgi.default_really_final = false
-
- ActionController::Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, response.body)
-
- # This finalizes the output using the proper HttpResponse way
- cgi.out("text/html",true) {""}
- rescue Errno::EPIPE
- response.socket.close
- rescue Object => rails_error
- STDERR.puts "#{Time.now.httpdate}: Error dispatching #{rails_error.inspect}"
- STDERR.puts rails_error.backtrace.join("\n")
- end
- end
- end
-end
diff --git a/vendor/rails-2.1.0/railties/lib/rails/plugin.rb b/vendor/rails-2.1.0/railties/lib/rails/plugin.rb
deleted file mode 100644
index 256f4b013..000000000
--- a/vendor/rails-2.1.0/railties/lib/rails/plugin.rb
+++ /dev/null
@@ -1,115 +0,0 @@
-module Rails
- # The Plugin class should be an object which provides the following methods:
- #
- # * +name+ - Used during initialisation to order the plugin (based on name and
- # the contents of <tt>config.plugins</tt>).
- # * +valid?+ - Returns true if this plugin can be loaded.
- # * +load_paths+ - Each path within the returned array will be added to the <tt>$LOAD_PATH</tt>.
- # * +load+ - Finally 'load' the plugin.
- #
- # These methods are expected by the Rails::Plugin::Locator and Rails::Plugin::Loader classes.
- # The default implementation returns the <tt>lib</tt> directory as its <tt>load_paths</tt>,
- # and evaluates <tt>init.rb</tt> when <tt>load</tt> is called.
- #
- # You can also inspect the about.yml data programmatically:
- #
- # plugin = Rails::Plugin.new(path_to_my_plugin)
- # plugin.about["author"] # => "James Adam"
- # plugin.about["url"] # => "http://interblah.net"
- class Plugin
- include Comparable
-
- attr_reader :directory, :name
-
- def initialize(directory)
- @directory = directory
- @name = File.basename(@directory) rescue nil
- @loaded = false
- end
-
- def valid?
- File.directory?(directory) && (has_lib_directory? || has_init_file?)
- end
-
- # Returns a list of paths this plugin wishes to make available in <tt>$LOAD_PATH</tt>.
- def load_paths
- report_nonexistant_or_empty_plugin! unless valid?
- has_lib_directory? ? [lib_path] : []
- end
-
- # Evaluates a plugin's init.rb file.
- def load(initializer)
- return if loaded?
- report_nonexistant_or_empty_plugin! unless valid?
- evaluate_init_rb(initializer)
- @loaded = true
- end
-
- def loaded?
- @loaded
- end
-
- def <=>(other_plugin)
- name <=> other_plugin.name
- end
-
- def about
- @about ||= load_about_information
- end
-
- private
- def load_about_information
- about_yml_path = File.join(@directory, "about.yml")
- parsed_yml = File.exist?(about_yml_path) ? YAML.load(File.read(about_yml_path)) : {}
- parsed_yml || {}
- rescue Exception
- {}
- end
-
- def report_nonexistant_or_empty_plugin!
- raise LoadError, "Can not find the plugin named: #{name}"
- end
-
- def lib_path
- File.join(directory, 'lib')
- end
-
- def init_path
- File.join(directory, 'init.rb')
- end
-
- def has_lib_directory?
- File.directory?(lib_path)
- end
-
- def has_init_file?
- File.file?(init_path)
- end
-
- def evaluate_init_rb(initializer)
- if has_init_file?
- silence_warnings do
- # Allow plugins to reference the current configuration object
- config = initializer.configuration
-
- eval(IO.read(init_path), binding, init_path)
- end
- end
- end
- end
-
- # This Plugin subclass represents a Gem plugin. Although RubyGems has already
- # taken care of $LOAD_PATHs, it exposes its load_paths to add them
- # to Dependencies.load_paths.
- class GemPlugin < Plugin
- # Initialize this plugin from a Gem::Specification.
- def initialize(spec)
- super(File.join(spec.full_gem_path))
- @name = spec.name
- end
-
- def init_path
- File.join(directory, 'rails', 'init.rb')
- end
- end
-end \ No newline at end of file
diff --git a/vendor/rails-2.1.0/railties/lib/rails/plugin/loader.rb b/vendor/rails-2.1.0/railties/lib/rails/plugin/loader.rb
deleted file mode 100644
index 1e542dd03..000000000
--- a/vendor/rails-2.1.0/railties/lib/rails/plugin/loader.rb
+++ /dev/null
@@ -1,152 +0,0 @@
-require "rails/plugin"
-
-module Rails
- class Plugin
- class Loader
- attr_reader :initializer
-
- # Creates a new Plugin::Loader instance, associated with the given
- # Rails::Initializer. This default implementation automatically locates
- # all plugins, and adds all plugin load paths, when it is created. The plugins
- # are then fully loaded (init.rb is evaluated) when load_plugins is called.
- #
- # It is the loader's responsibility to ensure that only the plugins specified
- # in the configuration are actually loaded, and that the order defined
- # is respected.
- def initialize(initializer)
- @initializer = initializer
- end
-
- # Returns the plugins to be loaded, in the order they should be loaded.
- def plugins
- @plugins ||= all_plugins.select { |plugin| should_load?(plugin) }.sort { |p1, p2| order_plugins(p1, p2) }
- end
-
- # Returns all the plugins that could be found by the current locators.
- def all_plugins
- @all_plugins ||= locate_plugins
- @all_plugins
- end
-
- def load_plugins
- plugins.each do |plugin|
- plugin.load(initializer)
- register_plugin_as_loaded(plugin)
- end
- ensure_all_registered_plugins_are_loaded!
- end
-
- # Adds the load paths for every plugin into the $LOAD_PATH. Plugin load paths are
- # added *after* the application's <tt>lib</tt> directory, to ensure that an application
- # can always override code within a plugin.
- #
- # Plugin load paths are also added to Dependencies.load_paths, and Dependencies.load_once_paths.
- def add_plugin_load_paths
- plugins.each do |plugin|
- plugin.load_paths.each do |path|
- $LOAD_PATH.insert(application_lib_index + 1, path)
- Dependencies.load_paths << path
- unless Rails.configuration.reload_plugins?
- Dependencies.load_once_paths << path
- end
- end
- end
- $LOAD_PATH.uniq!
- end
-
- protected
-
- # The locate_plugins method uses each class in config.plugin_locators to
- # find the set of all plugins available to this Rails application.
- def locate_plugins
- configuration.plugin_locators.map { |locator|
- locator.new(initializer).plugins
- }.flatten
- # TODO: sorting based on config.plugins
- end
-
- def register_plugin_as_loaded(plugin)
- initializer.loaded_plugins << plugin
- end
-
- def configuration
- initializer.configuration
- end
-
- def should_load?(plugin)
- # uses Plugin#name and Plugin#valid?
- enabled?(plugin) && plugin.valid?
- end
-
- def order_plugins(plugin_a, plugin_b)
- if !explicit_plugin_loading_order?
- plugin_a <=> plugin_b
- else
- if !explicitly_enabled?(plugin_a) && !explicitly_enabled?(plugin_b)
- plugin_a <=> plugin_b
- else
- effective_order_of(plugin_a) <=> effective_order_of(plugin_b)
- end
- end
- end
-
- def effective_order_of(plugin)
- if explicitly_enabled?(plugin)
- registered_plugin_names.index(plugin.name)
- else
- registered_plugin_names.index('all')
- end
- end
-
- def application_lib_index
- $LOAD_PATH.index(File.join(RAILS_ROOT, 'lib')) || 0
- end
-
- def enabled?(plugin)
- !explicit_plugin_loading_order? || registered?(plugin)
- end
-
- def explicit_plugin_loading_order?
- !registered_plugin_names.nil?
- end
-
- def registered?(plugin)
- explicit_plugin_loading_order? && registered_plugins_names_plugin?(plugin)
- end
-
- def explicitly_enabled?(plugin)
- !explicit_plugin_loading_order? || explicitly_registered?(plugin)
- end
-
- def explicitly_registered?(plugin)
- explicit_plugin_loading_order? && registered_plugin_names.include?(plugin.name)
- end
-
- def registered_plugins_names_plugin?(plugin)
- registered_plugin_names.include?(plugin.name) || registered_plugin_names.include?('all')
- end
-
- # The plugins that have been explicitly listed with config.plugins. If this list is nil
- # then it means the client does not care which plugins or in what order they are loaded,
- # so we load all in alphabetical order. If it is an empty array, we load no plugins, if it is
- # non empty, we load the named plugins in the order specified.
- def registered_plugin_names
- configuration.plugins ? configuration.plugins.map(&:to_s) : nil
- end
-
- def loaded?(plugin_name)
- initializer.loaded_plugins.detect { |plugin| plugin.name == plugin_name.to_s }
- end
-
- def ensure_all_registered_plugins_are_loaded!
- if explicit_plugin_loading_order?
- if configuration.plugins.detect {|plugin| plugin != :all && !loaded?(plugin) }
- missing_plugins = configuration.plugins - (plugins + [:all])
- raise LoadError, "Could not locate the following plugins: #{missing_plugins.to_sentence}"
- end
- end
- end
-
- end
- end
-end \ No newline at end of file
diff --git a/vendor/rails-2.1.0/railties/lib/rails/plugin/locator.rb b/vendor/rails-2.1.0/railties/lib/rails/plugin/locator.rb
deleted file mode 100644
index f06a51a57..000000000
--- a/vendor/rails-2.1.0/railties/lib/rails/plugin/locator.rb
+++ /dev/null
@@ -1,99 +0,0 @@
-module Rails
- class Plugin
-
- # The Plugin::Locator class should be subclasses to provide custom plugin-finding
- # abilities to Rails (i.e. loading plugins from Gems, etc). Each subclass should implement
- # the <tt>located_plugins</tt> method, which return an array of Plugin objects that have been found.
- class Locator
- include Enumerable
-
- attr_reader :initializer
-
- def initialize(initializer)
- @initializer = initializer
- end
-
- # This method should return all the plugins which this Plugin::Locator can find
- # These will then be used by the current Plugin::Loader, which is responsible for actually
- # loading the plugins themselves
- def plugins
- raise "The `plugins' method must be defined by concrete subclasses of #{self.class}"
- end
-
- def each(&block)
- plugins.each(&block)
- end
-
- def plugin_names
- plugins.map(&:name)
- end
- end
-
- # The Rails::Plugin::FileSystemLocator will try to locate plugins by examining the directories
- # the the paths given in configuration.plugin_paths. Any plugins that can be found are returned
- # in a list.
- #
- # The criteria for a valid plugin in this case is found in Rails::Plugin#valid?, although
- # other subclasses of Rails::Plugin::Locator can of course use different conditions.
- class FileSystemLocator < Locator
-
- # Returns all the plugins which can be loaded in the filesystem, under the paths given
- # by configuration.plugin_paths.
- def plugins
- initializer.configuration.plugin_paths.flatten.inject([]) do |plugins, path|
- plugins.concat locate_plugins_under(path)
- plugins
- end.flatten
- end
-
- private
-
- # Attempts to create a plugin from the given path. If the created plugin is valid?
- # (see Rails::Plugin#valid?) then the plugin instance is returned; otherwise nil.
- def create_plugin(path)
- plugin = Rails::Plugin.new(path)
- plugin.valid? ? plugin : nil
- end
-
- # This starts at the base path looking for valid plugins (see Rails::Plugin#valid?).
- # Since plugins can be nested arbitrarily deep within an unspecified number of intermediary
- # directories, this method runs recursively until it finds a plugin directory, e.g.
- #
- # locate_plugins_under('vendor/plugins/acts/acts_as_chunky_bacon')
- # => <Rails::Plugin name: 'acts_as_chunky_bacon' ... >
- #
- def locate_plugins_under(base_path)
- Dir.glob(File.join(base_path, '*')).inject([]) do |plugins, path|
- if plugin = create_plugin(path)
- plugins << plugin
- elsif File.directory?(path)
- plugins.concat locate_plugins_under(path)
- end
- plugins
- end
- end
- end
-
- # The GemLocator scans all the loaded RubyGems, looking for gems with
- # a <tt>rails/init.rb</tt> file.
- class GemLocator < Locator
- def plugins
- specs = initializer.configuration.gems.map(&:specification)
- specs += Gem.loaded_specs.values.select do |spec|
- spec.loaded_from && # prune stubs
- File.exist?(File.join(spec.full_gem_path, "rails", "init.rb"))
- end
- specs.compact!
-
- require "rubygems/dependency_list"
-
- deps = Gem::DependencyList.new
- deps.add(*specs) unless specs.empty?
-
- deps.dependency_order.collect do |spec|
- Rails::GemPlugin.new(spec)
- end
- end
- end
- end
-end \ No newline at end of file
diff --git a/vendor/rails-2.1.0/railties/lib/rails/version.rb b/vendor/rails-2.1.0/railties/lib/rails/version.rb
deleted file mode 100644
index 48d24da52..000000000
--- a/vendor/rails-2.1.0/railties/lib/rails/version.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-module Rails
- module VERSION #:nodoc:
- MAJOR = 2
- MINOR = 1
- TINY = 0
-
- STRING = [MAJOR, MINOR, TINY].join('.')
- end
-end