Skip to content

Commit

Permalink
Documentation updates/fixes for railties
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2637 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jamis committed Oct 16, 2005
1 parent 1ea085e commit ae294af
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 19 deletions.
10 changes: 10 additions & 0 deletions railties/Rakefile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ task :generate_app_doc do
system %{cd #{PKG_DESTINATION}; rake appdoc} system %{cd #{PKG_DESTINATION}; rake appdoc}
end end


Rake::RDocTask.new { |rdoc|
rdoc.rdoc_dir = 'doc'
rdoc.title = "Railties -- Gluing the Engine to the Rails"
rdoc.options << '--line-numbers --inline-source --accessor cattr_accessor=object'
rdoc.template = "#{ENV['template']}.rb" if ENV['template']
rdoc.rdoc_files.include('README', 'CHANGELOG')
rdoc.rdoc_files.include('lib/*.rb')
rdoc.rdoc_files.include('lib/rails_generator/*.rb')
rdoc.rdoc_files.include('lib/commands/**/*.rb')
}


# Generate GEM ---------------------------------------------------------------------------- # Generate GEM ----------------------------------------------------------------------------


Expand Down
4 changes: 3 additions & 1 deletion railties/lib/binding_of_caller.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,9 @@
begin begin
require 'simplecc' require 'simplecc'
rescue LoadError rescue LoadError
class Continuation; end # :nodoc: # for RDoc # to satisfy rdoc
class Continuation #:nodoc:
end
def Continuation.create(*args, &block) # :nodoc: def Continuation.create(*args, &block) # :nodoc:
cc = nil; result = callcc {|c| cc = c; block.call(cc) if block and args.empty?} cc = nil; result = callcc {|c| cc = c; block.call(cc) if block and args.empty?}
result ||= args result ||= args
Expand Down
10 changes: 5 additions & 5 deletions railties/lib/breakpoint.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def result.last_value; end
end end
def IRB.parse_opts() end def IRB.parse_opts() end


class Context class Context #:nodoc:
alias :old_evaluate :evaluate alias :old_evaluate :evaluate
def evaluate(line, line_no) def evaluate(line, line_no)
if line.chomp == "exit" then if line.chomp == "exit" then
Expand All @@ -473,7 +473,7 @@ def evaluate(line, line_no)
end end
end end


class WorkSpace class WorkSpace #:nodoc:
alias :old_evaluate :evaluate alias :old_evaluate :evaluate


def evaluate(*args) def evaluate(*args)
Expand All @@ -491,7 +491,7 @@ def evaluate(*args)
end end
end end


module InputCompletor module InputCompletor #:nodoc:
def self.eval(code, context, *more) def self.eval(code, context, *more)
# Big hack, this assumes that InputCompletor # Big hack, this assumes that InputCompletor
# will only call eval() when it wants code # will only call eval() when it wants code
Expand All @@ -501,8 +501,8 @@ def self.eval(code, context, *more)
end end
end end


module DRb # :nodoc: module DRb #:nodoc:
class DRbObject class DRbObject #:nodoc:
undef :inspect if method_defined?(:inspect) undef :inspect if method_defined?(:inspect)
undef :clone if method_defined?(:clone) undef :clone if method_defined?(:clone)
end end
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/breakpoint_client.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@


Options[:ServerURI] = ARGV[0] if ARGV[0] Options[:ServerURI] = ARGV[0] if ARGV[0]


module Handlers module Handlers #:nodoc:
extend self extend self


def breakpoint_handler(workspace, message) def breakpoint_handler(workspace, message)
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/code_statistics.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
class CodeStatistics class CodeStatistics #:nodoc:


TEST_TYPES = ['Units', 'Functionals', 'Unit tests', 'Functional tests'] TEST_TYPES = ['Units', 'Functionals', 'Unit tests', 'Functional tests']


Expand Down
27 changes: 23 additions & 4 deletions railties/lib/commands/process/reaper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@


if RUBY_PLATFORM =~ /mswin32/ then abort("Reaper is only for Unix") end if RUBY_PLATFORM =~ /mswin32/ then abort("Reaper is only for Unix") end


# Instances of this class represent a single running process. Processes may
# be queried by "keyword" to find those that meet a specific set of criteria.
class ProgramProcess class ProgramProcess
class << self class << self

# Searches for all processes matching the given keywords, and then invokes
# a specific action on each of them. This is useful for (e.g.) reloading a
# set of processes:
#
# ProgramProcess.process_keywords(:reload, "basecamp")
def process_keywords(action, *keywords) def process_keywords(action, *keywords)
processes = keywords.collect { |keyword| find_by_keyword(keyword) }.flatten processes = keywords.collect { |keyword| find_by_keyword(keyword) }.flatten


Expand All @@ -19,6 +27,9 @@ def process_keywords(action, *keywords)
end end
end end


# Searches for all processes matching the given keyword:
#
# ProgramProcess.find_by_keyword("basecamp")
def find_by_keyword(keyword) def find_by_keyword(keyword)
process_lines_with_keyword(keyword).split("\n").collect { |line| process_lines_with_keyword(keyword).split("\n").collect { |line|
next if line.include?("inq") || line.include?("ps -ax") || line.include?("grep") next if line.include?("inq") || line.include?("ps -ax") || line.include?("grep")
Expand All @@ -33,34 +44,42 @@ def process_lines_with_keyword(keyword)
end end
end end


# Create a new ProgramProcess instance that represents the process with the
# given pid, running the given command.
def initialize(pid, command) def initialize(pid, command)
@pid, @command = pid, command @pid, @command = pid, command
end end


def find # Forces the (rails) application to reload by sending a +HUP+ signal to the
end # process.

def reload def reload
`kill -s HUP #{@pid}` `kill -s HUP #{@pid}`
end end


# Forces the (rails) application to gracefully terminate by sending a
# +TERM+ signal to the process.
def graceful def graceful
`kill -s TERM #{@pid}` `kill -s TERM #{@pid}`
end end


# Forces the (rails) application to terminate immediately by sending a -9
# signal to the process.
def kill def kill
`kill -9 #{@pid}` `kill -9 #{@pid}`
end end


# Send a +USR1+ signal to the process.
def usr1 def usr1
`kill -s USR1 #{@pid}` `kill -s USR1 #{@pid}`
end end


# Force the (rails) application to restart by sending a +USR2+ signal to the
# process.
def restart def restart
`kill -s USR2 #{@pid}` `kill -s USR2 #{@pid}`
end end


def to_s def to_s #:nodoc:
"[#{@pid}] #{@command}" "[#{@pid}] #{@command}"
end end
end end
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/commands/process/spinner.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'optparse' require 'optparse'


def daemonize def daemonize #:nodoc:
exit if fork # Parent exits, child continues. exit if fork # Parent exits, child continues.
Process.setsid # Become session leader. Process.setsid # Become session leader.
exit if fork # Zap session leader. See [1]. exit if fork # Zap session leader. See [1].
Expand Down
9 changes: 9 additions & 0 deletions railties/lib/dispatcher.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++ #++


# This class provides an interface for dispatching a CGI (or CGI-like) request
# to the appropriate controller and action. It also takes care of resetting
# the environment (when Dependencies.load? is true) after each request.
class Dispatcher class Dispatcher
class << self class << self

# Dispatch the given CGI request, using the given session options, and
# emitting the output via the given output.
def dispatch(cgi = CGI.new, session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, output = $stdout) def dispatch(cgi = CGI.new, session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, output = $stdout)
begin begin
request, response = ActionController::CgiRequest.new(cgi, session_options), ActionController::CgiResponse.new(cgi) request, response = ActionController::CgiRequest.new(cgi, session_options), ActionController::CgiResponse.new(cgi)
Expand All @@ -35,6 +41,9 @@ def dispatch(cgi = CGI.new, session_options = ActionController::CgiRequest::DEFA
end end
end end


# Reset the application by clearing out loaded controllers, views, actions,
# mailers, and so forth. This allows them to be loaded again without having
# to restart the server (WEBrick, FastCGI, etc.).
def reset_application! def reset_application!
Controllers.clear! Controllers.clear!
Dependencies.clear Dependencies.clear
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rubyprof_ext.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'prof' require 'prof'


module Prof module Prof #:nodoc:
# Adapted from Shugo Maeda's unprof.rb # Adapted from Shugo Maeda's unprof.rb
def self.print_profile(results, io = $stderr) def self.print_profile(results, io = $stderr)
total = results.detect { |i| total = results.detect { |i|
Expand Down
17 changes: 12 additions & 5 deletions railties/lib/webrick_server.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


ActiveRecord::Base.threaded_connections = false ActiveRecord::Base.threaded_connections = false


class CGI class CGI #:nodoc:
def stdinput def stdinput
@stdin || $stdin @stdin || $stdin
end end
Expand Down Expand Up @@ -40,9 +40,16 @@ def initialize(type = "query", table = nil, stdin = nil)
end end
end end


# A custom dispatch servlet for use with WEBrick. It dispatches requests
# (using the Rails Dispatcher) to the appropriate controller/action. By default,
# it restricts WEBrick to a managing a single Rails request at a time, but you
# can change this behavior by setting ActionController::Base.allow_concurrency
# to true.
class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet
REQUEST_MUTEX = Mutex.new REQUEST_MUTEX = Mutex.new


# Start the WEBrick server with the given options, mounting the
# DispatchServlet at <tt>/</tt>.
def self.dispatch(options = {}) def self.dispatch(options = {})
Socket.do_not_reverse_lookup = true # patch for OS X Socket.do_not_reverse_lookup = true # patch for OS X


Expand All @@ -62,14 +69,14 @@ def self.dispatch(options = {})
server.start server.start
end end


def initialize(server, options) def initialize(server, options) #:nodoc:
@server_options = options @server_options = options
@file_handler = WEBrick::HTTPServlet::FileHandler.new(server, options[:server_root]) @file_handler = WEBrick::HTTPServlet::FileHandler.new(server, options[:server_root])
Dir.chdir(ABSOLUTE_RAILS_ROOT) Dir.chdir(ABSOLUTE_RAILS_ROOT)
super super
end end


def service(req, res) def service(req, res) #:nodoc:
begin begin
unless handle_file(req, res) unless handle_file(req, res)
REQUEST_MUTEX.lock unless ActionController::Base.allow_concurrency REQUEST_MUTEX.lock unless ActionController::Base.allow_concurrency
Expand All @@ -84,7 +91,7 @@ def service(req, res)
end end
end end


def handle_file(req, res) def handle_file(req, res) #:nodoc:
begin begin
req = req.dup req = req.dup
path = req.path.dup path = req.path.dup
Expand All @@ -105,7 +112,7 @@ def handle_file(req, res)
end end
end end


def handle_dispatch(req, res, origin = nil) def handle_dispatch(req, res, origin = nil) #:nodoc:
data = StringIO.new data = StringIO.new
Dispatcher.dispatch( Dispatcher.dispatch(
CGI.new("query", create_env_table(req, origin), StringIO.new(req.body || "")), CGI.new("query", create_env_table(req, origin), StringIO.new(req.body || "")),
Expand Down

0 comments on commit ae294af

Please sign in to comment.