Top Level Namespace
- Includes:
- Benchmark, FileUtils, WEBrick
Defined Under Namespace
Modules: Commands, Prof, Rails Classes: AppGenerator, CGI, CodeStatistics, ControllerGenerator, DispatchServlet, Inspector, IntegrationTestGenerator, Killer, MailerGenerator, MigrationGenerator, ModelGenerator, Module, Object, ObserverGenerator, Plugin, PluginGenerator, RailsEnvironment, RailsFCGIHandler, RecursiveHTTPFetcher, Repositories, Repository, ResourceGenerator, ScaffoldGenerator, SessionMigrationGenerator, SourceAnnotationExtractor
Constant Summary collapse
- Dispatcher =
ActionController::Dispatcher
- RAILS_ENV =
(ENV['RAILS_ENV'] || 'development').dup
- RAILTIES_PATH =
File.join(File.dirname(__FILE__), '..')
- OPTIONS =
{ :pid_path => File.(RAILS_ROOT + '/tmp/pids'), :pattern => "dispatch.*.pid", :ps => "ps -o pid,state,user,start,time,pcpu,vsz,majflt,command -p %s" }
Instance Method Summary collapse
-
#app(create = false) ⇒ Object
reference the global “app” instance, created on demand.
- #create_fixtures(*table_names) ⇒ Object
-
#daemonize ⇒ Object
:nodoc:.
- #find_cmd(*commands) ⇒ Object
- #helper(*helper_names) ⇒ Object
-
#new_session {|session| ... } ⇒ Object
create a new session.
-
#reload! ⇒ Object
reloads the environment.
- #start_debugger ⇒ Object
- #tail(log_file) ⇒ Object
Instance Method Details
#app(create = false) ⇒ Object
reference the global “app” instance, created on demand. To recreate the instance, pass a non-false value as the parameter.
8 9 10 11 12 13 |
# File 'lib/console_app.rb', line 8 def app(create=false) @app_integration_instance = nil if create @app_integration_instance ||= new_session do |sess| sess.host! "www.example.com" end end |
#create_fixtures(*table_names) ⇒ Object
18 19 20 |
# File 'lib/test_help.rb', line 18 def create_fixtures(*table_names) Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) end |
#daemonize ⇒ Object
:nodoc:
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/commands/process/spinner.rb', line 3 def daemonize #:nodoc: exit if fork # Parent exits, child continues. Process.setsid # Become session leader. exit if fork # Zap session leader. See [1]. Dir.chdir "/" # Release old working directory. File.umask 0000 # Ensure sensible umask. Adjust as needed. STDIN.reopen "/dev/null" # Free file descriptors and STDOUT.reopen "/dev/null", "a" # point them somewhere sensible. STDERR.reopen STDOUT # STDOUT/ERR should better go to a logfile. end |
#find_cmd(*commands) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/commands/dbconsole.rb', line 22 def find_cmd(*commands) dirs_on_path = ENV['PATH'].to_s.split(File::PATH_SEPARATOR) commands += commands.map{|cmd| "#{cmd}.exe"} if RUBY_PLATFORM =~ /win32/ commands.detect do |cmd| dirs_on_path.detect do |path| File.executable? File.join(path, cmd) end end || abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.") end |
#helper(*helper_names) ⇒ Object
13 14 15 16 17 |
# File 'lib/console_with_helpers.rb', line 13 def helper(*helper_names) returning @helper_proxy ||= Object.new do |helper| helper_names.each { |h| helper.extend "#{h}_helper".classify.constantize } end end |
#new_session {|session| ... } ⇒ Object
create a new session. If a block is given, the new session will be yielded to the block before being returned.
17 18 19 20 21 |
# File 'lib/console_app.rb', line 17 def new_session session = ActionController::Integration::Session.new yield session if block_given? session end |
#reload! ⇒ Object
reloads the environment
24 25 26 27 28 29 30 |
# File 'lib/console_app.rb', line 24 def reload! puts "Reloading..." dispatcher = ActionController::Dispatcher.new($stdout) dispatcher.cleanup_application dispatcher.reload_application true end |
#start_debugger ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/commands/servers/base.rb', line 21 def start_debugger begin require_library_or_gem 'ruby-debug' Debugger.start Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings) puts "=> Debugger enabled" rescue Exception puts "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'" exit end end |
#tail(log_file) ⇒ Object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/commands/servers/base.rb', line 1 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 |