authorails 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (347) hide show
  1. data/AUTHORAILS_README +20 -0
  2. data/CHANGELOG +1366 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README +182 -0
  5. data/Rakefile +334 -0
  6. data/bin/about +3 -0
  7. data/bin/authorails +19 -0
  8. data/bin/breakpointer +3 -0
  9. data/bin/console +3 -0
  10. data/bin/destroy +3 -0
  11. data/bin/generate +3 -0
  12. data/bin/performance/benchmarker +3 -0
  13. data/bin/performance/profiler +3 -0
  14. data/bin/plugin +3 -0
  15. data/bin/process/inspector +3 -0
  16. data/bin/process/reaper +3 -0
  17. data/bin/process/spawner +3 -0
  18. data/bin/runner +3 -0
  19. data/bin/server +3 -0
  20. data/builtin/rails_info/rails/info.rb +123 -0
  21. data/builtin/rails_info/rails/info_controller.rb +9 -0
  22. data/builtin/rails_info/rails/info_helper.rb +2 -0
  23. data/builtin/rails_info/rails_info_controller.rb +2 -0
  24. data/configs/apache.conf +40 -0
  25. data/configs/databases/frontbase.yml +28 -0
  26. data/configs/databases/mysql.yml +48 -0
  27. data/configs/databases/oracle.yml +39 -0
  28. data/configs/databases/postgresql.yml +44 -0
  29. data/configs/databases/sqlite2.yml +16 -0
  30. data/configs/databases/sqlite3.yml +19 -0
  31. data/configs/empty.log +0 -0
  32. data/configs/lighttpd.conf +54 -0
  33. data/configs/routes.rb +23 -0
  34. data/controllers/accounts_controller.rb +11 -0
  35. data/controllers/admin_controller.rb +76 -0
  36. data/controllers/begin_controller.rb +5 -0
  37. data/controllers/login_controller.rb +101 -0
  38. data/controllers/permission_controller.rb +91 -0
  39. data/controllers/roles_controller.rb +58 -0
  40. data/controllers/tables_controller.rb +714 -0
  41. data/dispatches/dispatch.fcgi +24 -0
  42. data/dispatches/dispatch.rb +10 -0
  43. data/dispatches/gateway.cgi +97 -0
  44. data/doc/README_FOR_APP +2 -0
  45. data/environments/boot.rb +45 -0
  46. data/environments/development.rb +21 -0
  47. data/environments/environment.rb +63 -0
  48. data/environments/production.rb +18 -0
  49. data/environments/test.rb +19 -0
  50. data/fresh_rakefile +10 -0
  51. data/helpers/application.rb +607 -0
  52. data/helpers/application_helper.rb +315 -0
  53. data/helpers/permission_helper.rb +27 -0
  54. data/helpers/test_helper.rb +28 -0
  55. data/html/404.html +30 -0
  56. data/html/500.html +30 -0
  57. data/html/favicon.ico +0 -0
  58. data/html/images/ArrowDn.png +0 -0
  59. data/html/images/ArrowUp.png +0 -0
  60. data/html/images/arrow.gif +0 -0
  61. data/html/images/authorails_logo.gif +0 -0
  62. data/html/images/delete.png +0 -0
  63. data/html/images/edit.png +0 -0
  64. data/html/images/minus.gif +0 -0
  65. data/html/images/plus.gif +0 -0
  66. data/html/images/rails.png +0 -0
  67. data/html/images/show.png +0 -0
  68. data/html/images/spinner.gif +0 -0
  69. data/html/index.html +273 -0
  70. data/html/javascripts/application.js +2 -0
  71. data/html/javascripts/controls.js +833 -0
  72. data/html/javascripts/dragdrop.js +942 -0
  73. data/html/javascripts/effects.js +1088 -0
  74. data/html/javascripts/live_validation.js +4 -0
  75. data/html/javascripts/prototype.js +2515 -0
  76. data/html/robots.txt +1 -0
  77. data/lib/authorails/version.rb +9 -0
  78. data/lib/binding_of_caller.rb +85 -0
  79. data/lib/breakpoint.rb +553 -0
  80. data/lib/breakpoint_client.rb +196 -0
  81. data/lib/code_statistics.rb +107 -0
  82. data/lib/commands.rb +17 -0
  83. data/lib/commands/about.rb +2 -0
  84. data/lib/commands/breakpointer.rb +1 -0
  85. data/lib/commands/console.rb +25 -0
  86. data/lib/commands/destroy.rb +6 -0
  87. data/lib/commands/generate.rb +6 -0
  88. data/lib/commands/ncgi/listener +86 -0
  89. data/lib/commands/ncgi/tracker +69 -0
  90. data/lib/commands/performance/benchmarker.rb +24 -0
  91. data/lib/commands/performance/profiler.rb +50 -0
  92. data/lib/commands/plugin.rb +918 -0
  93. data/lib/commands/process/inspector.rb +68 -0
  94. data/lib/commands/process/reaper.rb +149 -0
  95. data/lib/commands/process/spawner.rb +209 -0
  96. data/lib/commands/process/spinner.rb +57 -0
  97. data/lib/commands/runner.rb +48 -0
  98. data/lib/commands/server.rb +39 -0
  99. data/lib/commands/servers/base.rb +19 -0
  100. data/lib/commands/servers/lighttpd.rb +94 -0
  101. data/lib/commands/servers/mongrel.rb +65 -0
  102. data/lib/commands/servers/webrick.rb +59 -0
  103. data/lib/commands/update.rb +4 -0
  104. data/lib/console_app.rb +27 -0
  105. data/lib/console_sandbox.rb +6 -0
  106. data/lib/console_with_helpers.rb +23 -0
  107. data/lib/dispatcher.rb +173 -0
  108. data/lib/fcgi_handler.rb +225 -0
  109. data/lib/initializer.rb +702 -0
  110. data/lib/rails_generator.rb +43 -0
  111. data/lib/rails_generator/base.rb +261 -0
  112. data/lib/rails_generator/commands.rb +581 -0
  113. data/lib/rails_generator/generated_attribute.rb +42 -0
  114. data/lib/rails_generator/generators/applications/app/USAGE +16 -0
  115. data/lib/rails_generator/generators/applications/app/app_generator.rb +341 -0
  116. data/lib/rails_generator/generators/components/controller/USAGE +30 -0
  117. data/lib/rails_generator/generators/components/controller/controller_generator.rb +37 -0
  118. data/lib/rails_generator/generators/components/controller/templates/controller.rb +10 -0
  119. data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +18 -0
  120. data/lib/rails_generator/generators/components/controller/templates/helper.rb +2 -0
  121. data/lib/rails_generator/generators/components/controller/templates/view.rhtml +2 -0
  122. data/lib/rails_generator/generators/components/integration_test/USAGE +14 -0
  123. data/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb +16 -0
  124. data/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +10 -0
  125. data/lib/rails_generator/generators/components/mailer/USAGE +18 -0
  126. data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +34 -0
  127. data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +3 -0
  128. data/lib/rails_generator/generators/components/mailer/templates/mailer.rb +13 -0
  129. data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +37 -0
  130. data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +3 -0
  131. data/lib/rails_generator/generators/components/migration/USAGE +14 -0
  132. data/lib/rails_generator/generators/components/migration/migration_generator.rb +7 -0
  133. data/lib/rails_generator/generators/components/migration/templates/migration.rb +7 -0
  134. data/lib/rails_generator/generators/components/model/USAGE +26 -0
  135. data/lib/rails_generator/generators/components/model/model_generator.rb +38 -0
  136. data/lib/rails_generator/generators/components/model/templates/fixtures.yml +11 -0
  137. data/lib/rails_generator/generators/components/model/templates/migration.rb +13 -0
  138. data/lib/rails_generator/generators/components/model/templates/model.rb +2 -0
  139. data/lib/rails_generator/generators/components/model/templates/unit_test.rb +10 -0
  140. data/lib/rails_generator/generators/components/observer/USAGE +15 -0
  141. data/lib/rails_generator/generators/components/observer/observer_generator.rb +16 -0
  142. data/lib/rails_generator/generators/components/observer/templates/observer.rb +2 -0
  143. data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +10 -0
  144. data/lib/rails_generator/generators/components/plugin/USAGE +35 -0
  145. data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +38 -0
  146. data/lib/rails_generator/generators/components/plugin/templates/README +4 -0
  147. data/lib/rails_generator/generators/components/plugin/templates/Rakefile +22 -0
  148. data/lib/rails_generator/generators/components/plugin/templates/USAGE +8 -0
  149. data/lib/rails_generator/generators/components/plugin/templates/generator.rb +8 -0
  150. data/lib/rails_generator/generators/components/plugin/templates/init.rb +1 -0
  151. data/lib/rails_generator/generators/components/plugin/templates/install.rb +1 -0
  152. data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +1 -0
  153. data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +4 -0
  154. data/lib/rails_generator/generators/components/plugin/templates/uninstall.rb +1 -0
  155. data/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +8 -0
  156. data/lib/rails_generator/generators/components/resource/resource_generator.rb +76 -0
  157. data/lib/rails_generator/generators/components/resource/templates/USAGE +18 -0
  158. data/lib/rails_generator/generators/components/resource/templates/controller.rb +2 -0
  159. data/lib/rails_generator/generators/components/resource/templates/fixtures.yml +11 -0
  160. data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +20 -0
  161. data/lib/rails_generator/generators/components/resource/templates/helper.rb +2 -0
  162. data/lib/rails_generator/generators/components/resource/templates/migration.rb +13 -0
  163. data/lib/rails_generator/generators/components/resource/templates/model.rb +2 -0
  164. data/lib/rails_generator/generators/components/resource/templates/unit_test.rb +10 -0
  165. data/lib/rails_generator/generators/components/scaffold/USAGE +32 -0
  166. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +208 -0
  167. data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +134 -0
  168. data/lib/rails_generator/generators/components/scaffold/templates/form.rhtml +3 -0
  169. data/lib/rails_generator/generators/components/scaffold/templates/form_scaffolding.rhtml +35 -0
  170. data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +102 -0
  171. data/lib/rails_generator/generators/components/scaffold/templates/helper.rb +2 -0
  172. data/lib/rails_generator/generators/components/scaffold/templates/layout.rhtml +17 -0
  173. data/lib/rails_generator/generators/components/scaffold/templates/partial_list_elements.rhtml +127 -0
  174. data/lib/rails_generator/generators/components/scaffold/templates/style.css +74 -0
  175. data/lib/rails_generator/generators/components/scaffold/templates/view_edit.rhtml +75 -0
  176. data/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml +30 -0
  177. data/lib/rails_generator/generators/components/scaffold/templates/view_new.rhtml +8 -0
  178. data/lib/rails_generator/generators/components/scaffold/templates/view_show.rhtml +37 -0
  179. data/lib/rails_generator/generators/components/scaffold_resource/USAGE +29 -0
  180. data/lib/rails_generator/generators/components/scaffold_resource/scaffold_resource_generator.rb +92 -0
  181. data/lib/rails_generator/generators/components/scaffold_resource/templates/controller.rb +79 -0
  182. data/lib/rails_generator/generators/components/scaffold_resource/templates/fixtures.yml +11 -0
  183. data/lib/rails_generator/generators/components/scaffold_resource/templates/functional_test.rb +57 -0
  184. data/lib/rails_generator/generators/components/scaffold_resource/templates/helper.rb +2 -0
  185. data/lib/rails_generator/generators/components/scaffold_resource/templates/layout.rhtml +17 -0
  186. data/lib/rails_generator/generators/components/scaffold_resource/templates/migration.rb +13 -0
  187. data/lib/rails_generator/generators/components/scaffold_resource/templates/model.rb +2 -0
  188. data/lib/rails_generator/generators/components/scaffold_resource/templates/style.css +74 -0
  189. data/lib/rails_generator/generators/components/scaffold_resource/templates/unit_test.rb +10 -0
  190. data/lib/rails_generator/generators/components/scaffold_resource/templates/view_edit.rhtml +19 -0
  191. data/lib/rails_generator/generators/components/scaffold_resource/templates/view_index.rhtml +24 -0
  192. data/lib/rails_generator/generators/components/scaffold_resource/templates/view_new.rhtml +18 -0
  193. data/lib/rails_generator/generators/components/scaffold_resource/templates/view_show.rhtml +10 -0
  194. data/lib/rails_generator/generators/components/session_migration/USAGE +15 -0
  195. data/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb +18 -0
  196. data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +16 -0
  197. data/lib/rails_generator/generators/components/web_service/USAGE +28 -0
  198. data/lib/rails_generator/generators/components/web_service/templates/api_definition.rb +5 -0
  199. data/lib/rails_generator/generators/components/web_service/templates/controller.rb +8 -0
  200. data/lib/rails_generator/generators/components/web_service/templates/functional_test.rb +19 -0
  201. data/lib/rails_generator/generators/components/web_service/web_service_generator.rb +29 -0
  202. data/lib/rails_generator/lookup.rb +209 -0
  203. data/lib/rails_generator/manifest.rb +53 -0
  204. data/lib/rails_generator/options.rb +143 -0
  205. data/lib/rails_generator/scripts.rb +83 -0
  206. data/lib/rails_generator/scripts/destroy.rb +7 -0
  207. data/lib/rails_generator/scripts/generate.rb +7 -0
  208. data/lib/rails_generator/scripts/update.rb +12 -0
  209. data/lib/rails_generator/simple_logger.rb +46 -0
  210. data/lib/rails_generator/spec.rb +44 -0
  211. data/lib/railties_path.rb +1 -0
  212. data/lib/ruby_version_check.rb +17 -0
  213. data/lib/rubyprof_ext.rb +35 -0
  214. data/lib/tasks/databases.rake +187 -0
  215. data/lib/tasks/documentation.rake +82 -0
  216. data/lib/tasks/framework.rake +112 -0
  217. data/lib/tasks/log.rake +9 -0
  218. data/lib/tasks/misc.rake +4 -0
  219. data/lib/tasks/pre_namespace_aliases.rake +53 -0
  220. data/lib/tasks/rails.rb +8 -0
  221. data/lib/tasks/statistics.rake +18 -0
  222. data/lib/tasks/testing.rake +120 -0
  223. data/lib/tasks/tmp.rake +37 -0
  224. data/lib/test_help.rb +19 -0
  225. data/lib/webrick_server.rb +166 -0
  226. data/libs/migration_helper.rb +11 -0
  227. data/migrations/001_create_logins.rb +22 -0
  228. data/migrations/002_create_admins.rb +16 -0
  229. data/migrations/003_create_roles.rb +13 -0
  230. data/migrations/004_create_tables.rb +11 -0
  231. data/migrations/005_create_attr_types.rb +13 -0
  232. data/migrations/006_create_table_fields.rb +22 -0
  233. data/migrations/007_create_tab_operations.rb +13 -0
  234. data/migrations/008_create_attr_operations.rb +13 -0
  235. data/migrations/009_create_tab_permissions.rb +21 -0
  236. data/migrations/010_create_attr_permissions.rb +21 -0
  237. data/migrations/011_create_relations.rb +23 -0
  238. data/migrations/012_create_scaffolds.rb +11 -0
  239. data/migrations/013_create_relation_permissions.rb +20 -0
  240. data/models/admin.rb +38 -0
  241. data/models/attr_operation.rb +3 -0
  242. data/models/attr_permission.rb +5 -0
  243. data/models/attr_type.rb +3 -0
  244. data/models/login.rb +51 -0
  245. data/models/relation.rb +5 -0
  246. data/models/relation_permission.rb +4 -0
  247. data/models/role.rb +13 -0
  248. data/models/scaffold.rb +2 -0
  249. data/models/tab_operation.rb +3 -0
  250. data/models/tab_permission.rb +5 -0
  251. data/models/table.rb +18 -0
  252. data/models/table_field.rb +6 -0
  253. data/plugins/redhillonrails_core/CHANGELOG +186 -0
  254. data/plugins/redhillonrails_core/MIT-LICENSE +20 -0
  255. data/plugins/redhillonrails_core/README +152 -0
  256. data/plugins/redhillonrails_core/init.rb +1 -0
  257. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb +54 -0
  258. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/abstract_adapter.rb +46 -0
  259. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/column.rb +21 -0
  260. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb +26 -0
  261. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/index_definition.rb +11 -0
  262. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/mysql_adapter.rb +94 -0
  263. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/mysql_column.rb +8 -0
  264. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/postgresql_adapter.rb +131 -0
  265. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/schema_statements.rb +23 -0
  266. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/sqlite3_adapter.rb +9 -0
  267. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/table_definition.rb +27 -0
  268. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema.rb +25 -0
  269. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb +58 -0
  270. data/plugins/redhillonrails_core/lib/redhillonrails_core.rb +19 -0
  271. data/plugins/redhillonrails_core/tasks/db/comments.rake +9 -0
  272. data/plugins/schema_validations/CHANGELOG +149 -0
  273. data/plugins/schema_validations/MIT-LICENSE +20 -0
  274. data/plugins/schema_validations/README +54 -0
  275. data/plugins/schema_validations/about.yml +5 -0
  276. data/plugins/schema_validations/init.rb +1 -0
  277. data/plugins/schema_validations/install.rb +1 -0
  278. data/plugins/schema_validations/lib/red_hill_consulting/schema_validations/active_record/base.rb +108 -0
  279. data/plugins/schema_validations/lib/schema_validations.rb +1 -0
  280. data/plugins/svn/README +69 -0
  281. data/plugins/svn/Rakefile +22 -0
  282. data/plugins/svn/assets/javascripts/live_validation.js +4 -0
  283. data/plugins/svn/assets/stylesheets/live_validation.css +28 -0
  284. data/plugins/svn/init.rb +2 -0
  285. data/plugins/svn/install.rb +1 -0
  286. data/plugins/svn/lib/form_helpers.rb +49 -0
  287. data/plugins/svn/lib/live_validations.rb +73 -0
  288. data/plugins/svn/tasks/live_validation_tasks.rake +17 -0
  289. data/plugins/svn/test/form_helpers_test.rb +214 -0
  290. data/plugins/svn/test/live_validations_test.rb +124 -0
  291. data/plugins/svn/test/resource.rb +17 -0
  292. data/plugins/svn/uninstall.rb +1 -0
  293. data/stylesheets/live_validation.css +28 -0
  294. data/stylesheets/print.css +72 -0
  295. data/stylesheets/scaffold.css +175 -0
  296. data/views/accounts/index.rhtml +12 -0
  297. data/views/accounts/show.rhtml +5 -0
  298. data/views/admin/_form.rhtml +15 -0
  299. data/views/admin/add_user.rhtml +21 -0
  300. data/views/admin/change_pwd.rhtml +23 -0
  301. data/views/admin/edit_user.rhtml +12 -0
  302. data/views/admin/index.rhtml +19 -0
  303. data/views/begin/index.rhtml +0 -0
  304. data/views/layouts/general.rhtml +59 -0
  305. data/views/layouts/login.rhtml +18 -0
  306. data/views/login/change_pwd.rhtml +21 -0
  307. data/views/login/expired_pwd.rhtml +19 -0
  308. data/views/login/index.rhtml +15 -0
  309. data/views/permission/index.rhtml +17 -0
  310. data/views/permission/relations.rhtml +28 -0
  311. data/views/permission/roles.rhtml +45 -0
  312. data/views/permission/tables.rhtml +53 -0
  313. data/views/roles/_form.rhtml +8 -0
  314. data/views/roles/edit.rhtml +11 -0
  315. data/views/roles/list.rhtml +28 -0
  316. data/views/roles/new.rhtml +8 -0
  317. data/views/roles/show.rhtml +14 -0
  318. data/views/shared_views/_advanced_search.rhtml +35 -0
  319. data/views/shared_views/_child_elements.rhtml +30 -0
  320. data/views/shared_views/_childs.rhtml +20 -0
  321. data/views/shared_views/_father_elements.rhtml +27 -0
  322. data/views/shared_views/_fathers.rhtml +21 -0
  323. data/views/shared_views/_fathers_header.rhtml +58 -0
  324. data/views/shared_views/_many_to_many_elements.rhtml +50 -0
  325. data/views/shared_views/_many_to_manys.rhtml +18 -0
  326. data/views/shared_views/_one_to_one_elements.rhtml +24 -0
  327. data/views/shared_views/_one_to_one_father_elements.rhtml +26 -0
  328. data/views/shared_views/_one_to_ones.rhtml +42 -0
  329. data/views/shared_views/_one_to_ones_header.rhtml +117 -0
  330. data/views/shared_views/edit_child.rhtml +89 -0
  331. data/views/shared_views/edit_many.rhtml +75 -0
  332. data/views/tables/_cascade.rhtml +10 -0
  333. data/views/tables/_field.rhtml +10 -0
  334. data/views/tables/_fk.rhtml +9 -0
  335. data/views/tables/_form.rhtml +9 -0
  336. data/views/tables/_join_table_name.rhtml +16 -0
  337. data/views/tables/_relation_types.rhtml +5 -0
  338. data/views/tables/_tables.rhtml +15 -0
  339. data/views/tables/attributes.rhtml +15 -0
  340. data/views/tables/edit.rhtml +11 -0
  341. data/views/tables/edit_field.rhtml +18 -0
  342. data/views/tables/list.rhtml +39 -0
  343. data/views/tables/new.rhtml +8 -0
  344. data/views/tables/new_field.rhtml +25 -0
  345. data/views/tables/relations.rhtml +24 -0
  346. data/views/tables/show.rhtml +24 -0
  347. 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,5 @@
1
+ author: simon@redhillconsulting.com.au
2
+ summary: Reads various constraints defined against columns in your database and applies the closest matching rails validation.
3
+ homepage: http://www.redhillonrails.org
4
+ license: MIT
5
+ rails_version: EDGE
@@ -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"))
@@ -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