authorails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,23 @@
|
|
1
|
+
module RedHillConsulting::Core::ActiveRecord::ConnectionAdapters
|
2
|
+
module SchemaStatements
|
3
|
+
def self.included(base)
|
4
|
+
base.module_eval do
|
5
|
+
alias_method_chain :create_table, :redhillonrails_core
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_table_with_redhillonrails_core(name, options = {})
|
10
|
+
if options.include?(:comment)
|
11
|
+
options = options.dup
|
12
|
+
comment = options.delete(:comment)
|
13
|
+
end
|
14
|
+
|
15
|
+
create_table_without_redhillonrails_core(name, options) do |table_defintion|
|
16
|
+
table_defintion.name = name
|
17
|
+
yield table_defintion if block_given?
|
18
|
+
end
|
19
|
+
|
20
|
+
set_table_comment(name, comment) if comment
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module RedHillConsulting::Core::ActiveRecord::ConnectionAdapters
|
2
|
+
module Sqlite3Adapter
|
3
|
+
def add_foreign_key(table_name, column_names, references_table_name, references_column_names, options = {})
|
4
|
+
end
|
5
|
+
|
6
|
+
def remove_foreign_key(table_name, foreign_key_name)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module RedHillConsulting::Core::ActiveRecord::ConnectionAdapters
|
2
|
+
module TableDefinition
|
3
|
+
def self.included(base)
|
4
|
+
base.class_eval do
|
5
|
+
attr_accessor :name
|
6
|
+
alias_method_chain :initialize, :redhillonrails_core
|
7
|
+
alias_method_chain :to_sql, :redhillonrails_core
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize_with_redhillonrails_core(*args)
|
12
|
+
initialize_without_redhillonrails_core(*args)
|
13
|
+
@foreign_keys = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def foreign_key(column_names, references_table_name, references_column_names, options = {})
|
17
|
+
@foreign_keys << ForeignKeyDefinition.new(options[:name], nil, column_names, ActiveRecord::Migrator.proper_table_name(references_table_name), references_column_names, options[:on_update], options[:on_delete], options[:deferrable])
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_sql_with_redhillonrails_core
|
22
|
+
sql = to_sql_without_redhillonrails_core
|
23
|
+
sql << ', ' << @foreign_keys * ', ' unless @foreign_keys.empty? || ActiveRecord::Schema.defining?
|
24
|
+
sql
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RedHillConsulting::Core::ActiveRecord
|
2
|
+
module Schema
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def self.extended(base)
|
9
|
+
class << base
|
10
|
+
attr_accessor :defining
|
11
|
+
alias :defining? :defining
|
12
|
+
|
13
|
+
alias_method_chain :define, :redhillonrails_core
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def define_with_redhillonrails_core(info={}, &block)
|
18
|
+
self.defining = true
|
19
|
+
define_without_redhillonrails_core(info, &block)
|
20
|
+
ensure
|
21
|
+
self.defining = false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module RedHillConsulting::Core::ActiveRecord
|
2
|
+
module SchemaDumper
|
3
|
+
def self.included(base)
|
4
|
+
base.class_eval do
|
5
|
+
private
|
6
|
+
alias_method_chain :tables, :redhillonrails_core
|
7
|
+
alias_method_chain :indexes, :redhillonrails_core
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def tables_with_redhillonrails_core(stream)
|
14
|
+
@foreign_keys = StringIO.new
|
15
|
+
begin
|
16
|
+
tables_without_redhillonrails_core(stream)
|
17
|
+
@foreign_keys.rewind
|
18
|
+
stream.print @foreign_keys.read
|
19
|
+
views(stream)
|
20
|
+
ensure
|
21
|
+
@foreign_keys = nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def indexes_with_redhillonrails_core(table, stream)
|
26
|
+
indexes = @connection.indexes(table)
|
27
|
+
indexes.each do |index|
|
28
|
+
stream.print " add_index #{index.table.inspect}, #{index.columns.inspect}, :name => #{index.name.inspect}"
|
29
|
+
stream.print ", :unique => true" if index.unique
|
30
|
+
stream.print ", :case_sensitive => false" unless index.case_sensitive?
|
31
|
+
stream.puts
|
32
|
+
end
|
33
|
+
stream.puts unless indexes.empty?
|
34
|
+
|
35
|
+
foreign_keys(table, @foreign_keys)
|
36
|
+
end
|
37
|
+
|
38
|
+
def foreign_keys(table, stream)
|
39
|
+
foreign_keys = @connection.foreign_keys(table)
|
40
|
+
foreign_keys.each do |foreign_key|
|
41
|
+
stream.print " "
|
42
|
+
stream.print foreign_key.to_dump
|
43
|
+
stream.puts
|
44
|
+
end
|
45
|
+
stream.puts unless foreign_keys.empty?
|
46
|
+
end
|
47
|
+
|
48
|
+
def views(stream)
|
49
|
+
views = @connection.views
|
50
|
+
views.each do |view_name|
|
51
|
+
definition = @connection.view_definition(view_name)
|
52
|
+
stream.print " create_view #{view_name.inspect}, #{definition.inspect}"
|
53
|
+
stream.puts
|
54
|
+
end
|
55
|
+
stream.puts unless views.empty?
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
ActiveRecord::Base.send(:include, RedHillConsulting::Core::ActiveRecord::Base)
|
2
|
+
ActiveRecord::Schema.send(:include, RedHillConsulting::Core::ActiveRecord::Schema)
|
3
|
+
ActiveRecord::SchemaDumper.send(:include, RedHillConsulting::Core::ActiveRecord::SchemaDumper)
|
4
|
+
ActiveRecord::ConnectionAdapters::IndexDefinition.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::IndexDefinition)
|
5
|
+
ActiveRecord::ConnectionAdapters::TableDefinition.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::TableDefinition)
|
6
|
+
ActiveRecord::ConnectionAdapters::Column.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::Column)
|
7
|
+
ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::AbstractAdapter)
|
8
|
+
ActiveRecord::ConnectionAdapters::SchemaStatements.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::SchemaStatements)
|
9
|
+
|
10
|
+
if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) then
|
11
|
+
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::PostgresqlAdapter)
|
12
|
+
end
|
13
|
+
if defined?(ActiveRecord::ConnectionAdapters::MysqlAdapter) then
|
14
|
+
ActiveRecord::ConnectionAdapters::MysqlColumn.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::MysqlColumn)
|
15
|
+
ActiveRecord::ConnectionAdapters::MysqlAdapter.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::MysqlAdapter)
|
16
|
+
end
|
17
|
+
if defined?(ActiveRecord::ConnectionAdapters::SQLite3Adapter) then
|
18
|
+
ActiveRecord::ConnectionAdapters::SQLite3Adapter.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::Sqlite3Adapter)
|
19
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
namespace :db do
|
2
|
+
desc "Describe all the tables in the database by reading the table comments"
|
3
|
+
task :comments => :environment do
|
4
|
+
ActiveRecord::Base.connection.tables.sort.each do |table_name|
|
5
|
+
comment = ActiveRecord::Base.connection.table_comment(table_name)
|
6
|
+
puts "#{table_name} - #{comment}"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
[REVISION 20080131]
|
2
|
+
|
3
|
+
[FIXED] belongs_to associations failing when no table exists.
|
4
|
+
|
5
|
+
[REVISION 20071128]
|
6
|
+
|
7
|
+
[FIXED] Workaround to ensure plugin is only ever loaded once.
|
8
|
+
|
9
|
+
[REVISION 20070321]
|
10
|
+
|
11
|
+
[FIXED] Sub-class meta-data missing if loaded before super-class.
|
12
|
+
|
13
|
+
[REVISION 20070302]
|
14
|
+
|
15
|
+
[NEW] Validation may be limited to specific columns by calling schema_validations from within your model class, passing either a single column (:only => :name) or an array of columns (:except => [:isocode, :iddcode]).
|
16
|
+
|
17
|
+
[CHANGED] Use symbols rather than strings when calling validation methods as this seems to be the "way of the future" :).
|
18
|
+
|
19
|
+
[REVISION 20070224]
|
20
|
+
|
21
|
+
[FIXED] Removed useless assignment of class variable.
|
22
|
+
|
23
|
+
[REVISION 20070221]
|
24
|
+
|
25
|
+
[NEW] Where possible, validates_uniqueness_of adds the :case_sensitivity option based on the presence of case-insensitive indexes.
|
26
|
+
|
27
|
+
[REVISION 20061203]
|
28
|
+
|
29
|
+
[CHANGED] Lazily load meta-data during allocate/new rather than inherited.
|
30
|
+
|
31
|
+
[FIXED] Explicit table name ignored.
|
32
|
+
|
33
|
+
[REVISION 20061202]
|
34
|
+
|
35
|
+
[CHANGED] Use Rails 1.2 alias_method_chain.
|
36
|
+
|
37
|
+
[CHANGED] Separate modules into individual files.
|
38
|
+
|
39
|
+
[REVISION 20061114]
|
40
|
+
|
41
|
+
[FIXED] NOT NULL columns with a default not marked as required for update.
|
42
|
+
|
43
|
+
[REVISION 20061013]
|
44
|
+
|
45
|
+
[NEW] install.rb informs user of missing dependencies.
|
46
|
+
|
47
|
+
[REVISION 20061012]
|
48
|
+
|
49
|
+
[CHANGED] Only read meta-data for base-classes.
|
50
|
+
|
51
|
+
[REVISION 20061011]
|
52
|
+
|
53
|
+
[CHANGED] Use include rather than extend in init.rb as this is more general. Plugin code can then determine if it needs to use extend or not.
|
54
|
+
|
55
|
+
[REVISION 20061020]
|
56
|
+
|
57
|
+
[FIXED] Breaks abstract class inheritance. If classes are named 'AbstractXxx' they will be treated as abstract. This is somewhat of a work-around for the current implementation however I believe it is a sensible choice for now.
|
58
|
+
|
59
|
+
[REVISION 20060924]
|
60
|
+
|
61
|
+
[FIXED] validates_uniqueness_of causes new records to fail when nullable column is null and there exists another record where the value of the column is also null. NULL values should always be considered unique.
|
62
|
+
|
63
|
+
[REVISION 20060915]
|
64
|
+
|
65
|
+
[NEW] Multi-column unique indexes are converted to validates_uniqueness_of with scope. The column validated for uniqueness is either the last column not ending in '_id' or simply the last column. This follows the typical composite unique index column ordering where the scoping is specified first but will attempt to find the last non-foreign-key column just-in-case. Eg, both add_index :states, [:country_id, :name], :unique => true and add_index :states, [:name, :country_id], :unique => true would result in <code>validates_uniqueness_of :name, :scope => [:country_id].
|
66
|
+
|
67
|
+
[REVISION 20060914]
|
68
|
+
|
69
|
+
[CHANGED] Removed unnecessary condition from validates_presence_of for associations.
|
70
|
+
|
71
|
+
[REVISION 20060913]
|
72
|
+
|
73
|
+
[FIXED] validates_presence_of for associations causes new records to fail.
|
74
|
+
|
75
|
+
[REVISION 20060912]
|
76
|
+
|
77
|
+
[FIXED] 'Before updating scaffolding from new DB schema, try creating a table for your model (<model>)' when running ./script/generate scaffold <model>. Seems the scaffold sandbox dynamically creates classes which have no name.
|
78
|
+
|
79
|
+
[REVISION 20060911]
|
80
|
+
|
81
|
+
[CHANGED] Revert to nil defaults--as opposed to blank--now that the MySQL behaviour has been patched in redhillonrails_core.
|
82
|
+
|
83
|
+
[REVISION 20060909]
|
84
|
+
|
85
|
+
[NEW] Dependency on RedHill on Rails Core.
|
86
|
+
|
87
|
+
[NEW] validates_uniqueness_of for associations.
|
88
|
+
|
89
|
+
[FIXED] validates_presence_of for associations.
|
90
|
+
|
91
|
+
[REVISION 20060908]
|
92
|
+
|
93
|
+
[FIXED] validates_presence_of not being applied under MySQL; empty defaults are represented as blank rather than nil.
|
94
|
+
|
95
|
+
[NEW] validates_uniqueness_of for associations.
|
96
|
+
|
97
|
+
[REVISION 20060818]
|
98
|
+
|
99
|
+
[FIXED] 'Before updating scaffolding from new DB schema, try creating a table for your model (<model>)' when running ./script/generate scaffold <model>.
|
100
|
+
|
101
|
+
[FIXED] 'relation "system_settings" does not exist' when running a migrate with system_settings plugin installed.
|
102
|
+
|
103
|
+
[REVISION 20060816]
|
104
|
+
|
105
|
+
[FIXED] Overly greedy regex ignoring all date/time columns.
|
106
|
+
|
107
|
+
[REVISION 20060812]
|
108
|
+
|
109
|
+
[CHANGED] Documentation updated to reflect the fact that no further action is required once the plugin is installed.
|
110
|
+
|
111
|
+
[REVISION 20060812]
|
112
|
+
|
113
|
+
[FIXED] Documentation mentions :integer => true options; this should have read :only_integer => true.
|
114
|
+
|
115
|
+
[REVISION 20060803]
|
116
|
+
|
117
|
+
[FIXED] Revision 50 comments out the validates_presence_of magic on line 13 in belongs_to_with_schema_validations.
|
118
|
+
|
119
|
+
[REVISION 20060802]
|
120
|
+
|
121
|
+
[NEW] Support for validates_uniqueness_of for single-column unique indexes.
|
122
|
+
|
123
|
+
[CHANGED] Error message for boolean fields to be the same as the default for validates_presence_of
|
124
|
+
|
125
|
+
[REVISION 20060723]
|
126
|
+
|
127
|
+
[FIXED] Workaround for a "feature" of the way validates_presence_of handles boolean fields. See http://dev.rubyonrails.org/ticket/5090 and http://dev.rubyonrails.org/ticket/3334
|
128
|
+
|
129
|
+
[REVISION 20060719]
|
130
|
+
|
131
|
+
[NEW] Support validates_presence_of for belongs_to associations.
|
132
|
+
|
133
|
+
[REVISION 20060718]
|
134
|
+
|
135
|
+
[FIXED] String test checks #class instead of #klass
|
136
|
+
|
137
|
+
[CHANGED] Separated out check for null from validation of numericality. This means you'll get a "xxx can't be blank" rather than an "xx isn't a number" which seems more intuitive to me.
|
138
|
+
|
139
|
+
[FIXED] Default check should consider nil explicitly to allow for false.
|
140
|
+
|
141
|
+
[REVISION 20060717]
|
142
|
+
|
143
|
+
[NEW] Initial version.
|
144
|
+
|
145
|
+
[FIXED] Ignore columns ending in: _id, _count, _at, _on.
|
146
|
+
|
147
|
+
[NEW] Support validates_numericality_of for numbers (including :integer => true)
|
148
|
+
|
149
|
+
[NEW] Support validates_length_of for strings
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2006 RedHill Consulting, Pty. Ltd.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,54 @@
|
|
1
|
+
= Schema Validations
|
2
|
+
|
3
|
+
Schema Validations is a plugin that reads various constraints defined against
|
4
|
+
columns in your database and applies the closest matching rails validation.
|
5
|
+
(Ala Dave Thomas' Keynote.)
|
6
|
+
|
7
|
+
Over and above installing the plugin, no further action is required for the
|
8
|
+
validations to take effect; the database schema constraints will be read and
|
9
|
+
applied as validations when your ActiveRecord model classes are loaded; just
|
10
|
+
like magic.
|
11
|
+
|
12
|
+
The plugin supports the following constraints:
|
13
|
+
|
14
|
+
* <code>NOT NULL</code> is converted to +validates_presence_of+ (including +belongs_to+ associations);
|
15
|
+
* Numbers are checked using +validates_numericality_of+ (including <code>:only_integer => true</code>);
|
16
|
+
* String lengths are checked using +validates_length_of+;
|
17
|
+
* Single-column unique indexes are converted to +validates_uniqueness_of+; and
|
18
|
+
* Multi-column unique indexes are converted to +validates_uniqueness_of+ with +scope+.
|
19
|
+
|
20
|
+
For multi-column unique indexes the column validated for uniqueness is either
|
21
|
+
the last column not ending in '_id' or simply the last column. This follows the
|
22
|
+
typical composite unique index column ordering where the scoping is specified
|
23
|
+
first but will attempt to find the last non-foreign-key column just-in-case.
|
24
|
+
|
25
|
+
For example, either of the following two statements in a schema migration script:
|
26
|
+
|
27
|
+
add_index :states, [:country_id, :name], :unique => true
|
28
|
+
add_index :states, [:name, :country_id], :unique => true
|
29
|
+
|
30
|
+
would result in:
|
31
|
+
|
32
|
+
validates_uniqueness_of :name, :scope => [:country_id]
|
33
|
+
|
34
|
+
Validation may be limited to specific columns by calling <code>schema_validations</code> from within
|
35
|
+
your model class, passing either a single column:
|
36
|
+
|
37
|
+
class Country < ActiveRecord::Base
|
38
|
+
schema_validations :only => :name
|
39
|
+
end
|
40
|
+
|
41
|
+
or an array of columns:
|
42
|
+
|
43
|
+
class Country < ActiveRecord::Base
|
44
|
+
schema_validations :except => [:isocode, :iddcode]
|
45
|
+
end
|
46
|
+
|
47
|
+
=== Dependencies
|
48
|
+
|
49
|
+
* RedHill on Rails Core (redhillonrails_core).
|
50
|
+
|
51
|
+
=== License
|
52
|
+
|
53
|
+
This plugin is copyright 2006 by RedHill Consulting, Pty. Ltd. and is released
|
54
|
+
under the MIT license.
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'schema_validations' unless defined?(RedHillConsulting::SchemaValidations)
|
@@ -0,0 +1 @@
|
|
1
|
+
puts "WARNING: You also need to install redhillonrails_core" unless File.exists?(File.join(File.dirname(__FILE__), "..", "redhillonrails_core"))
|
data/plugins/schema_validations/lib/red_hill_consulting/schema_validations/active_record/base.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
module RedHillConsulting::SchemaValidations::ActiveRecord
|
2
|
+
module Base
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def self.extended(base)
|
9
|
+
class << base
|
10
|
+
alias_method_chain :allocate, :schema_validations
|
11
|
+
alias_method_chain :new, :schema_validations
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def inherited(child)
|
16
|
+
load_schema_validations unless self == ActiveRecord::Base
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def schema_validations(options = {})
|
21
|
+
column_names = []
|
22
|
+
if options[:only]
|
23
|
+
column_names = options[:only]
|
24
|
+
@schema_validations_column_include = true
|
25
|
+
elsif options[:except]
|
26
|
+
column_names = options[:except]
|
27
|
+
@schema_validations_column_include = false
|
28
|
+
end
|
29
|
+
|
30
|
+
@schema_validations_column_names = Array(column_names).map(&:to_s)
|
31
|
+
end
|
32
|
+
|
33
|
+
def allocate_with_schema_validations
|
34
|
+
load_schema_validations
|
35
|
+
allocate_without_schema_validations
|
36
|
+
end
|
37
|
+
|
38
|
+
def new_with_schema_validations(*args)
|
39
|
+
load_schema_validations
|
40
|
+
new_without_schema_validations(*args) { |*block_args| yield(*block_args) if block_given? }
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
def load_schema_validations
|
46
|
+
# Don't bother if: it's already been loaded; the class is abstract; not a base class; or the table doesn't exist
|
47
|
+
return if @schema_validations_loaded || abstract_class? || !base_class? || name.blank? || !table_exists?
|
48
|
+
@schema_validations_loaded = true
|
49
|
+
load_column_validations
|
50
|
+
load_association_validations
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def load_column_validations
|
56
|
+
content_columns.each do |column|
|
57
|
+
next unless validates?(column)
|
58
|
+
|
59
|
+
name = column.name.to_sym
|
60
|
+
|
61
|
+
# Data-type validation
|
62
|
+
if column.type == :integer
|
63
|
+
validates_numericality_of name, :allow_nil => true, :only_integer => true
|
64
|
+
elsif column.number?
|
65
|
+
validates_numericality_of name, :allow_nil => true
|
66
|
+
elsif column.text? && column.limit
|
67
|
+
validates_length_of name, :allow_nil => true, :maximum => column.limit
|
68
|
+
end
|
69
|
+
|
70
|
+
# NOT NULL constraints
|
71
|
+
if column.required_on
|
72
|
+
# Work-around for a "feature" of the way validates_presence_of handles boolean fields
|
73
|
+
# See http://dev.rubyonrails.org/ticket/5090 and http://dev.rubyonrails.org/ticket/3334
|
74
|
+
if column.type == :boolean
|
75
|
+
validates_inclusion_of name, :on => column.required_on, :in => [true, false], :message => ActiveRecord::Errors.default_error_messages[:blank]
|
76
|
+
else
|
77
|
+
validates_presence_of name, :on => column.required_on
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# UNIQUE constraints
|
82
|
+
validates_uniqueness_of name, :scope => column.unique_scope.map(&:to_sym), :allow_nil => true, :case_sensitive => column.case_sensitive? if column.unique?
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def load_association_validations
|
87
|
+
columns = columns_hash
|
88
|
+
reflect_on_all_associations(:belongs_to).each do |association|
|
89
|
+
column = columns[association.primary_key_name]
|
90
|
+
next unless validates?(column)
|
91
|
+
|
92
|
+
# NOT NULL constraints
|
93
|
+
module_eval(
|
94
|
+
"validates_presence_of :#{column.name}, :on => :#{column.required_on}, :if => lambda { |record| record.#{association.name}.nil? }"
|
95
|
+
) if column.required_on
|
96
|
+
|
97
|
+
# UNIQUE constraints
|
98
|
+
validates_uniqueness_of column.name.to_sym, :scope => column.unique_scope.map(&:to_sym), :allow_nil => true if column.unique?
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def validates?(column)
|
103
|
+
column.name !~ /^(((created|updated)_(at|on))|position)$/ &&
|
104
|
+
(@schema_validations_column_names.nil? || @schema_validations_column_names.include?(column.name) == @schema_validations_column_include)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|