authorails 1.0.0
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.
- data/AUTHORAILS_README +20 -0
- data/CHANGELOG +1366 -0
- data/MIT-LICENSE +20 -0
- data/README +182 -0
- data/Rakefile +334 -0
- data/bin/about +3 -0
- data/bin/authorails +19 -0
- data/bin/breakpointer +3 -0
- data/bin/console +3 -0
- data/bin/destroy +3 -0
- data/bin/generate +3 -0
- data/bin/performance/benchmarker +3 -0
- data/bin/performance/profiler +3 -0
- data/bin/plugin +3 -0
- data/bin/process/inspector +3 -0
- data/bin/process/reaper +3 -0
- data/bin/process/spawner +3 -0
- data/bin/runner +3 -0
- data/bin/server +3 -0
- data/builtin/rails_info/rails/info.rb +123 -0
- data/builtin/rails_info/rails/info_controller.rb +9 -0
- data/builtin/rails_info/rails/info_helper.rb +2 -0
- data/builtin/rails_info/rails_info_controller.rb +2 -0
- data/configs/apache.conf +40 -0
- data/configs/databases/frontbase.yml +28 -0
- data/configs/databases/mysql.yml +48 -0
- data/configs/databases/oracle.yml +39 -0
- data/configs/databases/postgresql.yml +44 -0
- data/configs/databases/sqlite2.yml +16 -0
- data/configs/databases/sqlite3.yml +19 -0
- data/configs/empty.log +0 -0
- data/configs/lighttpd.conf +54 -0
- data/configs/routes.rb +23 -0
- data/controllers/accounts_controller.rb +11 -0
- data/controllers/admin_controller.rb +76 -0
- data/controllers/begin_controller.rb +5 -0
- data/controllers/login_controller.rb +101 -0
- data/controllers/permission_controller.rb +91 -0
- data/controllers/roles_controller.rb +58 -0
- data/controllers/tables_controller.rb +714 -0
- data/dispatches/dispatch.fcgi +24 -0
- data/dispatches/dispatch.rb +10 -0
- data/dispatches/gateway.cgi +97 -0
- data/doc/README_FOR_APP +2 -0
- data/environments/boot.rb +45 -0
- data/environments/development.rb +21 -0
- data/environments/environment.rb +63 -0
- data/environments/production.rb +18 -0
- data/environments/test.rb +19 -0
- data/fresh_rakefile +10 -0
- data/helpers/application.rb +607 -0
- data/helpers/application_helper.rb +315 -0
- data/helpers/permission_helper.rb +27 -0
- data/helpers/test_helper.rb +28 -0
- data/html/404.html +30 -0
- data/html/500.html +30 -0
- data/html/favicon.ico +0 -0
- data/html/images/ArrowDn.png +0 -0
- data/html/images/ArrowUp.png +0 -0
- data/html/images/arrow.gif +0 -0
- data/html/images/authorails_logo.gif +0 -0
- data/html/images/delete.png +0 -0
- data/html/images/edit.png +0 -0
- data/html/images/minus.gif +0 -0
- data/html/images/plus.gif +0 -0
- data/html/images/rails.png +0 -0
- data/html/images/show.png +0 -0
- data/html/images/spinner.gif +0 -0
- data/html/index.html +273 -0
- data/html/javascripts/application.js +2 -0
- data/html/javascripts/controls.js +833 -0
- data/html/javascripts/dragdrop.js +942 -0
- data/html/javascripts/effects.js +1088 -0
- data/html/javascripts/live_validation.js +4 -0
- data/html/javascripts/prototype.js +2515 -0
- data/html/robots.txt +1 -0
- data/lib/authorails/version.rb +9 -0
- data/lib/binding_of_caller.rb +85 -0
- data/lib/breakpoint.rb +553 -0
- data/lib/breakpoint_client.rb +196 -0
- data/lib/code_statistics.rb +107 -0
- data/lib/commands.rb +17 -0
- data/lib/commands/about.rb +2 -0
- data/lib/commands/breakpointer.rb +1 -0
- data/lib/commands/console.rb +25 -0
- data/lib/commands/destroy.rb +6 -0
- data/lib/commands/generate.rb +6 -0
- data/lib/commands/ncgi/listener +86 -0
- data/lib/commands/ncgi/tracker +69 -0
- data/lib/commands/performance/benchmarker.rb +24 -0
- data/lib/commands/performance/profiler.rb +50 -0
- data/lib/commands/plugin.rb +918 -0
- data/lib/commands/process/inspector.rb +68 -0
- data/lib/commands/process/reaper.rb +149 -0
- data/lib/commands/process/spawner.rb +209 -0
- data/lib/commands/process/spinner.rb +57 -0
- data/lib/commands/runner.rb +48 -0
- data/lib/commands/server.rb +39 -0
- data/lib/commands/servers/base.rb +19 -0
- data/lib/commands/servers/lighttpd.rb +94 -0
- data/lib/commands/servers/mongrel.rb +65 -0
- data/lib/commands/servers/webrick.rb +59 -0
- data/lib/commands/update.rb +4 -0
- data/lib/console_app.rb +27 -0
- data/lib/console_sandbox.rb +6 -0
- data/lib/console_with_helpers.rb +23 -0
- data/lib/dispatcher.rb +173 -0
- data/lib/fcgi_handler.rb +225 -0
- data/lib/initializer.rb +702 -0
- data/lib/rails_generator.rb +43 -0
- data/lib/rails_generator/base.rb +261 -0
- data/lib/rails_generator/commands.rb +581 -0
- data/lib/rails_generator/generated_attribute.rb +42 -0
- data/lib/rails_generator/generators/applications/app/USAGE +16 -0
- data/lib/rails_generator/generators/applications/app/app_generator.rb +341 -0
- data/lib/rails_generator/generators/components/controller/USAGE +30 -0
- data/lib/rails_generator/generators/components/controller/controller_generator.rb +37 -0
- data/lib/rails_generator/generators/components/controller/templates/controller.rb +10 -0
- data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +18 -0
- data/lib/rails_generator/generators/components/controller/templates/helper.rb +2 -0
- data/lib/rails_generator/generators/components/controller/templates/view.rhtml +2 -0
- data/lib/rails_generator/generators/components/integration_test/USAGE +14 -0
- data/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb +16 -0
- data/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +10 -0
- data/lib/rails_generator/generators/components/mailer/USAGE +18 -0
- data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +34 -0
- data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +3 -0
- data/lib/rails_generator/generators/components/mailer/templates/mailer.rb +13 -0
- data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +37 -0
- data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +3 -0
- data/lib/rails_generator/generators/components/migration/USAGE +14 -0
- data/lib/rails_generator/generators/components/migration/migration_generator.rb +7 -0
- data/lib/rails_generator/generators/components/migration/templates/migration.rb +7 -0
- data/lib/rails_generator/generators/components/model/USAGE +26 -0
- data/lib/rails_generator/generators/components/model/model_generator.rb +38 -0
- data/lib/rails_generator/generators/components/model/templates/fixtures.yml +11 -0
- data/lib/rails_generator/generators/components/model/templates/migration.rb +13 -0
- data/lib/rails_generator/generators/components/model/templates/model.rb +2 -0
- data/lib/rails_generator/generators/components/model/templates/unit_test.rb +10 -0
- data/lib/rails_generator/generators/components/observer/USAGE +15 -0
- data/lib/rails_generator/generators/components/observer/observer_generator.rb +16 -0
- data/lib/rails_generator/generators/components/observer/templates/observer.rb +2 -0
- data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +10 -0
- data/lib/rails_generator/generators/components/plugin/USAGE +35 -0
- data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +38 -0
- data/lib/rails_generator/generators/components/plugin/templates/README +4 -0
- data/lib/rails_generator/generators/components/plugin/templates/Rakefile +22 -0
- data/lib/rails_generator/generators/components/plugin/templates/USAGE +8 -0
- data/lib/rails_generator/generators/components/plugin/templates/generator.rb +8 -0
- data/lib/rails_generator/generators/components/plugin/templates/init.rb +1 -0
- data/lib/rails_generator/generators/components/plugin/templates/install.rb +1 -0
- data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +1 -0
- data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +4 -0
- data/lib/rails_generator/generators/components/plugin/templates/uninstall.rb +1 -0
- data/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +8 -0
- data/lib/rails_generator/generators/components/resource/resource_generator.rb +76 -0
- data/lib/rails_generator/generators/components/resource/templates/USAGE +18 -0
- data/lib/rails_generator/generators/components/resource/templates/controller.rb +2 -0
- data/lib/rails_generator/generators/components/resource/templates/fixtures.yml +11 -0
- data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +20 -0
- data/lib/rails_generator/generators/components/resource/templates/helper.rb +2 -0
- data/lib/rails_generator/generators/components/resource/templates/migration.rb +13 -0
- data/lib/rails_generator/generators/components/resource/templates/model.rb +2 -0
- data/lib/rails_generator/generators/components/resource/templates/unit_test.rb +10 -0
- data/lib/rails_generator/generators/components/scaffold/USAGE +32 -0
- data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +208 -0
- data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +134 -0
- data/lib/rails_generator/generators/components/scaffold/templates/form.rhtml +3 -0
- data/lib/rails_generator/generators/components/scaffold/templates/form_scaffolding.rhtml +35 -0
- data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +102 -0
- data/lib/rails_generator/generators/components/scaffold/templates/helper.rb +2 -0
- data/lib/rails_generator/generators/components/scaffold/templates/layout.rhtml +17 -0
- data/lib/rails_generator/generators/components/scaffold/templates/partial_list_elements.rhtml +127 -0
- data/lib/rails_generator/generators/components/scaffold/templates/style.css +74 -0
- data/lib/rails_generator/generators/components/scaffold/templates/view_edit.rhtml +75 -0
- data/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml +30 -0
- data/lib/rails_generator/generators/components/scaffold/templates/view_new.rhtml +8 -0
- data/lib/rails_generator/generators/components/scaffold/templates/view_show.rhtml +37 -0
- data/lib/rails_generator/generators/components/scaffold_resource/USAGE +29 -0
- data/lib/rails_generator/generators/components/scaffold_resource/scaffold_resource_generator.rb +92 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/controller.rb +79 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/fixtures.yml +11 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/functional_test.rb +57 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/helper.rb +2 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/layout.rhtml +17 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/migration.rb +13 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/model.rb +2 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/style.css +74 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/unit_test.rb +10 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/view_edit.rhtml +19 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/view_index.rhtml +24 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/view_new.rhtml +18 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/view_show.rhtml +10 -0
- data/lib/rails_generator/generators/components/session_migration/USAGE +15 -0
- data/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb +18 -0
- data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +16 -0
- data/lib/rails_generator/generators/components/web_service/USAGE +28 -0
- data/lib/rails_generator/generators/components/web_service/templates/api_definition.rb +5 -0
- data/lib/rails_generator/generators/components/web_service/templates/controller.rb +8 -0
- data/lib/rails_generator/generators/components/web_service/templates/functional_test.rb +19 -0
- data/lib/rails_generator/generators/components/web_service/web_service_generator.rb +29 -0
- data/lib/rails_generator/lookup.rb +209 -0
- data/lib/rails_generator/manifest.rb +53 -0
- data/lib/rails_generator/options.rb +143 -0
- data/lib/rails_generator/scripts.rb +83 -0
- data/lib/rails_generator/scripts/destroy.rb +7 -0
- data/lib/rails_generator/scripts/generate.rb +7 -0
- data/lib/rails_generator/scripts/update.rb +12 -0
- data/lib/rails_generator/simple_logger.rb +46 -0
- data/lib/rails_generator/spec.rb +44 -0
- data/lib/railties_path.rb +1 -0
- data/lib/ruby_version_check.rb +17 -0
- data/lib/rubyprof_ext.rb +35 -0
- data/lib/tasks/databases.rake +187 -0
- data/lib/tasks/documentation.rake +82 -0
- data/lib/tasks/framework.rake +112 -0
- data/lib/tasks/log.rake +9 -0
- data/lib/tasks/misc.rake +4 -0
- data/lib/tasks/pre_namespace_aliases.rake +53 -0
- data/lib/tasks/rails.rb +8 -0
- data/lib/tasks/statistics.rake +18 -0
- data/lib/tasks/testing.rake +120 -0
- data/lib/tasks/tmp.rake +37 -0
- data/lib/test_help.rb +19 -0
- data/lib/webrick_server.rb +166 -0
- data/libs/migration_helper.rb +11 -0
- data/migrations/001_create_logins.rb +22 -0
- data/migrations/002_create_admins.rb +16 -0
- data/migrations/003_create_roles.rb +13 -0
- data/migrations/004_create_tables.rb +11 -0
- data/migrations/005_create_attr_types.rb +13 -0
- data/migrations/006_create_table_fields.rb +22 -0
- data/migrations/007_create_tab_operations.rb +13 -0
- data/migrations/008_create_attr_operations.rb +13 -0
- data/migrations/009_create_tab_permissions.rb +21 -0
- data/migrations/010_create_attr_permissions.rb +21 -0
- data/migrations/011_create_relations.rb +23 -0
- data/migrations/012_create_scaffolds.rb +11 -0
- data/migrations/013_create_relation_permissions.rb +20 -0
- data/models/admin.rb +38 -0
- data/models/attr_operation.rb +3 -0
- data/models/attr_permission.rb +5 -0
- data/models/attr_type.rb +3 -0
- data/models/login.rb +51 -0
- data/models/relation.rb +5 -0
- data/models/relation_permission.rb +4 -0
- data/models/role.rb +13 -0
- data/models/scaffold.rb +2 -0
- data/models/tab_operation.rb +3 -0
- data/models/tab_permission.rb +5 -0
- data/models/table.rb +18 -0
- data/models/table_field.rb +6 -0
- data/plugins/redhillonrails_core/CHANGELOG +186 -0
- data/plugins/redhillonrails_core/MIT-LICENSE +20 -0
- data/plugins/redhillonrails_core/README +152 -0
- data/plugins/redhillonrails_core/init.rb +1 -0
- data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb +54 -0
- data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/abstract_adapter.rb +46 -0
- data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/column.rb +21 -0
- data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb +26 -0
- data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/index_definition.rb +11 -0
- data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/mysql_adapter.rb +94 -0
- data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/mysql_column.rb +8 -0
- data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/postgresql_adapter.rb +131 -0
- data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/schema_statements.rb +23 -0
- data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/sqlite3_adapter.rb +9 -0
- data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/table_definition.rb +27 -0
- data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema.rb +25 -0
- data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb +58 -0
- data/plugins/redhillonrails_core/lib/redhillonrails_core.rb +19 -0
- data/plugins/redhillonrails_core/tasks/db/comments.rake +9 -0
- data/plugins/schema_validations/CHANGELOG +149 -0
- data/plugins/schema_validations/MIT-LICENSE +20 -0
- data/plugins/schema_validations/README +54 -0
- data/plugins/schema_validations/about.yml +5 -0
- data/plugins/schema_validations/init.rb +1 -0
- data/plugins/schema_validations/install.rb +1 -0
- data/plugins/schema_validations/lib/red_hill_consulting/schema_validations/active_record/base.rb +108 -0
- data/plugins/schema_validations/lib/schema_validations.rb +1 -0
- data/plugins/svn/README +69 -0
- data/plugins/svn/Rakefile +22 -0
- data/plugins/svn/assets/javascripts/live_validation.js +4 -0
- data/plugins/svn/assets/stylesheets/live_validation.css +28 -0
- data/plugins/svn/init.rb +2 -0
- data/plugins/svn/install.rb +1 -0
- data/plugins/svn/lib/form_helpers.rb +49 -0
- data/plugins/svn/lib/live_validations.rb +73 -0
- data/plugins/svn/tasks/live_validation_tasks.rake +17 -0
- data/plugins/svn/test/form_helpers_test.rb +214 -0
- data/plugins/svn/test/live_validations_test.rb +124 -0
- data/plugins/svn/test/resource.rb +17 -0
- data/plugins/svn/uninstall.rb +1 -0
- data/stylesheets/live_validation.css +28 -0
- data/stylesheets/print.css +72 -0
- data/stylesheets/scaffold.css +175 -0
- data/views/accounts/index.rhtml +12 -0
- data/views/accounts/show.rhtml +5 -0
- data/views/admin/_form.rhtml +15 -0
- data/views/admin/add_user.rhtml +21 -0
- data/views/admin/change_pwd.rhtml +23 -0
- data/views/admin/edit_user.rhtml +12 -0
- data/views/admin/index.rhtml +19 -0
- data/views/begin/index.rhtml +0 -0
- data/views/layouts/general.rhtml +59 -0
- data/views/layouts/login.rhtml +18 -0
- data/views/login/change_pwd.rhtml +21 -0
- data/views/login/expired_pwd.rhtml +19 -0
- data/views/login/index.rhtml +15 -0
- data/views/permission/index.rhtml +17 -0
- data/views/permission/relations.rhtml +28 -0
- data/views/permission/roles.rhtml +45 -0
- data/views/permission/tables.rhtml +53 -0
- data/views/roles/_form.rhtml +8 -0
- data/views/roles/edit.rhtml +11 -0
- data/views/roles/list.rhtml +28 -0
- data/views/roles/new.rhtml +8 -0
- data/views/roles/show.rhtml +14 -0
- data/views/shared_views/_advanced_search.rhtml +35 -0
- data/views/shared_views/_child_elements.rhtml +30 -0
- data/views/shared_views/_childs.rhtml +20 -0
- data/views/shared_views/_father_elements.rhtml +27 -0
- data/views/shared_views/_fathers.rhtml +21 -0
- data/views/shared_views/_fathers_header.rhtml +58 -0
- data/views/shared_views/_many_to_many_elements.rhtml +50 -0
- data/views/shared_views/_many_to_manys.rhtml +18 -0
- data/views/shared_views/_one_to_one_elements.rhtml +24 -0
- data/views/shared_views/_one_to_one_father_elements.rhtml +26 -0
- data/views/shared_views/_one_to_ones.rhtml +42 -0
- data/views/shared_views/_one_to_ones_header.rhtml +117 -0
- data/views/shared_views/edit_child.rhtml +89 -0
- data/views/shared_views/edit_many.rhtml +75 -0
- data/views/tables/_cascade.rhtml +10 -0
- data/views/tables/_field.rhtml +10 -0
- data/views/tables/_fk.rhtml +9 -0
- data/views/tables/_form.rhtml +9 -0
- data/views/tables/_join_table_name.rhtml +16 -0
- data/views/tables/_relation_types.rhtml +5 -0
- data/views/tables/_tables.rhtml +15 -0
- data/views/tables/attributes.rhtml +15 -0
- data/views/tables/edit.rhtml +11 -0
- data/views/tables/edit_field.rhtml +18 -0
- data/views/tables/list.rhtml +39 -0
- data/views/tables/new.rhtml +8 -0
- data/views/tables/new_field.rhtml +25 -0
- data/views/tables/relations.rhtml +24 -0
- data/views/tables/show.rhtml +24 -0
- metadata +518 -0
data/lib/fcgi_handler.rb
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
require 'fcgi'
|
|
2
|
+
require 'logger'
|
|
3
|
+
require 'dispatcher'
|
|
4
|
+
require 'rbconfig'
|
|
5
|
+
|
|
6
|
+
class RailsFCGIHandler
|
|
7
|
+
SIGNALS = {
|
|
8
|
+
'HUP' => :reload,
|
|
9
|
+
'INT' => :exit_now,
|
|
10
|
+
'TERM' => :exit_now,
|
|
11
|
+
'USR1' => :exit,
|
|
12
|
+
'USR2' => :restart,
|
|
13
|
+
'SIGTRAP' => :breakpoint
|
|
14
|
+
}
|
|
15
|
+
GLOBAL_SIGNALS = SIGNALS.keys - %w(USR1)
|
|
16
|
+
|
|
17
|
+
attr_reader :when_ready
|
|
18
|
+
|
|
19
|
+
attr_accessor :log_file_path
|
|
20
|
+
attr_accessor :gc_request_period
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# Initialize and run the FastCGI instance, passing arguments through to new.
|
|
24
|
+
def self.process!(*args, &block)
|
|
25
|
+
new(*args, &block).process!
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Initialize the FastCGI instance with the path to a crash log
|
|
29
|
+
# detailing unhandled exceptions (default RAILS_ROOT/log/fastcgi.crash.log)
|
|
30
|
+
# and the number of requests to process between garbage collection runs
|
|
31
|
+
# (default nil for normal GC behavior.) Optionally, pass a block which
|
|
32
|
+
# takes this instance as an argument for further configuration.
|
|
33
|
+
def initialize(log_file_path = nil, gc_request_period = nil)
|
|
34
|
+
self.log_file_path = log_file_path || "#{RAILS_ROOT}/log/fastcgi.crash.log"
|
|
35
|
+
self.gc_request_period = gc_request_period
|
|
36
|
+
|
|
37
|
+
# Yield for additional configuration.
|
|
38
|
+
yield self if block_given?
|
|
39
|
+
|
|
40
|
+
# Safely install signal handlers.
|
|
41
|
+
install_signal_handlers
|
|
42
|
+
|
|
43
|
+
# Start error timestamp at 11 seconds ago.
|
|
44
|
+
@last_error_on = Time.now - 11
|
|
45
|
+
|
|
46
|
+
dispatcher_log :info, "starting"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def process!(provider = FCGI)
|
|
50
|
+
# Make a note of $" so we can safely reload this instance.
|
|
51
|
+
mark!
|
|
52
|
+
|
|
53
|
+
run_gc! if gc_request_period
|
|
54
|
+
|
|
55
|
+
process_each_request!(provider)
|
|
56
|
+
|
|
57
|
+
GC.enable
|
|
58
|
+
dispatcher_log :info, "terminated gracefully"
|
|
59
|
+
|
|
60
|
+
rescue SystemExit => exit_error
|
|
61
|
+
dispatcher_log :info, "terminated by explicit exit"
|
|
62
|
+
|
|
63
|
+
rescue Exception => fcgi_error # FCGI errors
|
|
64
|
+
# retry on errors that would otherwise have terminated the FCGI process,
|
|
65
|
+
# but only if they occur more than 10 seconds apart.
|
|
66
|
+
if !(SignalException === fcgi_error) && Time.now - @last_error_on > 10
|
|
67
|
+
@last_error_on = Time.now
|
|
68
|
+
dispatcher_error(fcgi_error, "almost killed by this error")
|
|
69
|
+
retry
|
|
70
|
+
else
|
|
71
|
+
dispatcher_error(fcgi_error, "killed by this error")
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
protected
|
|
77
|
+
def logger
|
|
78
|
+
@logger ||= Logger.new(@log_file_path)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def dispatcher_log(level, msg)
|
|
82
|
+
time_str = Time.now.strftime("%d/%b/%Y:%H:%M:%S")
|
|
83
|
+
logger.send(level, "[#{time_str} :: #{$$}] #{msg}")
|
|
84
|
+
rescue Exception => log_error # Logger errors
|
|
85
|
+
STDERR << "Couldn't write to #{@log_file_path.inspect}: #{msg}\n"
|
|
86
|
+
STDERR << " #{log_error.class}: #{log_error.message}\n"
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def dispatcher_error(e, msg = "")
|
|
90
|
+
error_message =
|
|
91
|
+
"Dispatcher failed to catch: #{e} (#{e.class})\n" +
|
|
92
|
+
" #{e.backtrace.join("\n ")}\n#{msg}"
|
|
93
|
+
dispatcher_log(:error, error_message)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def install_signal_handlers
|
|
97
|
+
GLOBAL_SIGNALS.each { |signal| install_signal_handler(signal) }
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def install_signal_handler(signal, handler = nil)
|
|
101
|
+
handler ||= method("#{SIGNALS[signal]}_handler").to_proc
|
|
102
|
+
trap(signal, handler)
|
|
103
|
+
rescue ArgumentError
|
|
104
|
+
dispatcher_log :warn, "Ignoring unsupported signal #{signal}."
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def with_signal_handler(signal)
|
|
108
|
+
install_signal_handler(signal)
|
|
109
|
+
yield
|
|
110
|
+
ensure
|
|
111
|
+
install_signal_handler(signal, 'DEFAULT')
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def exit_now_handler(signal)
|
|
115
|
+
dispatcher_log :info, "asked to terminate immediately"
|
|
116
|
+
exit
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def exit_handler(signal)
|
|
120
|
+
dispatcher_log :info, "asked to terminate ASAP"
|
|
121
|
+
@when_ready = :exit
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def reload_handler(signal)
|
|
125
|
+
dispatcher_log :info, "asked to reload ASAP"
|
|
126
|
+
@when_ready = :reload
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def restart_handler(signal)
|
|
130
|
+
dispatcher_log :info, "asked to restart ASAP"
|
|
131
|
+
@when_ready = :restart
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def breakpoint_handler(signal)
|
|
135
|
+
dispatcher_log :info, "asked to breakpoint ASAP"
|
|
136
|
+
@when_ready = :breakpoint
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def process_each_request!(provider)
|
|
140
|
+
cgi = nil
|
|
141
|
+
provider.each_cgi do |cgi|
|
|
142
|
+
with_signal_handler 'USR1' do
|
|
143
|
+
process_request(cgi)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
case when_ready
|
|
147
|
+
when :reload
|
|
148
|
+
reload!
|
|
149
|
+
when :restart
|
|
150
|
+
close_connection(cgi)
|
|
151
|
+
restart!
|
|
152
|
+
when :exit
|
|
153
|
+
close_connection(cgi)
|
|
154
|
+
break
|
|
155
|
+
when :breakpoint
|
|
156
|
+
close_connection(cgi)
|
|
157
|
+
breakpoint!
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
gc_countdown
|
|
161
|
+
end
|
|
162
|
+
rescue SignalException => signal
|
|
163
|
+
raise unless signal.message == 'SIGUSR1'
|
|
164
|
+
close_connection(cgi) if cgi
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def process_request(cgi)
|
|
168
|
+
Dispatcher.dispatch(cgi)
|
|
169
|
+
rescue Exception => e # errors from CGI dispatch
|
|
170
|
+
raise if SignalException === e
|
|
171
|
+
dispatcher_error(e)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def restart!
|
|
175
|
+
config = ::Config::CONFIG
|
|
176
|
+
ruby = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
|
|
177
|
+
command_line = [ruby, $0, ARGV].flatten.join(' ')
|
|
178
|
+
|
|
179
|
+
dispatcher_log :info, "restarted"
|
|
180
|
+
|
|
181
|
+
exec(command_line)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def reload!
|
|
185
|
+
run_gc! if gc_request_period
|
|
186
|
+
restore!
|
|
187
|
+
@when_ready = nil
|
|
188
|
+
dispatcher_log :info, "reloaded"
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def mark!
|
|
192
|
+
@features = $".clone
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def restore!
|
|
196
|
+
$".replace @features
|
|
197
|
+
Dispatcher.reset_application!
|
|
198
|
+
ActionController::Routing::Routes.reload
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def breakpoint!
|
|
202
|
+
require 'breakpoint'
|
|
203
|
+
port = defined?(BREAKPOINT_SERVER_PORT) ? BREAKPOINT_SERVER_PORT : 42531
|
|
204
|
+
Breakpoint.activate_drb("druby://localhost:#{port}", nil, !defined?(FastCGI))
|
|
205
|
+
dispatcher_log :info, "breakpointing"
|
|
206
|
+
breakpoint
|
|
207
|
+
@when_ready = nil
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def run_gc!
|
|
211
|
+
@gc_request_countdown = gc_request_period
|
|
212
|
+
GC.enable; GC.start; GC.disable
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def gc_countdown
|
|
216
|
+
if gc_request_period
|
|
217
|
+
@gc_request_countdown -= 1
|
|
218
|
+
run_gc! if @gc_request_countdown <= 0
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def close_connection(cgi)
|
|
223
|
+
cgi.instance_variable_get("@request").finish
|
|
224
|
+
end
|
|
225
|
+
end
|
data/lib/initializer.rb
ADDED
|
@@ -0,0 +1,702 @@
|
|
|
1
|
+
require 'logger'
|
|
2
|
+
require 'set'
|
|
3
|
+
require File.join(File.dirname(__FILE__), 'railties_path')
|
|
4
|
+
require File.join(File.dirname(__FILE__), 'authorails/version')
|
|
5
|
+
|
|
6
|
+
RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
|
|
7
|
+
|
|
8
|
+
module Rails
|
|
9
|
+
# The Initializer is responsible for processing the Rails configuration, such
|
|
10
|
+
# as setting the $LOAD_PATH, requiring the right frameworks, initializing
|
|
11
|
+
# logging, and more. It can be run either as a single command that'll just
|
|
12
|
+
# use the default configuration, like this:
|
|
13
|
+
#
|
|
14
|
+
# Rails::Initializer.run
|
|
15
|
+
#
|
|
16
|
+
# But normally it's more interesting to pass in a custom configuration
|
|
17
|
+
# through the block running:
|
|
18
|
+
#
|
|
19
|
+
# Rails::Initializer.run do |config|
|
|
20
|
+
# config.frameworks -= [ :action_web_service ]
|
|
21
|
+
# end
|
|
22
|
+
#
|
|
23
|
+
# This will use the default configuration options from Rails::Configuration,
|
|
24
|
+
# but allow for overwriting on select areas.
|
|
25
|
+
class Initializer
|
|
26
|
+
# The Configuration instance used by this Initializer instance.
|
|
27
|
+
attr_reader :configuration
|
|
28
|
+
|
|
29
|
+
# The set of loaded plugins.
|
|
30
|
+
attr_reader :loaded_plugins
|
|
31
|
+
|
|
32
|
+
# Runs the initializer. By default, this will invoke the #process method,
|
|
33
|
+
# which simply executes all of the initialization routines. Alternately,
|
|
34
|
+
# you can specify explicitly which initialization routine you want:
|
|
35
|
+
#
|
|
36
|
+
# Rails::Initializer.run(:set_load_path)
|
|
37
|
+
#
|
|
38
|
+
# This is useful if you only want the load path initialized, without
|
|
39
|
+
# incuring the overhead of completely loading the entire environment.
|
|
40
|
+
def self.run(command = :process, configuration = Configuration.new)
|
|
41
|
+
yield configuration if block_given?
|
|
42
|
+
initializer = new configuration
|
|
43
|
+
initializer.send(command)
|
|
44
|
+
initializer
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Create a new Initializer instance that references the given Configuration
|
|
48
|
+
# instance.
|
|
49
|
+
def initialize(configuration)
|
|
50
|
+
@configuration = configuration
|
|
51
|
+
@loaded_plugins = []
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Sequentially step through all of the available initialization routines,
|
|
55
|
+
# in order:
|
|
56
|
+
#
|
|
57
|
+
# * #set_load_path
|
|
58
|
+
# * #set_connection_adapters
|
|
59
|
+
# * #require_frameworks
|
|
60
|
+
# * #load_environment
|
|
61
|
+
# * #initialize_database
|
|
62
|
+
# * #initialize_logger
|
|
63
|
+
# * #initialize_framework_logging
|
|
64
|
+
# * #initialize_framework_views
|
|
65
|
+
# * #initialize_dependency_mechanism
|
|
66
|
+
# * #initialize_breakpoints
|
|
67
|
+
# * #initialize_whiny_nils
|
|
68
|
+
# * #initialize_framework_settings
|
|
69
|
+
# * #load_environment
|
|
70
|
+
# * #load_plugins
|
|
71
|
+
# * #load_observers
|
|
72
|
+
# * #initialize_routing
|
|
73
|
+
#
|
|
74
|
+
# (Note that #load_environment is invoked twice, once at the start and
|
|
75
|
+
# once at the end, to support the legacy configuration style where the
|
|
76
|
+
# environment could overwrite the defaults directly, instead of via the
|
|
77
|
+
# Configuration instance.
|
|
78
|
+
def process
|
|
79
|
+
check_ruby_version
|
|
80
|
+
set_load_path
|
|
81
|
+
set_connection_adapters
|
|
82
|
+
|
|
83
|
+
require_frameworks
|
|
84
|
+
set_autoload_paths
|
|
85
|
+
load_environment
|
|
86
|
+
|
|
87
|
+
initialize_encoding
|
|
88
|
+
initialize_database
|
|
89
|
+
initialize_logger
|
|
90
|
+
initialize_framework_logging
|
|
91
|
+
initialize_framework_views
|
|
92
|
+
initialize_dependency_mechanism
|
|
93
|
+
initialize_breakpoints
|
|
94
|
+
initialize_whiny_nils
|
|
95
|
+
initialize_temporary_directories
|
|
96
|
+
initialize_framework_settings
|
|
97
|
+
|
|
98
|
+
# Support for legacy configuration style where the environment
|
|
99
|
+
# could overwrite anything set from the defaults/global through
|
|
100
|
+
# the individual base class configurations.
|
|
101
|
+
load_environment
|
|
102
|
+
|
|
103
|
+
add_support_load_paths
|
|
104
|
+
|
|
105
|
+
load_plugins
|
|
106
|
+
|
|
107
|
+
# Observers are loaded after plugins in case Observers or observed models are modified by plugins.
|
|
108
|
+
load_observers
|
|
109
|
+
|
|
110
|
+
# Routing must be initialized after plugins to allow the former to extend the routes
|
|
111
|
+
initialize_routing
|
|
112
|
+
|
|
113
|
+
# the framework is now fully initialized
|
|
114
|
+
after_initialize
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Check for valid Ruby version
|
|
118
|
+
# This is done in an external file, so we can use it
|
|
119
|
+
# from the `rails` program as well without duplication.
|
|
120
|
+
def check_ruby_version
|
|
121
|
+
require 'ruby_version_check'
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Set the <tt>$LOAD_PATH</tt> based on the value of
|
|
125
|
+
# Configuration#load_paths. Duplicates are removed.
|
|
126
|
+
def set_load_path
|
|
127
|
+
load_paths = configuration.load_paths + configuration.framework_paths
|
|
128
|
+
load_paths.reverse_each { |dir| $LOAD_PATH.unshift(dir) if File.directory?(dir) }
|
|
129
|
+
$LOAD_PATH.uniq!
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# Set the paths from which Rails will automatically load source files, and
|
|
133
|
+
# the load_once paths.
|
|
134
|
+
def set_autoload_paths
|
|
135
|
+
Dependencies.load_paths = configuration.load_paths.uniq
|
|
136
|
+
Dependencies.load_once_paths = configuration.load_once_paths.uniq
|
|
137
|
+
|
|
138
|
+
extra = Dependencies.load_once_paths - Dependencies.load_paths
|
|
139
|
+
unless extra.empty?
|
|
140
|
+
abort <<-end_error
|
|
141
|
+
load_once_paths must be a subset of the load_paths.
|
|
142
|
+
Extra items in load_once_paths: #{extra * ','}
|
|
143
|
+
end_error
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Freeze the arrays so future modifications will fail rather than do nothing mysteriously
|
|
147
|
+
configuration.load_once_paths.freeze
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Sets the +RAILS_CONNECTION_ADAPTERS+ constant based on the value of
|
|
151
|
+
# Configuration#connection_adapters. This constant is used to determine
|
|
152
|
+
# which database adapters should be loaded (by default, all adapters are
|
|
153
|
+
# loaded).
|
|
154
|
+
def set_connection_adapters
|
|
155
|
+
Object.const_set("RAILS_CONNECTION_ADAPTERS", configuration.connection_adapters) if configuration.connection_adapters
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# Requires all frameworks specified by the Configuration#frameworks
|
|
159
|
+
# list. By default, all frameworks (ActiveRecord, ActiveSupport,
|
|
160
|
+
# ActionPack, ActionMailer, and ActionWebService) are loaded.
|
|
161
|
+
def require_frameworks
|
|
162
|
+
configuration.frameworks.each { |framework| require(framework.to_s) }
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# Add the load paths used by support functions such as the info controller
|
|
166
|
+
def add_support_load_paths
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# Loads all plugins in <tt>config.plugin_paths</tt>. <tt>plugin_paths</tt>
|
|
170
|
+
# defaults to <tt>vendor/plugins</tt> but may also be set to a list of
|
|
171
|
+
# paths, such as
|
|
172
|
+
# config.plugin_paths = ['lib/plugins', 'vendor/plugins']
|
|
173
|
+
#
|
|
174
|
+
# Each plugin discovered in <tt>plugin_paths</tt> is initialized:
|
|
175
|
+
# * add its +lib+ directory, if present, to the beginning of the load path
|
|
176
|
+
# * evaluate <tt>init.rb</tt> if present
|
|
177
|
+
#
|
|
178
|
+
# After all plugins are loaded, duplicates are removed from the load path.
|
|
179
|
+
# If an array of plugin names is specified in config.plugins, the plugins
|
|
180
|
+
# will be loaded in that order. Otherwise, plugins are loaded in alphabetical
|
|
181
|
+
# order.
|
|
182
|
+
def load_plugins
|
|
183
|
+
if configuration.plugins.nil?
|
|
184
|
+
# a nil value implies we don't care about plugins; load 'em all in a reliable order
|
|
185
|
+
find_plugins(configuration.plugin_paths).sort.each { |path| load_plugin path }
|
|
186
|
+
elsif !configuration.plugins.empty?
|
|
187
|
+
# we've specified a config.plugins array, so respect that order
|
|
188
|
+
plugin_paths = find_plugins(configuration.plugin_paths)
|
|
189
|
+
configuration.plugins.each do |name|
|
|
190
|
+
path = plugin_paths.find { |p| File.basename(p) == name }
|
|
191
|
+
raise(LoadError, "Cannot find the plugin '#{name}'!") if path.nil?
|
|
192
|
+
load_plugin path
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
$LOAD_PATH.uniq!
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
# Loads the environment specified by Configuration#environment_path, which
|
|
199
|
+
# is typically one of development, testing, or production.
|
|
200
|
+
def load_environment
|
|
201
|
+
silence_warnings do
|
|
202
|
+
config = configuration
|
|
203
|
+
constants = self.class.constants
|
|
204
|
+
eval(IO.read(configuration.environment_path), binding, configuration.environment_path)
|
|
205
|
+
(self.class.constants - constants).each do |const|
|
|
206
|
+
Object.const_set(const, self.class.const_get(const))
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def load_observers
|
|
212
|
+
ActiveRecord::Base.instantiate_observers
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
# This initialzation sets $KCODE to 'u' to enable the multibyte safe operations.
|
|
216
|
+
# Plugin authors supporting other encodings should override this behaviour and
|
|
217
|
+
# set the relevant +default_charset+ on ActionController::Base
|
|
218
|
+
def initialize_encoding
|
|
219
|
+
$KCODE='u'
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
# This initialization routine does nothing unless <tt>:active_record</tt>
|
|
223
|
+
# is one of the frameworks to load (Configuration#frameworks). If it is,
|
|
224
|
+
# this sets the database configuration from Configuration#database_configuration
|
|
225
|
+
# and then establishes the connection.
|
|
226
|
+
def initialize_database
|
|
227
|
+
return unless configuration.frameworks.include?(:active_record)
|
|
228
|
+
ActiveRecord::Base.configurations = configuration.database_configuration
|
|
229
|
+
ActiveRecord::Base.establish_connection
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# If the +RAILS_DEFAULT_LOGGER+ constant is already set, this initialization
|
|
233
|
+
# routine does nothing. If the constant is not set, and Configuration#logger
|
|
234
|
+
# is not +nil+, this also does nothing. Otherwise, a new logger instance
|
|
235
|
+
# is created at Configuration#log_path, with a default log level of
|
|
236
|
+
# Configuration#log_level.
|
|
237
|
+
#
|
|
238
|
+
# If the log could not be created, the log will be set to output to
|
|
239
|
+
# +STDERR+, with a log level of +WARN+.
|
|
240
|
+
def initialize_logger
|
|
241
|
+
# if the environment has explicitly defined a logger, use it
|
|
242
|
+
return if defined?(RAILS_DEFAULT_LOGGER)
|
|
243
|
+
|
|
244
|
+
unless logger = configuration.logger
|
|
245
|
+
begin
|
|
246
|
+
logger = Logger.new(configuration.log_path)
|
|
247
|
+
logger.level = Logger.const_get(configuration.log_level.to_s.upcase)
|
|
248
|
+
rescue StandardError
|
|
249
|
+
logger = Logger.new(STDERR)
|
|
250
|
+
logger.level = Logger::WARN
|
|
251
|
+
logger.warn(
|
|
252
|
+
"Rails Error: Unable to access log file. Please ensure that #{configuration.log_path} exists and is chmod 0666. " +
|
|
253
|
+
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
|
|
254
|
+
)
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
silence_warnings { Object.const_set "RAILS_DEFAULT_LOGGER", logger }
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
# Sets the logger for ActiveRecord, ActionController, and ActionMailer
|
|
262
|
+
# (but only for those frameworks that are to be loaded). If the framework's
|
|
263
|
+
# logger is already set, it is not changed, otherwise it is set to use
|
|
264
|
+
# +RAILS_DEFAULT_LOGGER+.
|
|
265
|
+
def initialize_framework_logging
|
|
266
|
+
for framework in ([ :active_record, :action_controller, :action_mailer ] & configuration.frameworks)
|
|
267
|
+
framework.to_s.camelize.constantize.const_get("Base").logger ||= RAILS_DEFAULT_LOGGER
|
|
268
|
+
end
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
# Sets the +template_root+ for ActionController::Base and ActionMailer::Base
|
|
272
|
+
# (but only for those frameworks that are to be loaded). If the framework's
|
|
273
|
+
# +template_root+ has already been set, it is not changed, otherwise it is
|
|
274
|
+
# set to use Configuration#view_path.
|
|
275
|
+
def initialize_framework_views
|
|
276
|
+
for framework in ([ :action_controller, :action_mailer ] & configuration.frameworks)
|
|
277
|
+
framework.to_s.camelize.constantize.const_get("Base").template_root ||= configuration.view_path
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
# If ActionController is not one of the loaded frameworks (Configuration#frameworks)
|
|
282
|
+
# this does nothing. Otherwise, it loads the routing definitions and sets up
|
|
283
|
+
# loading module used to lazily load controllers (Configuration#controller_paths).
|
|
284
|
+
def initialize_routing
|
|
285
|
+
return unless configuration.frameworks.include?(:action_controller)
|
|
286
|
+
ActionController::Routing.controller_paths = configuration.controller_paths
|
|
287
|
+
ActionController::Routing::Routes.reload
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
# Sets the dependency loading mechanism based on the value of
|
|
291
|
+
# Configuration#cache_classes.
|
|
292
|
+
def initialize_dependency_mechanism
|
|
293
|
+
Dependencies.mechanism = configuration.cache_classes ? :require : :load
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
# Sets the +BREAKPOINT_SERVER_PORT+ if Configuration#breakpoint_server
|
|
297
|
+
# is true.
|
|
298
|
+
def initialize_breakpoints
|
|
299
|
+
silence_warnings { Object.const_set("BREAKPOINT_SERVER_PORT", 42531) if configuration.breakpoint_server }
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
# Loads support for "whiny nil" (noisy warnings when methods are invoked
|
|
303
|
+
# on +nil+ values) if Configuration#whiny_nils is true.
|
|
304
|
+
def initialize_whiny_nils
|
|
305
|
+
require('active_support/whiny_nil') if configuration.whiny_nils
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
def initialize_temporary_directories
|
|
309
|
+
if configuration.frameworks.include?(:action_controller)
|
|
310
|
+
session_path = "#{RAILS_ROOT}/tmp/sessions/"
|
|
311
|
+
ActionController::Base.session_options[:tmpdir] = File.exist?(session_path) ? session_path : Dir::tmpdir
|
|
312
|
+
|
|
313
|
+
cache_path = "#{RAILS_ROOT}/tmp/cache/"
|
|
314
|
+
if File.exist?(cache_path)
|
|
315
|
+
ActionController::Base.fragment_cache_store = :file_store, cache_path
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
# Initializes framework-specific settings for each of the loaded frameworks
|
|
321
|
+
# (Configuration#frameworks). The available settings map to the accessors
|
|
322
|
+
# on each of the corresponding Base classes.
|
|
323
|
+
def initialize_framework_settings
|
|
324
|
+
configuration.frameworks.each do |framework|
|
|
325
|
+
base_class = framework.to_s.camelize.constantize.const_get("Base")
|
|
326
|
+
|
|
327
|
+
configuration.send(framework).each do |setting, value|
|
|
328
|
+
base_class.send("#{setting}=", value)
|
|
329
|
+
end
|
|
330
|
+
end
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
# Fires the user-supplied after_initialize block (Configuration#after_initialize)
|
|
334
|
+
def after_initialize
|
|
335
|
+
configuration.after_initialize_block.call if configuration.after_initialize_block
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
protected
|
|
339
|
+
# Return a list of plugin paths within base_path. A plugin path is
|
|
340
|
+
# a directory that contains either a lib directory or an init.rb file.
|
|
341
|
+
# This recurses into directories which are not plugin paths, so you
|
|
342
|
+
# may organize your plugins within the plugin path.
|
|
343
|
+
def find_plugins(*base_paths)
|
|
344
|
+
base_paths.flatten.inject([]) do |plugins, base_path|
|
|
345
|
+
Dir.glob(File.join(base_path, '*')).each do |path|
|
|
346
|
+
if plugin_path?(path)
|
|
347
|
+
plugins << path if plugin_enabled?(path)
|
|
348
|
+
elsif File.directory?(path)
|
|
349
|
+
plugins += find_plugins(path)
|
|
350
|
+
end
|
|
351
|
+
end
|
|
352
|
+
plugins
|
|
353
|
+
end
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
def plugin_path?(path)
|
|
357
|
+
File.directory?(path) and (File.directory?(File.join(path, 'lib')) or File.file?(File.join(path, 'init.rb')))
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
def plugin_enabled?(path)
|
|
361
|
+
configuration.plugins.nil? || configuration.plugins.include?(File.basename(path))
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
# Load the plugin at <tt>path</tt> unless already loaded.
|
|
365
|
+
#
|
|
366
|
+
# Each plugin is initialized:
|
|
367
|
+
# * add its +lib+ directory, if present, to the beginning of the load path
|
|
368
|
+
# * evaluate <tt>init.rb</tt> if present
|
|
369
|
+
#
|
|
370
|
+
# Returns <tt>true</tt> if the plugin is successfully loaded or
|
|
371
|
+
# <tt>false</tt> if it is already loaded (similar to Kernel#require).
|
|
372
|
+
# Raises <tt>LoadError</tt> if the plugin is not found.
|
|
373
|
+
def load_plugin(directory)
|
|
374
|
+
name = File.basename(directory)
|
|
375
|
+
return false if loaded_plugins.include?(name)
|
|
376
|
+
|
|
377
|
+
# Catch nonexistent and empty plugins.
|
|
378
|
+
raise LoadError, "No such plugin: #{directory}" unless plugin_path?(directory)
|
|
379
|
+
|
|
380
|
+
lib_path = File.join(directory, 'lib')
|
|
381
|
+
init_path = File.join(directory, 'init.rb')
|
|
382
|
+
has_lib = File.directory?(lib_path)
|
|
383
|
+
has_init = File.file?(init_path)
|
|
384
|
+
|
|
385
|
+
# Add lib to load path *after* the application lib, to allow
|
|
386
|
+
# application libraries to override plugin libraries.
|
|
387
|
+
if has_lib
|
|
388
|
+
application_lib_index = $LOAD_PATH.index(File.join(RAILS_ROOT, "lib")) || 0
|
|
389
|
+
$LOAD_PATH.insert(application_lib_index + 1, lib_path)
|
|
390
|
+
Dependencies.load_paths << lib_path
|
|
391
|
+
Dependencies.load_once_paths << lib_path
|
|
392
|
+
end
|
|
393
|
+
|
|
394
|
+
# Allow plugins to reference the current configuration object
|
|
395
|
+
config = configuration
|
|
396
|
+
|
|
397
|
+
# Add to set of loaded plugins before 'name' collapsed in eval.
|
|
398
|
+
loaded_plugins << name
|
|
399
|
+
|
|
400
|
+
# Evaluate init.rb.
|
|
401
|
+
silence_warnings { eval(IO.read(init_path), binding, init_path) } if has_init
|
|
402
|
+
|
|
403
|
+
true
|
|
404
|
+
end
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
# The Configuration class holds all the parameters for the Initializer and
|
|
408
|
+
# ships with defaults that suites most Rails applications. But it's possible
|
|
409
|
+
# to overwrite everything. Usually, you'll create an Configuration file
|
|
410
|
+
# implicitly through the block running on the Initializer, but it's also
|
|
411
|
+
# possible to create the Configuration instance in advance and pass it in
|
|
412
|
+
# like this:
|
|
413
|
+
#
|
|
414
|
+
# config = Rails::Configuration.new
|
|
415
|
+
# Rails::Initializer.run(:process, config)
|
|
416
|
+
class Configuration
|
|
417
|
+
# A stub for setting options on ActionController::Base
|
|
418
|
+
attr_accessor :action_controller
|
|
419
|
+
|
|
420
|
+
# A stub for setting options on ActionMailer::Base
|
|
421
|
+
attr_accessor :action_mailer
|
|
422
|
+
|
|
423
|
+
# A stub for setting options on ActionView::Base
|
|
424
|
+
attr_accessor :action_view
|
|
425
|
+
|
|
426
|
+
# A stub for setting options on ActionWebService::Base
|
|
427
|
+
attr_accessor :action_web_service
|
|
428
|
+
|
|
429
|
+
# A stub for setting options on ActiveRecord::Base
|
|
430
|
+
attr_accessor :active_record
|
|
431
|
+
|
|
432
|
+
# Whether or not to use the breakpoint server (boolean)
|
|
433
|
+
attr_accessor :breakpoint_server
|
|
434
|
+
|
|
435
|
+
# Whether or not classes should be cached (set to false if you want
|
|
436
|
+
# application classes to be reloaded on each request)
|
|
437
|
+
attr_accessor :cache_classes
|
|
438
|
+
|
|
439
|
+
# The list of connection adapters to load. (By default, all connection
|
|
440
|
+
# adapters are loaded. You can set this to be just the adapter(s) you
|
|
441
|
+
# will use to reduce your application's load time.)
|
|
442
|
+
attr_accessor :connection_adapters
|
|
443
|
+
|
|
444
|
+
# The list of paths that should be searched for controllers. (Defaults
|
|
445
|
+
# to <tt>app/controllers</tt> and <tt>components</tt>.)
|
|
446
|
+
attr_accessor :controller_paths
|
|
447
|
+
|
|
448
|
+
# The path to the database configuration file to use. (Defaults to
|
|
449
|
+
# <tt>config/database.yml</tt>.)
|
|
450
|
+
attr_accessor :database_configuration_file
|
|
451
|
+
|
|
452
|
+
# The list of rails framework components that should be loaded. (Defaults
|
|
453
|
+
# to <tt>:active_record</tt>, <tt>:action_controller</tt>,
|
|
454
|
+
# <tt>:action_view</tt>, <tt>:action_mailer</tt>, and
|
|
455
|
+
# <tt>:action_web_service</tt>).
|
|
456
|
+
attr_accessor :frameworks
|
|
457
|
+
|
|
458
|
+
# An array of additional paths to prepend to the load path. By default,
|
|
459
|
+
# all +app+, +lib+, +vendor+ and mock paths are included in this list.
|
|
460
|
+
attr_accessor :load_paths
|
|
461
|
+
|
|
462
|
+
# An array of paths from which Rails will automatically load from only once.
|
|
463
|
+
# All elements of this array must also be in +load_paths+.
|
|
464
|
+
attr_accessor :load_once_paths
|
|
465
|
+
|
|
466
|
+
# The log level to use for the default Rails logger. In production mode,
|
|
467
|
+
# this defaults to <tt>:info</tt>. In development mode, it defaults to
|
|
468
|
+
# <tt>:debug</tt>.
|
|
469
|
+
attr_accessor :log_level
|
|
470
|
+
|
|
471
|
+
# The path to the log file to use. Defaults to log/#{environment}.log
|
|
472
|
+
# (e.g. log/development.log or log/production.log).
|
|
473
|
+
attr_accessor :log_path
|
|
474
|
+
|
|
475
|
+
# The specific logger to use. By default, a logger will be created and
|
|
476
|
+
# initialized using #log_path and #log_level, but a programmer may
|
|
477
|
+
# specifically set the logger to use via this accessor and it will be
|
|
478
|
+
# used directly.
|
|
479
|
+
attr_accessor :logger
|
|
480
|
+
|
|
481
|
+
# The root of the application's views. (Defaults to <tt>app/views</tt>.)
|
|
482
|
+
attr_accessor :view_path
|
|
483
|
+
|
|
484
|
+
# Set to +true+ if you want to be warned (noisily) when you try to invoke
|
|
485
|
+
# any method of +nil+. Set to +false+ for the standard Ruby behavior.
|
|
486
|
+
attr_accessor :whiny_nils
|
|
487
|
+
|
|
488
|
+
# The list of plugins to load. If this is set to <tt>nil</tt>, all plugins will
|
|
489
|
+
# be loaded. If this is set to <tt>[]</tt>, no plugins will be loaded. Otherwise,
|
|
490
|
+
# plugins will be loaded in the order specified.
|
|
491
|
+
attr_accessor :plugins
|
|
492
|
+
|
|
493
|
+
# The path to the root of the plugins directory. By default, it is in
|
|
494
|
+
# <tt>vendor/plugins</tt>.
|
|
495
|
+
attr_accessor :plugin_paths
|
|
496
|
+
|
|
497
|
+
# Create a new Configuration instance, initialized with the default
|
|
498
|
+
# values.
|
|
499
|
+
def initialize
|
|
500
|
+
self.frameworks = default_frameworks
|
|
501
|
+
self.load_paths = default_load_paths
|
|
502
|
+
self.load_once_paths = default_load_once_paths
|
|
503
|
+
self.log_path = default_log_path
|
|
504
|
+
self.log_level = default_log_level
|
|
505
|
+
self.view_path = default_view_path
|
|
506
|
+
self.controller_paths = default_controller_paths
|
|
507
|
+
self.cache_classes = default_cache_classes
|
|
508
|
+
self.breakpoint_server = default_breakpoint_server
|
|
509
|
+
self.whiny_nils = default_whiny_nils
|
|
510
|
+
self.plugins = default_plugins
|
|
511
|
+
self.plugin_paths = default_plugin_paths
|
|
512
|
+
self.database_configuration_file = default_database_configuration_file
|
|
513
|
+
|
|
514
|
+
for framework in default_frameworks
|
|
515
|
+
self.send("#{framework}=", Rails::OrderedOptions.new)
|
|
516
|
+
end
|
|
517
|
+
end
|
|
518
|
+
|
|
519
|
+
# Loads and returns the contents of the #database_configuration_file. The
|
|
520
|
+
# contents of the file are processed via ERB before being sent through
|
|
521
|
+
# YAML::load.
|
|
522
|
+
def database_configuration
|
|
523
|
+
YAML::load(ERB.new(IO.read(database_configuration_file)).result)
|
|
524
|
+
end
|
|
525
|
+
|
|
526
|
+
# The path to the current environment's file (development.rb, etc.). By
|
|
527
|
+
# default the file is at <tt>config/environments/#{environment}.rb</tt>.
|
|
528
|
+
def environment_path
|
|
529
|
+
"#{root_path}/config/environments/#{environment}.rb"
|
|
530
|
+
end
|
|
531
|
+
|
|
532
|
+
# Return the currently selected environment. By default, it returns the
|
|
533
|
+
# value of the +RAILS_ENV+ constant.
|
|
534
|
+
def environment
|
|
535
|
+
::RAILS_ENV
|
|
536
|
+
end
|
|
537
|
+
|
|
538
|
+
# Sets a block which will be executed after rails has been fully initialized.
|
|
539
|
+
# Useful for per-environment configuration which depends on the framework being
|
|
540
|
+
# fully initialized.
|
|
541
|
+
def after_initialize(&after_initialize_block)
|
|
542
|
+
@after_initialize_block = after_initialize_block
|
|
543
|
+
end
|
|
544
|
+
|
|
545
|
+
# Returns the block set in Configuration#after_initialize
|
|
546
|
+
def after_initialize_block
|
|
547
|
+
@after_initialize_block
|
|
548
|
+
end
|
|
549
|
+
|
|
550
|
+
# Add a preparation callback that will run before every request in development
|
|
551
|
+
# mode, or before the first request in production.
|
|
552
|
+
#
|
|
553
|
+
# See Dispatcher#to_prepare.
|
|
554
|
+
def to_prepare(&callback)
|
|
555
|
+
require 'dispatcher' unless defined?(::Dispatcher)
|
|
556
|
+
Dispatcher.to_prepare(&callback)
|
|
557
|
+
end
|
|
558
|
+
|
|
559
|
+
def builtin_directories
|
|
560
|
+
# Include builtins only in the development environment.
|
|
561
|
+
(environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
|
|
562
|
+
end
|
|
563
|
+
|
|
564
|
+
def framework_paths
|
|
565
|
+
# TODO: Don't include dirs for frameworks that are not used
|
|
566
|
+
%w(
|
|
567
|
+
railties
|
|
568
|
+
railties/lib
|
|
569
|
+
actionpack/lib
|
|
570
|
+
activesupport/lib
|
|
571
|
+
activerecord/lib
|
|
572
|
+
actionmailer/lib
|
|
573
|
+
actionwebservice/lib
|
|
574
|
+
).map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
|
|
575
|
+
end
|
|
576
|
+
|
|
577
|
+
private
|
|
578
|
+
def root_path
|
|
579
|
+
::RAILS_ROOT
|
|
580
|
+
end
|
|
581
|
+
|
|
582
|
+
def framework_root_path
|
|
583
|
+
defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root_path}/vendor/rails"
|
|
584
|
+
end
|
|
585
|
+
|
|
586
|
+
def default_frameworks
|
|
587
|
+
[ :active_record, :action_controller, :action_view, :action_mailer, :action_web_service ]
|
|
588
|
+
end
|
|
589
|
+
|
|
590
|
+
def default_load_paths
|
|
591
|
+
paths = ["#{root_path}/test/mocks/#{environment}"]
|
|
592
|
+
|
|
593
|
+
# Add the app's controller directory
|
|
594
|
+
paths.concat(Dir["#{root_path}/app/controllers/"])
|
|
595
|
+
|
|
596
|
+
# Then components subdirectories.
|
|
597
|
+
paths.concat(Dir["#{root_path}/components/[_a-z]*"])
|
|
598
|
+
|
|
599
|
+
# Followed by the standard includes.
|
|
600
|
+
paths.concat %w(
|
|
601
|
+
app
|
|
602
|
+
app/models
|
|
603
|
+
app/controllers
|
|
604
|
+
app/helpers
|
|
605
|
+
app/services
|
|
606
|
+
app/apis
|
|
607
|
+
components
|
|
608
|
+
config
|
|
609
|
+
lib
|
|
610
|
+
vendor
|
|
611
|
+
).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
|
|
612
|
+
|
|
613
|
+
paths.concat builtin_directories
|
|
614
|
+
end
|
|
615
|
+
|
|
616
|
+
# Doesn't matter since plugins aren't in load_paths yet.
|
|
617
|
+
def default_load_once_paths
|
|
618
|
+
[]
|
|
619
|
+
end
|
|
620
|
+
|
|
621
|
+
def default_log_path
|
|
622
|
+
File.join(root_path, 'log', "#{environment}.log")
|
|
623
|
+
end
|
|
624
|
+
|
|
625
|
+
def default_log_level
|
|
626
|
+
environment == 'production' ? :info : :debug
|
|
627
|
+
end
|
|
628
|
+
|
|
629
|
+
def default_database_configuration_file
|
|
630
|
+
File.join(root_path, 'config', 'database.yml')
|
|
631
|
+
end
|
|
632
|
+
|
|
633
|
+
def default_view_path
|
|
634
|
+
File.join(root_path, 'app', 'views')
|
|
635
|
+
end
|
|
636
|
+
|
|
637
|
+
def default_controller_paths
|
|
638
|
+
paths = [ File.join(root_path, 'app', 'controllers'), File.join(root_path, 'components') ]
|
|
639
|
+
paths.concat builtin_directories
|
|
640
|
+
paths
|
|
641
|
+
end
|
|
642
|
+
|
|
643
|
+
def default_dependency_mechanism
|
|
644
|
+
:load
|
|
645
|
+
end
|
|
646
|
+
|
|
647
|
+
def default_cache_classes
|
|
648
|
+
false
|
|
649
|
+
end
|
|
650
|
+
|
|
651
|
+
def default_breakpoint_server
|
|
652
|
+
false
|
|
653
|
+
end
|
|
654
|
+
|
|
655
|
+
def default_whiny_nils
|
|
656
|
+
false
|
|
657
|
+
end
|
|
658
|
+
|
|
659
|
+
def default_plugins
|
|
660
|
+
nil
|
|
661
|
+
end
|
|
662
|
+
|
|
663
|
+
def default_plugin_paths
|
|
664
|
+
["#{root_path}/vendor/plugins"]
|
|
665
|
+
end
|
|
666
|
+
end
|
|
667
|
+
end
|
|
668
|
+
|
|
669
|
+
# Needs to be duplicated from Active Support since its needed before Active
|
|
670
|
+
# Support is available. Here both Options and Hash are namespaced to prevent
|
|
671
|
+
# conflicts with other implementations AND with the classes residing in ActiveSupport.
|
|
672
|
+
class Rails::OrderedOptions < Array #:nodoc:
|
|
673
|
+
def []=(key, value)
|
|
674
|
+
key = key.to_sym
|
|
675
|
+
|
|
676
|
+
if pair = find_pair(key)
|
|
677
|
+
pair.pop
|
|
678
|
+
pair << value
|
|
679
|
+
else
|
|
680
|
+
self << [key, value]
|
|
681
|
+
end
|
|
682
|
+
end
|
|
683
|
+
|
|
684
|
+
def [](key)
|
|
685
|
+
pair = find_pair(key.to_sym)
|
|
686
|
+
pair ? pair.last : nil
|
|
687
|
+
end
|
|
688
|
+
|
|
689
|
+
def method_missing(name, *args)
|
|
690
|
+
if name.to_s =~ /(.*)=$/
|
|
691
|
+
self[$1.to_sym] = args.first
|
|
692
|
+
else
|
|
693
|
+
self[name]
|
|
694
|
+
end
|
|
695
|
+
end
|
|
696
|
+
|
|
697
|
+
private
|
|
698
|
+
def find_pair(key)
|
|
699
|
+
self.each { |i| return i if i.first == key }
|
|
700
|
+
return false
|
|
701
|
+
end
|
|
702
|
+
end
|