heroku-true-relic 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +39 -0
  3. data/Rakefile +56 -0
  4. data/lib/heroku-true-relic.rb +5 -0
  5. data/lib/heroku-true-relic/queue_time_logger.rb +32 -0
  6. data/lib/heroku-true-relic/rails2.rb +13 -0
  7. data/lib/heroku-true-relic/railtie.rb +7 -0
  8. data/lib/heroku-true-relic/version.rb +3 -0
  9. data/lib/tasks/heroku-true-relic_tasks.rake +4 -0
  10. data/spec/rails-2.3/Gemfile +14 -0
  11. data/spec/rails-2.3/Gemfile.lock +82 -0
  12. data/spec/rails-2.3/Rakefile +10 -0
  13. data/spec/rails-2.3/app_root/config/boot.rb +114 -0
  14. data/spec/rails-2.3/app_root/config/database.yml +22 -0
  15. data/spec/rails-2.3/app_root/config/environment.rb +45 -0
  16. data/spec/rails-2.3/app_root/config/environments/development.rb +17 -0
  17. data/spec/rails-2.3/app_root/config/environments/production.rb +28 -0
  18. data/spec/rails-2.3/app_root/config/environments/test.rb +28 -0
  19. data/spec/rails-2.3/app_root/config/initializers/backtrace_silencers.rb +7 -0
  20. data/spec/rails-2.3/app_root/config/initializers/cookie_verification_secret.rb +7 -0
  21. data/spec/rails-2.3/app_root/config/initializers/inflections.rb +10 -0
  22. data/spec/rails-2.3/app_root/config/initializers/mime_types.rb +5 -0
  23. data/spec/rails-2.3/app_root/config/initializers/new_rails_defaults.rb +21 -0
  24. data/spec/rails-2.3/app_root/config/initializers/session_store.rb +15 -0
  25. data/spec/rails-2.3/app_root/config/locales/en.yml +5 -0
  26. data/spec/rails-2.3/app_root/config/routes.rb +4 -0
  27. data/spec/rails-2.3/app_root/db/development.sqlite3 +0 -0
  28. data/spec/rails-2.3/app_root/db/seeds.rb +7 -0
  29. data/spec/rails-2.3/app_root/db/test.sqlite3 +0 -0
  30. data/spec/rails-2.3/app_root/doc/README_FOR_APP +2 -0
  31. data/spec/rails-2.3/app_root/log/development.log +43 -0
  32. data/spec/rails-2.3/app_root/log/production.log +0 -0
  33. data/spec/rails-2.3/app_root/log/server.log +0 -0
  34. data/spec/rails-2.3/app_root/log/test.log +380 -0
  35. data/spec/rails-2.3/app_root/public/404.html +30 -0
  36. data/spec/rails-2.3/app_root/public/422.html +30 -0
  37. data/spec/rails-2.3/app_root/public/500.html +30 -0
  38. data/spec/rails-2.3/app_root/public/favicon.ico +0 -0
  39. data/spec/rails-2.3/app_root/public/images/rails.png +0 -0
  40. data/spec/rails-2.3/app_root/public/javascripts/application.js +2 -0
  41. data/spec/rails-2.3/app_root/public/javascripts/controls.js +963 -0
  42. data/spec/rails-2.3/app_root/public/javascripts/dragdrop.js +973 -0
  43. data/spec/rails-2.3/app_root/public/javascripts/effects.js +1128 -0
  44. data/spec/rails-2.3/app_root/public/javascripts/prototype.js +4320 -0
  45. data/spec/rails-2.3/app_root/public/robots.txt +5 -0
  46. data/spec/rails-2.3/app_root/script/about +4 -0
  47. data/spec/rails-2.3/app_root/script/console +3 -0
  48. data/spec/rails-2.3/app_root/script/dbconsole +3 -0
  49. data/spec/rails-2.3/app_root/script/destroy +3 -0
  50. data/spec/rails-2.3/app_root/script/generate +3 -0
  51. data/spec/rails-2.3/app_root/script/performance/benchmarker +3 -0
  52. data/spec/rails-2.3/app_root/script/performance/profiler +3 -0
  53. data/spec/rails-2.3/app_root/script/plugin +3 -0
  54. data/spec/rails-2.3/app_root/script/runner +3 -0
  55. data/spec/rails-2.3/app_root/script/server +3 -0
  56. data/spec/rails-2.3/app_root/test/performance/browsing_test.rb +9 -0
  57. data/spec/rails-2.3/app_root/test/test_helper.rb +38 -0
  58. data/spec/rails-2.3/spec/spec.opts +4 -0
  59. data/spec/rails-2.3/spec/spec_helper.rb +59 -0
  60. data/spec/rails-3.2/Gemfile +14 -0
  61. data/spec/rails-3.2/Gemfile.lock +146 -0
  62. data/spec/rails-3.2/Rakefile +10 -0
  63. data/spec/rails-3.2/app_root/README.rdoc +261 -0
  64. data/spec/rails-3.2/app_root/config.ru +4 -0
  65. data/spec/rails-3.2/app_root/config/application.rb +59 -0
  66. data/spec/rails-3.2/app_root/config/boot.rb +10 -0
  67. data/spec/rails-3.2/app_root/config/database.yml +25 -0
  68. data/spec/rails-3.2/app_root/config/environment.rb +5 -0
  69. data/spec/rails-3.2/app_root/config/environments/development.rb +37 -0
  70. data/spec/rails-3.2/app_root/config/environments/production.rb +67 -0
  71. data/spec/rails-3.2/app_root/config/environments/test.rb +37 -0
  72. data/spec/rails-3.2/app_root/config/initializers/backtrace_silencers.rb +7 -0
  73. data/spec/rails-3.2/app_root/config/initializers/inflections.rb +15 -0
  74. data/spec/rails-3.2/app_root/config/initializers/mime_types.rb +5 -0
  75. data/spec/rails-3.2/app_root/config/initializers/secret_token.rb +7 -0
  76. data/spec/rails-3.2/app_root/config/initializers/session_store.rb +8 -0
  77. data/spec/rails-3.2/app_root/config/initializers/wrap_parameters.rb +14 -0
  78. data/spec/rails-3.2/app_root/config/locales/en.yml +5 -0
  79. data/spec/rails-3.2/app_root/config/routes.rb +61 -0
  80. data/spec/rails-3.2/app_root/db/development.sqlite3 +0 -0
  81. data/spec/rails-3.2/app_root/db/test.sqlite3 +0 -0
  82. data/spec/rails-3.2/app_root/log/development.log +75 -0
  83. data/spec/rails-3.2/app_root/log/test.log +883 -0
  84. data/spec/rails-3.2/app_root/public/404.html +26 -0
  85. data/spec/rails-3.2/app_root/public/422.html +26 -0
  86. data/spec/rails-3.2/app_root/public/500.html +25 -0
  87. data/spec/rails-3.2/app_root/public/favicon.ico +0 -0
  88. data/spec/rails-3.2/app_root/script/rails +6 -0
  89. data/spec/rails-3.2/spec/spec_helper.rb +47 -0
  90. data/spec/shared/app_root/app/assets/javascripts/application.js +15 -0
  91. data/spec/shared/app_root/app/assets/stylesheets/application.css +13 -0
  92. data/spec/shared/app_root/app/controllers/application_controller.rb +3 -0
  93. data/spec/shared/app_root/app/controllers/dummy_controller.rb +5 -0
  94. data/spec/shared/app_root/app/controllers/env_controller.rb +5 -0
  95. data/spec/shared/app_root/app/helpers/application_helper.rb +2 -0
  96. data/spec/shared/app_root/app/views/layouts/application.html.erb +14 -0
  97. data/spec/shared/heroku-true-relic/heroku-true-relic_spec.rb +44 -0
  98. metadata +366 -0
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
4
+ require 'commands/about'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/console'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/dbconsole'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/destroy'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/generate'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../../config/boot', __FILE__)
3
+ require 'commands/performance/benchmarker'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../../config/boot', __FILE__)
3
+ require 'commands/performance/profiler'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/plugin'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/runner'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/server'
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+ require 'performance_test_help'
3
+
4
+ # Profiling results for each test method are written to tmp/performance.
5
+ class BrowsingTest < ActionController::PerformanceTest
6
+ def test_homepage
7
+ get '/'
8
+ end
9
+ end
@@ -0,0 +1,38 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
3
+ require 'test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Transactional fixtures accelerate your tests by wrapping each test method
7
+ # in a transaction that's rolled back on completion. This ensures that the
8
+ # test database remains unchanged so your fixtures don't have to be reloaded
9
+ # between every test method. Fewer database queries means faster tests.
10
+ #
11
+ # Read Mike Clark's excellent walkthrough at
12
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
13
+ #
14
+ # Every Active Record database supports transactions except MyISAM tables
15
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
16
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
17
+ # is recommended.
18
+ #
19
+ # The only drawback to using transactional fixtures is when you actually
20
+ # need to test transactions. Since your test is bracketed by a transaction,
21
+ # any transactions started in your code will be automatically rolled back.
22
+ self.use_transactional_fixtures = true
23
+
24
+ # Instantiated fixtures are slow, but give you @david where otherwise you
25
+ # would need people(:david). If you don't want to migrate your existing
26
+ # test cases which use the @david style and don't mind the speed hit (each
27
+ # instantiated fixtures translates to a database query per test method),
28
+ # then set this back to true.
29
+ self.use_instantiated_fixtures = false
30
+
31
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
32
+ #
33
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
34
+ # -- they do not yet inherit this setting
35
+ fixtures :all
36
+
37
+ # Add more helper methods to be used by all tests here...
38
+ end
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,59 @@
1
+ # This file is copied to ~/spec when you run 'ruby script/generate rspec'
2
+ # from the project root directory.
3
+ ENV["RAILS_ENV"] ||= 'test'
4
+ require File.expand_path("../../app_root/config/environment.rb", __FILE__)
5
+ require 'spec/autorun'
6
+ require 'spec/rails'
7
+
8
+ require 'rubygems'
9
+ require 'pry'
10
+ require 'capybara/rails'
11
+ require 'timecop'
12
+
13
+ # Uncomment the next line to use webrat's matchers
14
+ #require 'webrat/integrations/rspec-rails'
15
+
16
+ # Requires supporting files with custom matchers and macros, etc,
17
+ # in ./support/ and its subdirectories.
18
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
19
+
20
+ Spec::Runner.configure do |config|
21
+ # If you're not using ActiveRecord you should remove these
22
+ # lines, delete config/database.yml and disable :active_record
23
+ # in your config/boot.rb
24
+ config.use_transactional_fixtures = true
25
+ config.use_instantiated_fixtures = false
26
+ config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
27
+
28
+ # == Fixtures
29
+ #
30
+ # You can declare fixtures for each example_group like this:
31
+ # describe "...." do
32
+ # fixtures :table_a, :table_b
33
+ #
34
+ # Alternatively, if you prefer to declare them only once, you can
35
+ # do so right here. Just uncomment the next line and replace the fixture
36
+ # names with your fixtures.
37
+ #
38
+ # config.global_fixtures = :table_a, :table_b
39
+ #
40
+ # If you declare global fixtures, be aware that they will be declared
41
+ # for all of your examples, even those that don't use them.
42
+ #
43
+ # You can also declare which fixtures to use (for example fixtures for test/fixtures):
44
+ #
45
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
46
+ #
47
+ # == Mock Framework
48
+ #
49
+ # RSpec uses its own mocking framework by default. If you prefer to
50
+ # use mocha, flexmock or RR, uncomment the appropriate line:
51
+ #
52
+ # config.mock_with :mocha
53
+ # config.mock_with :flexmock
54
+ # config.mock_with :rr
55
+ #
56
+ # == Notes
57
+ #
58
+ # For more information take a look at Spec::Runner::Configuration and Spec::Runner
59
+ end
@@ -0,0 +1,14 @@
1
+ source :rubygems
2
+
3
+ gem "rails", "~> 3.2.12"
4
+ gem "sqlite3"
5
+ gem 'heroku-true-relic', :path => '../..'
6
+
7
+ group :test, :development do
8
+ gem "rspec"
9
+ gem "rspec-rails"
10
+ gem "pry"
11
+ gem "pry-rails"
12
+ gem "capybara"
13
+ gem "timecop"
14
+ end
@@ -0,0 +1,146 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ heroku-true-relic (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ actionmailer (3.2.12)
10
+ actionpack (= 3.2.12)
11
+ mail (~> 2.4.4)
12
+ actionpack (3.2.12)
13
+ activemodel (= 3.2.12)
14
+ activesupport (= 3.2.12)
15
+ builder (~> 3.0.0)
16
+ erubis (~> 2.7.0)
17
+ journey (~> 1.0.4)
18
+ rack (~> 1.4.5)
19
+ rack-cache (~> 1.2)
20
+ rack-test (~> 0.6.1)
21
+ sprockets (~> 2.2.1)
22
+ activemodel (3.2.12)
23
+ activesupport (= 3.2.12)
24
+ builder (~> 3.0.0)
25
+ activerecord (3.2.12)
26
+ activemodel (= 3.2.12)
27
+ activesupport (= 3.2.12)
28
+ arel (~> 3.0.2)
29
+ tzinfo (~> 0.3.29)
30
+ activeresource (3.2.12)
31
+ activemodel (= 3.2.12)
32
+ activesupport (= 3.2.12)
33
+ activesupport (3.2.12)
34
+ i18n (~> 0.6)
35
+ multi_json (~> 1.0)
36
+ arel (3.0.2)
37
+ builder (3.0.4)
38
+ capybara (2.0.2)
39
+ mime-types (>= 1.16)
40
+ nokogiri (>= 1.3.3)
41
+ rack (>= 1.0.0)
42
+ rack-test (>= 0.5.4)
43
+ selenium-webdriver (~> 2.0)
44
+ xpath (~> 1.0.0)
45
+ childprocess (0.3.8)
46
+ ffi (~> 1.0, >= 1.0.11)
47
+ coderay (1.0.8)
48
+ diff-lcs (1.1.3)
49
+ erubis (2.7.0)
50
+ ffi (1.4.0)
51
+ hike (1.2.1)
52
+ i18n (0.6.1)
53
+ journey (1.0.4)
54
+ json (1.7.7)
55
+ mail (2.4.4)
56
+ i18n (>= 0.4.0)
57
+ mime-types (~> 1.16)
58
+ treetop (~> 1.4.8)
59
+ method_source (0.8.1)
60
+ mime-types (1.21)
61
+ multi_json (1.6.1)
62
+ nokogiri (1.5.6)
63
+ polyglot (0.3.3)
64
+ pry (0.9.12)
65
+ coderay (~> 1.0.5)
66
+ method_source (~> 0.8)
67
+ slop (~> 3.4)
68
+ pry-rails (0.2.2)
69
+ pry (>= 0.9.10)
70
+ rack (1.4.5)
71
+ rack-cache (1.2)
72
+ rack (>= 0.4)
73
+ rack-ssl (1.3.3)
74
+ rack
75
+ rack-test (0.6.2)
76
+ rack (>= 1.0)
77
+ rails (3.2.12)
78
+ actionmailer (= 3.2.12)
79
+ actionpack (= 3.2.12)
80
+ activerecord (= 3.2.12)
81
+ activeresource (= 3.2.12)
82
+ activesupport (= 3.2.12)
83
+ bundler (~> 1.0)
84
+ railties (= 3.2.12)
85
+ railties (3.2.12)
86
+ actionpack (= 3.2.12)
87
+ activesupport (= 3.2.12)
88
+ rack-ssl (~> 1.3.2)
89
+ rake (>= 0.8.7)
90
+ rdoc (~> 3.4)
91
+ thor (>= 0.14.6, < 2.0)
92
+ rake (10.0.3)
93
+ rdoc (3.12.1)
94
+ json (~> 1.4)
95
+ rspec (2.12.0)
96
+ rspec-core (~> 2.12.0)
97
+ rspec-expectations (~> 2.12.0)
98
+ rspec-mocks (~> 2.12.0)
99
+ rspec-core (2.12.2)
100
+ rspec-expectations (2.12.1)
101
+ diff-lcs (~> 1.1.3)
102
+ rspec-mocks (2.12.2)
103
+ rspec-rails (2.12.2)
104
+ actionpack (>= 3.0)
105
+ activesupport (>= 3.0)
106
+ railties (>= 3.0)
107
+ rspec-core (~> 2.12.0)
108
+ rspec-expectations (~> 2.12.0)
109
+ rspec-mocks (~> 2.12.0)
110
+ rubyzip (0.9.9)
111
+ selenium-webdriver (2.29.0)
112
+ childprocess (>= 0.2.5)
113
+ multi_json (~> 1.0)
114
+ rubyzip
115
+ websocket (~> 1.0.4)
116
+ slop (3.4.3)
117
+ sprockets (2.2.2)
118
+ hike (~> 1.2)
119
+ multi_json (~> 1.0)
120
+ rack (~> 1.0)
121
+ tilt (~> 1.1, != 1.3.0)
122
+ sqlite3 (1.3.7)
123
+ thor (0.17.0)
124
+ tilt (1.3.3)
125
+ timecop (0.5.9.2)
126
+ treetop (1.4.12)
127
+ polyglot
128
+ polyglot (>= 0.3.1)
129
+ tzinfo (0.3.35)
130
+ websocket (1.0.7)
131
+ xpath (1.0.0)
132
+ nokogiri (~> 1.3)
133
+
134
+ PLATFORMS
135
+ ruby
136
+
137
+ DEPENDENCIES
138
+ capybara
139
+ heroku-true-relic!
140
+ pry
141
+ pry-rails
142
+ rails (~> 3.2.12)
143
+ rspec
144
+ rspec-rails
145
+ sqlite3
146
+ timecop
@@ -0,0 +1,10 @@
1
+ require 'rake'
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc 'Default: Run all specs for a specific rails version.'
5
+ task :default => :spec
6
+
7
+ desc "Run all specs for a specific rails version"
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ # t.pattern = ['**/*_spec.rb', '../shared/**/*_spec.rb']
10
+ end
@@ -0,0 +1,261 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application framework that includes everything needed to create
4
+ database-backed web applications according to the Model-View-Control pattern.
5
+
6
+ This pattern splits the view (also called the presentation) into "dumb"
7
+ templates that are primarily responsible for inserting pre-built data in between
8
+ HTML tags. The model contains the "smart" domain objects (such as Account,
9
+ Product, Person, Post) that holds all the business logic and knows how to
10
+ persist themselves to a database. The controller handles the incoming requests
11
+ (such as Save New Account, Update Product, Show Post) by manipulating the model
12
+ and directing data to the view.
13
+
14
+ In Rails, the model is handled by what's called an object-relational mapping
15
+ layer entitled Active Record. This layer allows you to present the data from
16
+ database rows as objects and embellish these data objects with business logic
17
+ methods. You can read more about Active Record in
18
+ link:files/vendor/rails/activerecord/README.html.
19
+
20
+ The controller and view are handled by the Action Pack, which handles both
21
+ layers by its two parts: Action View and Action Controller. These two layers
22
+ are bundled in a single package due to their heavy interdependence. This is
23
+ unlike the relationship between the Active Record and Action Pack that is much
24
+ more separate. Each of these packages can be used independently outside of
25
+ Rails. You can read more about Action Pack in
26
+ link:files/vendor/rails/actionpack/README.html.
27
+
28
+
29
+ == Getting Started
30
+
31
+ 1. At the command prompt, create a new Rails application:
32
+ <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
33
+
34
+ 2. Change directory to <tt>myapp</tt> and start the web server:
35
+ <tt>cd myapp; rails server</tt> (run with --help for options)
36
+
37
+ 3. Go to http://localhost:3000/ and you'll see:
38
+ "Welcome aboard: You're riding Ruby on Rails!"
39
+
40
+ 4. Follow the guidelines to start developing your application. You can find
41
+ the following resources handy:
42
+
43
+ * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
44
+ * Ruby on Rails Tutorial Book: http://www.railstutorial.org/
45
+
46
+
47
+ == Debugging Rails
48
+
49
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
50
+ will help you debug it and get it back on the rails.
51
+
52
+ First area to check is the application log files. Have "tail -f" commands
53
+ running on the server.log and development.log. Rails will automatically display
54
+ debugging and runtime information to these files. Debugging info will also be
55
+ shown in the browser on requests from 127.0.0.1.
56
+
57
+ You can also log your own messages directly into the log file from your code
58
+ using the Ruby logger class from inside your controllers. Example:
59
+
60
+ class WeblogController < ActionController::Base
61
+ def destroy
62
+ @weblog = Weblog.find(params[:id])
63
+ @weblog.destroy
64
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
65
+ end
66
+ end
67
+
68
+ The result will be a message in your log file along the lines of:
69
+
70
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
71
+
72
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
73
+
74
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
75
+ several books available online as well:
76
+
77
+ * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
78
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
79
+
80
+ These two books will bring you up to speed on the Ruby language and also on
81
+ programming in general.
82
+
83
+
84
+ == Debugger
85
+
86
+ Debugger support is available through the debugger command when you start your
87
+ Mongrel or WEBrick server with --debugger. This means that you can break out of
88
+ execution at any point in the code, investigate and change the model, and then,
89
+ resume execution! You need to install ruby-debug to run the server in debugging
90
+ mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
91
+
92
+ class WeblogController < ActionController::Base
93
+ def index
94
+ @posts = Post.all
95
+ debugger
96
+ end
97
+ end
98
+
99
+ So the controller will accept the action, run the first line, then present you
100
+ with a IRB prompt in the server window. Here you can do things like:
101
+
102
+ >> @posts.inspect
103
+ => "[#<Post:0x14a6be8
104
+ @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
105
+ #<Post:0x14a6620
106
+ @attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
107
+ >> @posts.first.title = "hello from a debugger"
108
+ => "hello from a debugger"
109
+
110
+ ...and even better, you can examine how your runtime objects actually work:
111
+
112
+ >> f = @posts.first
113
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
114
+ >> f.
115
+ Display all 152 possibilities? (y or n)
116
+
117
+ Finally, when you're ready to resume execution, you can enter "cont".
118
+
119
+
120
+ == Console
121
+
122
+ The console is a Ruby shell, which allows you to interact with your
123
+ application's domain model. Here you'll have all parts of the application
124
+ configured, just like it is when the application is running. You can inspect
125
+ domain models, change values, and save to the database. Starting the script
126
+ without arguments will launch it in the development environment.
127
+
128
+ To start the console, run <tt>rails console</tt> from the application
129
+ directory.
130
+
131
+ Options:
132
+
133
+ * Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
134
+ made to the database.
135
+ * Passing an environment name as an argument will load the corresponding
136
+ environment. Example: <tt>rails console production</tt>.
137
+
138
+ To reload your controllers and models after launching the console run
139
+ <tt>reload!</tt>
140
+
141
+ More information about irb can be found at:
142
+ link:http://www.rubycentral.org/pickaxe/irb.html
143
+
144
+
145
+ == dbconsole
146
+
147
+ You can go to the command line of your database directly through <tt>rails
148
+ dbconsole</tt>. You would be connected to the database with the credentials
149
+ defined in database.yml. Starting the script without arguments will connect you
150
+ to the development database. Passing an argument will connect you to a different
151
+ database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
152
+ PostgreSQL and SQLite 3.
153
+
154
+ == Description of Contents
155
+
156
+ The default directory structure of a generated Ruby on Rails application:
157
+
158
+ |-- app
159
+ | |-- assets
160
+ | |-- images
161
+ | |-- javascripts
162
+ | `-- stylesheets
163
+ | |-- controllers
164
+ | |-- helpers
165
+ | |-- mailers
166
+ | |-- models
167
+ | `-- views
168
+ | `-- layouts
169
+ |-- config
170
+ | |-- environments
171
+ | |-- initializers
172
+ | `-- locales
173
+ |-- db
174
+ |-- doc
175
+ |-- lib
176
+ | `-- tasks
177
+ |-- log
178
+ |-- public
179
+ |-- script
180
+ |-- test
181
+ | |-- fixtures
182
+ | |-- functional
183
+ | |-- integration
184
+ | |-- performance
185
+ | `-- unit
186
+ |-- tmp
187
+ | |-- cache
188
+ | |-- pids
189
+ | |-- sessions
190
+ | `-- sockets
191
+ `-- vendor
192
+ |-- assets
193
+ `-- stylesheets
194
+ `-- plugins
195
+
196
+ app
197
+ Holds all the code that's specific to this particular application.
198
+
199
+ app/assets
200
+ Contains subdirectories for images, stylesheets, and JavaScript files.
201
+
202
+ app/controllers
203
+ Holds controllers that should be named like weblogs_controller.rb for
204
+ automated URL mapping. All controllers should descend from
205
+ ApplicationController which itself descends from ActionController::Base.
206
+
207
+ app/models
208
+ Holds models that should be named like post.rb. Models descend from
209
+ ActiveRecord::Base by default.
210
+
211
+ app/views
212
+ Holds the template files for the view that should be named like
213
+ weblogs/index.html.erb for the WeblogsController#index action. All views use
214
+ eRuby syntax by default.
215
+
216
+ app/views/layouts
217
+ Holds the template files for layouts to be used with views. This models the
218
+ common header/footer method of wrapping views. In your views, define a layout
219
+ using the <tt>layout :default</tt> and create a file named default.html.erb.
220
+ Inside default.html.erb, call <% yield %> to render the view using this
221
+ layout.
222
+
223
+ app/helpers
224
+ Holds view helpers that should be named like weblogs_helper.rb. These are
225
+ generated for you automatically when using generators for controllers.
226
+ Helpers can be used to wrap functionality for your views into methods.
227
+
228
+ config
229
+ Configuration files for the Rails environment, the routing map, the database,
230
+ and other dependencies.
231
+
232
+ db
233
+ Contains the database schema in schema.rb. db/migrate contains all the
234
+ sequence of Migrations for your schema.
235
+
236
+ doc
237
+ This directory is where your application documentation will be stored when
238
+ generated using <tt>rake doc:app</tt>
239
+
240
+ lib
241
+ Application specific libraries. Basically, any kind of custom code that
242
+ doesn't belong under controllers, models, or helpers. This directory is in
243
+ the load path.
244
+
245
+ public
246
+ The directory available for the web server. Also contains the dispatchers and the
247
+ default HTML files. This should be set as the DOCUMENT_ROOT of your web
248
+ server.
249
+
250
+ script
251
+ Helper scripts for automation and generation.
252
+
253
+ test
254
+ Unit and functional tests along with fixtures. When using the rails generate
255
+ command, template test files will be generated for you and placed in this
256
+ directory.
257
+
258
+ vendor
259
+ External libraries that the application depends on. Also includes the plugins
260
+ subdirectory. If the app has frozen rails, those gems also go here, under
261
+ vendor/rails/. This directory is in the load path.