bleak_house 3.5.1 → 3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. data/CHANGELOG +2 -0
  2. data/Manifest +49 -2
  3. data/README +4 -1
  4. data/TODO +1 -1
  5. data/bleak_house.gemspec +48 -0
  6. data/ext/bleak_house/logger/snapshot.c +6 -7
  7. data/lib/bleak_house/analyzer/analyzer.rb +2 -2
  8. data/lib/bleak_house/analyzer.rb +0 -2
  9. data/lib/bleak_house/rails/bleak_house.rb +2 -0
  10. data/lib/bleak_house/rails/dispatcher.rb +11 -15
  11. data/test/integration/app/README +203 -0
  12. data/test/integration/app/Rakefile +10 -0
  13. data/test/integration/app/app/controllers/application.rb +12 -0
  14. data/test/integration/app/app/controllers/items_controller.rb +6 -0
  15. data/test/integration/app/app/helpers/application_helper.rb +3 -0
  16. data/test/integration/app/app/helpers/items_helper.rb +2 -0
  17. data/test/integration/app/app/views/items/index.rhtml +2 -0
  18. data/test/integration/app/config/boot.rb +109 -0
  19. data/test/integration/app/config/database.yml +19 -0
  20. data/test/integration/app/config/environment.rb +15 -0
  21. data/test/integration/app/config/environments/development.rb +18 -0
  22. data/test/integration/app/config/environments/production.rb +19 -0
  23. data/test/integration/app/config/environments/test.rb +22 -0
  24. data/test/integration/app/config/initializers/inflections.rb +10 -0
  25. data/test/integration/app/config/initializers/mime_types.rb +5 -0
  26. data/test/integration/app/config/routes.rb +35 -0
  27. data/test/integration/app/doc/README_FOR_APP +2 -0
  28. data/test/integration/app/log/bleak_house_production.dump +237342 -0
  29. data/test/integration/app/public/404.html +30 -0
  30. data/test/integration/app/public/422.html +30 -0
  31. data/test/integration/app/public/500.html +30 -0
  32. data/test/integration/app/public/dispatch.cgi +10 -0
  33. data/test/integration/app/public/dispatch.fcgi +24 -0
  34. data/test/integration/app/public/dispatch.rb +10 -0
  35. data/test/integration/app/public/favicon.ico +0 -0
  36. data/test/integration/app/public/images/rails.png +0 -0
  37. data/test/integration/app/public/javascripts/application.js +2 -0
  38. data/test/integration/app/public/javascripts/controls.js +963 -0
  39. data/test/integration/app/public/javascripts/dragdrop.js +972 -0
  40. data/test/integration/app/public/javascripts/effects.js +1120 -0
  41. data/test/integration/app/public/javascripts/prototype.js +4225 -0
  42. data/test/integration/app/public/robots.txt +5 -0
  43. data/test/integration/app/script/about +3 -0
  44. data/test/integration/app/script/console +3 -0
  45. data/test/integration/app/script/destroy +3 -0
  46. data/test/integration/app/script/generate +3 -0
  47. data/test/integration/app/script/performance/benchmarker +3 -0
  48. data/test/integration/app/script/performance/profiler +3 -0
  49. data/test/integration/app/script/performance/request +3 -0
  50. data/test/integration/app/script/plugin +3 -0
  51. data/test/integration/app/script/process/inspector +3 -0
  52. data/test/integration/app/script/process/reaper +3 -0
  53. data/test/integration/app/script/process/spawner +3 -0
  54. data/test/integration/app/script/runner +3 -0
  55. data/test/integration/app/script/server +3 -0
  56. data/test/integration/app/test/functional/items_controller_test.rb +8 -0
  57. data/test/integration/app/test/test_helper.rb +38 -0
  58. data/test/integration/server_test.rb +91 -0
  59. data/test/test_helper.rb +6 -0
  60. data.tar.gz.sig +0 -0
  61. metadata +54 -5
  62. metadata.gz.sig +0 -0
  63. data/Rakefile +0 -26
  64. data/lib/bleak_house/support/rake.rb +0 -25
data/CHANGELOG CHANGED
@@ -1,4 +1,6 @@
1
1
 
2
+ v3.6. Rails 2.0.2 compatibility.
3
+
2
4
  v3.5.1. Update bundled Ruby to patchlevel 110. Delete your current ruby-bleak-house and reinstall.
3
5
 
4
6
  v3.5. Explain when you need more frames. Use a cross-platform version of 'which'. Slight accuracy improvement.
data/Manifest CHANGED
@@ -16,16 +16,63 @@ lib/bleak_house/rails/bleak_house.rb
16
16
  lib/bleak_house/rails/dispatcher.rb
17
17
  lib/bleak_house/rails.rb
18
18
  lib/bleak_house/support/core_extensions.rb
19
- lib/bleak_house/support/rake.rb
20
19
  lib/bleak_house.rb
21
20
  LICENSE
22
21
  LICENSE_BSD
23
22
  Manifest
24
- Rakefile
25
23
  README
26
24
  ruby/gc.c.patch
27
25
  ruby/parse.y.patch
28
26
  ruby/ruby-1.8.6-p110.tar.bz2
27
+ test/integration/app/app/controllers/application.rb
28
+ test/integration/app/app/controllers/items_controller.rb
29
+ test/integration/app/app/helpers/application_helper.rb
30
+ test/integration/app/app/helpers/items_helper.rb
31
+ test/integration/app/app/views/items/index.rhtml
32
+ test/integration/app/config/boot.rb
33
+ test/integration/app/config/database.yml
34
+ test/integration/app/config/environment.rb
35
+ test/integration/app/config/environments/development.rb
36
+ test/integration/app/config/environments/production.rb
37
+ test/integration/app/config/environments/test.rb
38
+ test/integration/app/config/initializers/inflections.rb
39
+ test/integration/app/config/initializers/mime_types.rb
40
+ test/integration/app/config/routes.rb
41
+ test/integration/app/doc/README_FOR_APP
42
+ test/integration/app/log/bleak_house_production.dump
43
+ test/integration/app/public/404.html
44
+ test/integration/app/public/422.html
45
+ test/integration/app/public/500.html
46
+ test/integration/app/public/dispatch.cgi
47
+ test/integration/app/public/dispatch.fcgi
48
+ test/integration/app/public/dispatch.rb
49
+ test/integration/app/public/favicon.ico
50
+ test/integration/app/public/images/rails.png
51
+ test/integration/app/public/javascripts/application.js
52
+ test/integration/app/public/javascripts/controls.js
53
+ test/integration/app/public/javascripts/dragdrop.js
54
+ test/integration/app/public/javascripts/effects.js
55
+ test/integration/app/public/javascripts/prototype.js
56
+ test/integration/app/public/robots.txt
57
+ test/integration/app/Rakefile
58
+ test/integration/app/README
59
+ test/integration/app/script/about
60
+ test/integration/app/script/console
61
+ test/integration/app/script/destroy
62
+ test/integration/app/script/generate
63
+ test/integration/app/script/performance/benchmarker
64
+ test/integration/app/script/performance/profiler
65
+ test/integration/app/script/performance/request
66
+ test/integration/app/script/plugin
67
+ test/integration/app/script/process/inspector
68
+ test/integration/app/script/process/reaper
69
+ test/integration/app/script/process/spawner
70
+ test/integration/app/script/runner
71
+ test/integration/app/script/server
72
+ test/integration/app/test/functional/items_controller_test.rb
73
+ test/integration/app/test/test_helper.rb
74
+ test/integration/server_test.rb
29
75
  test/misc/direct.rb
76
+ test/test_helper.rb
30
77
  test/unit/test_bleak_house.rb
31
78
  TODO
data/README CHANGED
@@ -20,6 +20,7 @@ The public certificate for this gem is at http://rubyforge.org/frs/download.php/
20
20
 
21
21
  * A unix-like operating system
22
22
  * Ruby 1.8.6
23
+ * Rails 2.0.2 or greater
23
24
 
24
25
  = Usage
25
26
 
@@ -30,6 +31,8 @@ Install the gem:
30
31
 
31
32
  The installation takes a long time because it compiles a patched Ruby binary for you. It is installed as <tt>ruby-bleak-house</tt> alongside your regular <tt>ruby</tt>binary.
32
33
 
34
+ Please see the forum ( http://rubyforge.org/forum/forum.php?forum_id=13983 ) if you have installation problems.
35
+
33
36
  == Profiling a Rails app
34
37
 
35
38
  To setup a Rails app for profiling, just <tt>require 'bleak_house'</tt> in <tt>config/environment.rb</tt>.
@@ -48,7 +51,7 @@ Be patient.
48
51
 
49
52
  == Using BleakHouse outside of Rails
50
53
 
51
- Just instantiate a BleakHouse::Logger object, and make calls to <tt>snapshot</tt> at appropriate times.
54
+ Just instantiate a BleakHouse::Logger object, and make calls to <tt>snapshot</tt> at appropriate times, with tags to identify their context.
52
55
 
53
56
  == Troubleshooting
54
57
 
data/TODO CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- * Some bug in the immortal detector; no results returned on the CHOW 2gb dump.
2
+ * Better docs on what the tags mean
@@ -0,0 +1,48 @@
1
+
2
+ # Gem::Specification for Bleak_house-3.6
3
+ # Originally generated by Echoe
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = %q{bleak_house}
7
+ s.version = "3.6"
8
+
9
+ s.specification_version = 2 if s.respond_to? :specification_version=
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.authors = ["Evan Weaver"]
13
+ s.date = %q{2008-01-02}
14
+ s.default_executable = %q{bleak}
15
+ s.description = %q{A library for finding memory leaks.}
16
+ s.email = %q{}
17
+ s.executables = ["bleak"]
18
+ s.extensions = ["ext/bleak_house/logger/extconf.rb"]
19
+ s.files = ["bin/bleak", "CHANGELOG", "ext/bleak_house/logger/build_logger.rb", "ext/bleak_house/logger/build_ruby.rb", "ext/bleak_house/logger/extconf.rb", "ext/bleak_house/logger/snapshot.c", "ext/bleak_house/logger/snapshot.h", "init.rb", "install.rb", "lib/bleak_house/analyzer/analyzer.rb", "lib/bleak_house/analyzer.rb", "lib/bleak_house/logger/mem_usage.rb", "lib/bleak_house/logger.rb", "lib/bleak_house/rails/action_controller.rb", "lib/bleak_house/rails/bleak_house.rb", "lib/bleak_house/rails/dispatcher.rb", "lib/bleak_house/rails.rb", "lib/bleak_house/support/core_extensions.rb", "lib/bleak_house.rb", "LICENSE", "LICENSE_BSD", "Manifest", "README", "ruby/gc.c.patch", "ruby/parse.y.patch", "ruby/ruby-1.8.6-p110.tar.bz2", "test/integration/app/app/controllers/application.rb", "test/integration/app/app/controllers/items_controller.rb", "test/integration/app/app/helpers/application_helper.rb", "test/integration/app/app/helpers/items_helper.rb", "test/integration/app/app/views/items/index.rhtml", "test/integration/app/config/boot.rb", "test/integration/app/config/database.yml", "test/integration/app/config/environment.rb", "test/integration/app/config/environments/development.rb", "test/integration/app/config/environments/production.rb", "test/integration/app/config/environments/test.rb", "test/integration/app/config/initializers/inflections.rb", "test/integration/app/config/initializers/mime_types.rb", "test/integration/app/config/routes.rb", "test/integration/app/doc/README_FOR_APP", "test/integration/app/log/bleak_house_production.dump", "test/integration/app/public/404.html", "test/integration/app/public/422.html", "test/integration/app/public/500.html", "test/integration/app/public/dispatch.cgi", "test/integration/app/public/dispatch.fcgi", "test/integration/app/public/dispatch.rb", "test/integration/app/public/favicon.ico", "test/integration/app/public/images/rails.png", "test/integration/app/public/javascripts/application.js", "test/integration/app/public/javascripts/controls.js", "test/integration/app/public/javascripts/dragdrop.js", "test/integration/app/public/javascripts/effects.js", "test/integration/app/public/javascripts/prototype.js", "test/integration/app/public/robots.txt", "test/integration/app/Rakefile", "test/integration/app/README", "test/integration/app/script/about", "test/integration/app/script/console", "test/integration/app/script/destroy", "test/integration/app/script/generate", "test/integration/app/script/performance/benchmarker", "test/integration/app/script/performance/profiler", "test/integration/app/script/performance/request", "test/integration/app/script/plugin", "test/integration/app/script/process/inspector", "test/integration/app/script/process/reaper", "test/integration/app/script/process/spawner", "test/integration/app/script/runner", "test/integration/app/script/server", "test/integration/app/test/functional/items_controller_test.rb", "test/integration/app/test/test_helper.rb", "test/integration/server_test.rb", "test/misc/direct.rb", "test/test_helper.rb", "test/unit/test_bleak_house.rb", "TODO", "bleak_house.gemspec"]
20
+ s.has_rdoc = true
21
+ s.homepage = %q{http://blog.evanweaver.com/files/doc/fauna/bleak_house/}
22
+ s.require_paths = ["lib", "ext"]
23
+ s.rubyforge_project = %q{fauna}
24
+ s.rubygems_version = %q{1.0.1}
25
+ s.summary = %q{A library for finding memory leaks.}
26
+ s.test_files = ["test/integration/server_test.rb", "test/unit/test_bleak_house.rb"]
27
+
28
+ s.add_dependency(%q<ccsv>, [">= 0"])
29
+ end
30
+
31
+
32
+ # # Original Rakefile source (requires the Echoe gem):
33
+ #
34
+ #
35
+ # require 'echoe'
36
+ #
37
+ # Echoe.new("bleak_house") do |p|
38
+ # p.author = "Evan Weaver"
39
+ # p.project = "fauna"
40
+ # p.summary = "A library for finding memory leaks."
41
+ # p.url = "http://blog.evanweaver.com/files/doc/fauna/bleak_house/"
42
+ # p.docs_host = 'blog.evanweaver.com:~/www/bax/public/files/doc/'
43
+ # p.dependencies = ['ccsv']
44
+ # p.require_signed = true
45
+ #
46
+ # p.rdoc_pattern = /^ext.*\.c|lib.*logger.*rb|analyzer|rails\/bleak_house|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
47
+ # p.test_pattern = ["test/integration/*.rb", "test/unit/*.rb"]
48
+ # end
@@ -1,4 +1,4 @@
1
-
1
+ #include <time.h>
2
2
  #include "snapshot.h"
3
3
 
4
4
  static VALUE rb_mBleakHouse;
@@ -20,7 +20,7 @@ static VALUE snapshot(VALUE self, VALUE _logfile, VALUE tag, VALUE _specials) {
20
20
  Check_Type(tag, T_STRING);
21
21
 
22
22
  RVALUE *obj, *obj_end;
23
- st_table_entry *sym, *sym_end;
23
+ st_table_entry *sym;
24
24
 
25
25
  struct heaps_slot * heaps = rb_gc_heap_slots();
26
26
  struct st_table * sym_tbl = rb_parse_sym_tbl();
@@ -39,21 +39,20 @@ static VALUE snapshot(VALUE self, VALUE _logfile, VALUE tag, VALUE _specials) {
39
39
  rb_raise(rb_eRuntimeError, "couldn't open snapshot file");
40
40
 
41
41
  /* write the time */
42
- fprintf(logfile, "-1,%i\n", time(0));
42
+ fprintf(logfile, "-1,%li\n", time(0));
43
43
 
44
44
  /* get and write the memory usage */
45
45
  VALUE mem = rb_funcall(self, rb_intern("mem_usage"), 0);
46
- fprintf(logfile, "-2,%i\n", NUM2INT(RARRAY_PTR(mem)[0]));
47
- fprintf(logfile, "-3,%i\n", NUM2INT(RARRAY_PTR(mem)[1]));
46
+ fprintf(logfile, "-2,%li\n", NUM2INT(RARRAY_PTR(mem)[0]));
47
+ fprintf(logfile, "-3,%li\n", NUM2INT(RARRAY_PTR(mem)[1]));
48
48
 
49
- int current_pos = 0;
50
49
  int filled_slots = 0;
51
50
  int free_slots = 0;
52
51
 
53
52
  /* write the tag header */
54
53
  fprintf(logfile, "-4,%s\n", StringValueCStr(tag));
55
54
 
56
- int i, j;
55
+ int i;
57
56
 
58
57
  /* walk the heap */
59
58
  for (i = 0; i < rb_gc_heaps_used(); i++) {
@@ -1,5 +1,5 @@
1
1
 
2
- require 'rubygems'
2
+ require 'ccsv'
3
3
  require 'fileutils'
4
4
  require 'yaml'
5
5
  require 'pp'
@@ -84,7 +84,7 @@ module BleakHouse
84
84
 
85
85
  if total_frames < INITIAL_SKIP * 3
86
86
  puts "Not enough frames for accurate results. Please record at least #{INITIAL_SKIP * 3} frames."
87
- exit!
87
+ exit # Should be exit! but that messes up backticks capturing in the tests
88
88
  end
89
89
 
90
90
  Ccsv.foreach(logfile) do |row|
@@ -1,5 +1,3 @@
1
1
 
2
- require 'ccsv'
3
-
4
2
  require 'bleak_house/support/core_extensions'
5
3
  require 'bleak_house/analyzer/analyzer'
@@ -1,6 +1,8 @@
1
1
 
2
2
  module BleakHouse
3
3
  module Rails
4
+ @@last_request_name = nil
5
+
4
6
  class << self
5
7
 
6
8
  def last_request_name
@@ -1,19 +1,15 @@
1
1
 
2
- # Override Dispatcher#prepare and Dispatcher#reset_after_dispatch so that each request makes before-and-after usage snapshots.
2
+ # Insert callbacks so that each request makes before-and-after usage snapshots.
3
3
  class Dispatcher
4
- class << self
5
-
6
- def prepare_application_with_bleak_house
7
- prepare_application_without_bleak_house
8
- BleakHouse::Rails::MEMLOGGER.snapshot(BleakHouse::Rails::LOGFILE, 'core rails', BleakHouse::Rails::WITH_SPECIALS)
9
- end
10
- alias_method_chain :prepare_application, :bleak_house
11
-
12
- def reset_after_dispatch_with_bleak_house
13
- BleakHouse::Rails::MEMLOGGER.snapshot(BleakHouse::Rails::LOGFILE, BleakHouse::Rails.last_request_name || 'unknown', BleakHouse::Rails::WITH_SPECIALS)
14
- reset_after_dispatch_without_bleak_house
15
- end
16
- alias_method_chain :reset_after_dispatch, :bleak_house
17
-
4
+
5
+ def core_rails_snapshot
6
+ BleakHouse::Rails::MEMLOGGER.snapshot(BleakHouse::Rails::LOGFILE, 'core rails', BleakHouse::Rails::WITH_SPECIALS)
18
7
  end
8
+ callbacks[:before].unshift('core_rails_snapshot')
9
+
10
+ def controller_snapshot
11
+ BleakHouse::Rails::MEMLOGGER.snapshot(BleakHouse::Rails::LOGFILE, BleakHouse::Rails.last_request_name || 'unknown', BleakHouse::Rails::WITH_SPECIALS)
12
+ end
13
+ callbacks[:after].unshift('controller_snapshot')
14
+
19
15
  end
@@ -0,0 +1,203 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application and persistence framework that includes everything
4
+ needed to create database-backed web-applications according to the
5
+ Model-View-Control pattern of separation. This pattern splits the view (also
6
+ called the presentation) into "dumb" templates that are primarily responsible
7
+ for inserting pre-built data in between HTML tags. The model contains the
8
+ "smart" domain objects (such as Account, Product, Person, Post) that holds all
9
+ the business logic and knows how to persist themselves to a database. The
10
+ controller handles the incoming requests (such as Save New Account, Update
11
+ Product, Show Post) by manipulating the model and directing data to the view.
12
+
13
+ In Rails, the model is handled by what's called an object-relational mapping
14
+ layer entitled Active Record. This layer allows you to present the data from
15
+ database rows as objects and embellish these data objects with business logic
16
+ methods. You can read more about Active Record in
17
+ link:files/vendor/rails/activerecord/README.html.
18
+
19
+ The controller and view are handled by the Action Pack, which handles both
20
+ layers by its two parts: Action View and Action Controller. These two layers
21
+ are bundled in a single package due to their heavy interdependence. This is
22
+ unlike the relationship between the Active Record and Action Pack that is much
23
+ more separate. Each of these packages can be used independently outside of
24
+ Rails. You can read more about Action Pack in
25
+ link:files/vendor/rails/actionpack/README.html.
26
+
27
+
28
+ == Getting Started
29
+
30
+ 1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
31
+ and your application name. Ex: rails myapp
32
+ (If you've downloaded Rails in a complete tgz or zip, this step is already done)
33
+ 2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
34
+ 3. Go to http://localhost:3000/ and get "Welcome aboard: You’re riding the Rails!"
35
+ 4. Follow the guidelines to start developing your application
36
+
37
+
38
+ == Web Servers
39
+
40
+ By default, Rails will try to use Mongrel and lighttpd if they are installed, otherwise
41
+ Rails will use WEBrick, the webserver that ships with Ruby. When you run script/server,
42
+ Rails will check if Mongrel exists, then lighttpd and finally fall back to WEBrick. This ensures
43
+ that you can always get up and running quickly.
44
+
45
+ Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
46
+ suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
47
+ getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
48
+ More info at: http://mongrel.rubyforge.org
49
+
50
+ If Mongrel is not installed, Rails will look for lighttpd. It's considerably faster than
51
+ Mongrel and WEBrick and also suited for production use, but requires additional
52
+ installation and currently only works well on OS X/Unix (Windows users are encouraged
53
+ to start with Mongrel). We recommend version 1.4.11 and higher. You can download it from
54
+ http://www.lighttpd.net.
55
+
56
+ And finally, if neither Mongrel or lighttpd are installed, Rails will use the built-in Ruby
57
+ web server, WEBrick. WEBrick is a small Ruby web server suitable for development, but not
58
+ for production.
59
+
60
+ But of course its also possible to run Rails on any platform that supports FCGI.
61
+ Apache, LiteSpeed, IIS are just a few. For more information on FCGI,
62
+ please visit: http://wiki.rubyonrails.com/rails/pages/FastCGI
63
+
64
+
65
+ == Debugging Rails
66
+
67
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
68
+ will help you debug it and get it back on the rails.
69
+
70
+ First area to check is the application log files. Have "tail -f" commands running
71
+ on the server.log and development.log. Rails will automatically display debugging
72
+ and runtime information to these files. Debugging info will also be shown in the
73
+ browser on requests from 127.0.0.1.
74
+
75
+ You can also log your own messages directly into the log file from your code using
76
+ the Ruby logger class from inside your controllers. Example:
77
+
78
+ class WeblogController < ActionController::Base
79
+ def destroy
80
+ @weblog = Weblog.find(params[:id])
81
+ @weblog.destroy
82
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
83
+ end
84
+ end
85
+
86
+ The result will be a message in your log file along the lines of:
87
+
88
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
89
+
90
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
91
+
92
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
93
+
94
+ * The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
95
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
96
+
97
+ These two online (and free) books will bring you up to speed on the Ruby language
98
+ and also on programming in general.
99
+
100
+
101
+ == Debugger
102
+
103
+ Debugger support is available through the debugger command when you start your Mongrel or
104
+ Webrick server with --debugger. This means that you can break out of execution at any point
105
+ in the code, investigate and change the model, AND then resume execution! Example:
106
+
107
+ class WeblogController < ActionController::Base
108
+ def index
109
+ @posts = Post.find(:all)
110
+ debugger
111
+ end
112
+ end
113
+
114
+ So the controller will accept the action, run the first line, then present you
115
+ with a IRB prompt in the server window. Here you can do things like:
116
+
117
+ >> @posts.inspect
118
+ => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
119
+ #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
120
+ >> @posts.first.title = "hello from a debugger"
121
+ => "hello from a debugger"
122
+
123
+ ...and even better is that you can examine how your runtime objects actually work:
124
+
125
+ >> f = @posts.first
126
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
127
+ >> f.
128
+ Display all 152 possibilities? (y or n)
129
+
130
+ Finally, when you're ready to resume execution, you enter "cont"
131
+
132
+
133
+ == Console
134
+
135
+ You can interact with the domain model by starting the console through <tt>script/console</tt>.
136
+ Here you'll have all parts of the application configured, just like it is when the
137
+ application is running. You can inspect domain models, change values, and save to the
138
+ database. Starting the script without arguments will launch it in the development environment.
139
+ Passing an argument will specify a different environment, like <tt>script/console production</tt>.
140
+
141
+ To reload your controllers and models after launching the console run <tt>reload!</tt>
142
+
143
+
144
+ == Description of Contents
145
+
146
+ app
147
+ Holds all the code that's specific to this particular application.
148
+
149
+ app/controllers
150
+ Holds controllers that should be named like weblogs_controller.rb for
151
+ automated URL mapping. All controllers should descend from ApplicationController
152
+ which itself descends from ActionController::Base.
153
+
154
+ app/models
155
+ Holds models that should be named like post.rb.
156
+ Most models will descend from ActiveRecord::Base.
157
+
158
+ app/views
159
+ Holds the template files for the view that should be named like
160
+ weblogs/index.erb for the WeblogsController#index action. All views use eRuby
161
+ syntax.
162
+
163
+ app/views/layouts
164
+ Holds the template files for layouts to be used with views. This models the common
165
+ header/footer method of wrapping views. In your views, define a layout using the
166
+ <tt>layout :default</tt> and create a file named default.erb. Inside default.erb,
167
+ call <% yield %> to render the view using this layout.
168
+
169
+ app/helpers
170
+ Holds view helpers that should be named like weblogs_helper.rb. These are generated
171
+ for you automatically when using script/generate for controllers. Helpers can be used to
172
+ wrap functionality for your views into methods.
173
+
174
+ config
175
+ Configuration files for the Rails environment, the routing map, the database, and other dependencies.
176
+
177
+ db
178
+ Contains the database schema in schema.rb. db/migrate contains all
179
+ the sequence of Migrations for your schema.
180
+
181
+ doc
182
+ This directory is where your application documentation will be stored when generated
183
+ using <tt>rake doc:app</tt>
184
+
185
+ lib
186
+ Application specific libraries. Basically, any kind of custom code that doesn't
187
+ belong under controllers, models, or helpers. This directory is in the load path.
188
+
189
+ public
190
+ The directory available for the web server. Contains subdirectories for images, stylesheets,
191
+ and javascripts. Also contains the dispatchers and the default HTML files. This should be
192
+ set as the DOCUMENT_ROOT of your web server.
193
+
194
+ script
195
+ Helper scripts for automation and generation.
196
+
197
+ test
198
+ Unit and functional tests along with fixtures. When using the script/generate scripts, template
199
+ test files will be generated for you and placed in this directory.
200
+
201
+ vendor
202
+ External libraries that the application depends on. Also includes the plugins subdirectory.
203
+ This directory is in the load path.
@@ -0,0 +1,10 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
5
+
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+ require 'rake/rdoctask'
9
+
10
+ require 'tasks/rails'
@@ -0,0 +1,12 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ session :disabled => true
6
+
7
+ # helper :all # include all helpers, all the time
8
+
9
+ # See ActionController::RequestForgeryProtection for details
10
+ # Uncomment the :secret if you're not using the cookie session store
11
+ # protect_from_forgery # :secret => '44cb65cbbae43fcd80952f9fb263a780'
12
+ end
@@ -0,0 +1,6 @@
1
+ class ItemsController < ApplicationController
2
+
3
+ def index
4
+ end
5
+
6
+ end
@@ -0,0 +1,3 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ end
@@ -0,0 +1,2 @@
1
+ module ItemsHelper
2
+ end
@@ -0,0 +1,109 @@
1
+ # Don't change this file!
2
+ # Configure your app in config/environment.rb and config/environments/*.rb
3
+
4
+ RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
5
+
6
+ module Rails
7
+ class << self
8
+ def boot!
9
+ unless booted?
10
+ preinitialize
11
+ pick_boot.run
12
+ end
13
+ end
14
+
15
+ def booted?
16
+ defined? Rails::Initializer
17
+ end
18
+
19
+ def pick_boot
20
+ (vendor_rails? ? VendorBoot : GemBoot).new
21
+ end
22
+
23
+ def vendor_rails?
24
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
25
+ end
26
+
27
+ # FIXME : Ruby 1.9
28
+ def preinitialize
29
+ load(preinitializer_path) if File.exists?(preinitializer_path)
30
+ end
31
+
32
+ def preinitializer_path
33
+ "#{RAILS_ROOT}/config/preinitializer.rb"
34
+ end
35
+ end
36
+
37
+ class Boot
38
+ def run
39
+ load_initializer
40
+ Rails::Initializer.run(:set_load_path)
41
+ end
42
+ end
43
+
44
+ class VendorBoot < Boot
45
+ def load_initializer
46
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
47
+ end
48
+ end
49
+
50
+ class GemBoot < Boot
51
+ def load_initializer
52
+ self.class.load_rubygems
53
+ load_rails_gem
54
+ require 'initializer'
55
+ end
56
+
57
+ def load_rails_gem
58
+ if version = self.class.gem_version
59
+ gem 'rails', version
60
+ else
61
+ gem 'rails'
62
+ end
63
+ rescue Gem::LoadError => load_error
64
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
65
+ exit 1
66
+ end
67
+
68
+ class << self
69
+ def rubygems_version
70
+ Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
71
+ end
72
+
73
+ def gem_version
74
+ if defined? RAILS_GEM_VERSION
75
+ RAILS_GEM_VERSION
76
+ elsif ENV.include?('RAILS_GEM_VERSION')
77
+ ENV['RAILS_GEM_VERSION']
78
+ else
79
+ parse_gem_version(read_environment_rb)
80
+ end
81
+ end
82
+
83
+ def load_rubygems
84
+ require 'rubygems'
85
+
86
+ unless rubygems_version >= '0.9.4'
87
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
88
+ exit 1
89
+ end
90
+
91
+ rescue LoadError
92
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
93
+ exit 1
94
+ end
95
+
96
+ def parse_gem_version(text)
97
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
98
+ end
99
+
100
+ private
101
+ def read_environment_rb
102
+ File.read("#{RAILS_ROOT}/config/environment.rb")
103
+ end
104
+ end
105
+ end
106
+ end
107
+
108
+ # All that for this:
109
+ Rails.boot!
@@ -0,0 +1,19 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
+ development:
4
+ adapter: sqlite3
5
+ database: db/development.sqlite3
6
+ timeout: 5000
7
+
8
+ # Warning: The database defined as 'test' will be erased and
9
+ # re-generated from your development database when you run 'rake'.
10
+ # Do not set this db to the same as development or production.
11
+ test:
12
+ adapter: sqlite3
13
+ database: db/test.sqlite3
14
+ timeout: 5000
15
+
16
+ production:
17
+ adapter: sqlite3
18
+ database: db/production.sqlite3
19
+ timeout: 5000
@@ -0,0 +1,15 @@
1
+
2
+ require File.join(File.dirname(__FILE__), 'boot')
3
+ require 'action_controller'
4
+ require 'active_support'
5
+
6
+ Rails::Initializer.run do |config|
7
+
8
+ if ActionController::Base.respond_to? 'session='
9
+ config.action_controller.session = {:session_key => '_app_session', :secret => '22cde4d5c1a61ba69a81795322cde4d5c1a61ba69a81795322cde4d5c1a61ba69a817953'}
10
+ end
11
+
12
+ end
13
+
14
+ $LOAD_PATH.unshift "#{RAILS_ROOT}/../../../lib/"
15
+ require 'bleak_house'