hobo 1.1.0 → 1.3.0.RC

Sign up to get free protection for your applications and to get access to all the features.
Files changed (278) hide show
  1. data/CHANGES.txt +238 -287
  2. data/Rakefile +14 -31
  3. data/VERSION +1 -0
  4. data/{lib/hobo → app/controllers}/dev_controller.rb +6 -6
  5. data/app/controllers/dryml_support_controller.rb +13 -0
  6. data/{rails_generators/hobo_front_controller/templates → app/views/dev}/summary.dryml +7 -10
  7. data/bin/hobo +12 -144
  8. data/config/initializers/inflections.rb +3 -0
  9. data/config/routes.rb +6 -0
  10. data/{doctest → doctests}/hobo/lifecycles.rdoctest +40 -59
  11. data/{doctest → doctests/hobo}/model.rdoctest +33 -40
  12. data/{doctest → doctests/hobo}/multi_model_forms.rdoctest +15 -19
  13. data/{doctest → doctests/hobo}/scopes.rdoctest +27 -41
  14. data/doctests/prepare_testapp.rb +8 -0
  15. data/hobo.gemspec +26 -199
  16. data/lib/generators/hobo/activation_email.rb +11 -0
  17. data/lib/generators/hobo/admin_subsite/admin_subsite_generator.rb +35 -0
  18. data/lib/generators/hobo/admin_subsite/templates/admin.css +20 -0
  19. data/lib/generators/hobo/admin_subsite/templates/admin_tag_injection.erb +10 -0
  20. data/{rails_generators/hobo_admin_site → lib/generators/hobo/admin_subsite}/templates/application.dryml +0 -0
  21. data/{rails_generators/hobo_admin_site/templates/controller.rb → lib/generators/hobo/admin_subsite/templates/controller.rb.erb} +5 -5
  22. data/lib/generators/hobo/admin_subsite/templates/users_index.dryml +7 -0
  23. data/lib/generators/hobo/assets/assets_generator.rb +18 -0
  24. data/{rails_generators/hobo → lib/generators/hobo/assets}/templates/application.css +0 -0
  25. data/lib/generators/hobo/assets/templates/application.dryml.erb +9 -0
  26. data/{rails_generators/hobo → lib/generators/hobo/assets}/templates/dryml-support.js +2 -2
  27. data/lib/generators/hobo/assets/templates/dryml_taglibs_initializer.rb +1 -0
  28. data/lib/generators/hobo/assets/templates/en_injection.yml +19 -0
  29. data/{rails_generators/hobo → lib/generators/hobo/assets}/templates/guest.rb +1 -1
  30. data/lib/generators/hobo/controller.rb +35 -0
  31. data/lib/generators/hobo/controller/controller_generator.rb +6 -0
  32. data/lib/generators/hobo/controller/templates/controller.rb.erb +7 -0
  33. data/{rails_generators/hobo_front_controller → lib/generators/hobo/front_controller}/USAGE +0 -0
  34. data/lib/generators/hobo/front_controller/front_controller_generator.rb +55 -0
  35. data/{rails_generators/hobo_front_controller/templates/controller.rb → lib/generators/hobo/front_controller/templates/controller.rb.erb} +0 -0
  36. data/{rails_generators/hobo_front_controller → lib/generators/hobo/front_controller}/templates/index.dryml +6 -12
  37. data/lib/generators/hobo/i18n/i18n_generator.rb +35 -0
  38. data/lib/generators/hobo/i18n/templates/app.de.yml +30 -0
  39. data/lib/generators/hobo/i18n/templates/app.en.yml +25 -0
  40. data/lib/generators/hobo/i18n/templates/app.es.yml +31 -0
  41. data/lib/generators/hobo/i18n/templates/app.fr.yml +26 -0
  42. data/lib/generators/hobo/i18n/templates/app.it.yml +28 -0
  43. data/lib/generators/hobo/i18n/templates/app.pt-PT.yml +25 -0
  44. data/lib/generators/hobo/i18n/templates/app.ru.yml +24 -0
  45. data/lib/generators/hobo/i18n/templates/hobo.de.yml +204 -0
  46. data/lib/generators/hobo/i18n/templates/hobo.en.yml +195 -0
  47. data/lib/generators/hobo/i18n/templates/hobo.es.yml +202 -0
  48. data/lib/generators/hobo/i18n/templates/hobo.fr.yml +195 -0
  49. data/lib/generators/hobo/i18n/templates/hobo.it.yml +202 -0
  50. data/lib/generators/hobo/i18n/templates/hobo.pt-PT.yml +196 -0
  51. data/lib/generators/hobo/i18n/templates/hobo.ru.yml +200 -0
  52. data/lib/generators/hobo/invite_only.rb +18 -0
  53. data/lib/generators/hobo/model/USAGE +19 -0
  54. data/lib/generators/hobo/model/model_generator.rb +11 -0
  55. data/{rails_generators/hobo_model/templates/model.rb → lib/generators/hobo/model/templates/model_injection.rb.erb} +0 -2
  56. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/USAGE +0 -0
  57. data/lib/generators/hobo/rapid/rapid_generator.rb +24 -0
  58. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/IE7.js +0 -0
  59. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/blank.gif +0 -0
  60. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/hobo-rapid.css +0 -0
  61. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/hobo-rapid.js +65 -65
  62. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/ie7-recalc.js +21 -21
  63. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/lowpro.js +31 -31
  64. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/reset.css +1 -1
  65. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-ACD3E6-DBE1E5-H.png +0 -0
  66. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-DBE1E5-FCFEF5-H.png +0 -0
  67. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/300-3B5F87-ACD3E6-H.png +0 -0
  68. data/{rails_generators/hobo_rapid/templates/themes/clean → lib/generators/hobo/rapid/templates/themes/clean-sidemenu}/public/images/spinner.gif +0 -0
  69. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/stylesheets/clean-sidemenu.css +81 -0
  70. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/views/clean-sidemenu.dryml +30 -0
  71. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/101-3B5F87-ACD3E6.png +0 -0
  72. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/30-3E547A-242E42.png +0 -0
  73. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/30-DBE1E5-FCFEF5.png +0 -0
  74. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/300-ACD3E6-fff.png +0 -0
  75. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/50-ACD3E6-fff.png +0 -0
  76. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/fieldbg.gif +0 -0
  77. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/pencil.png +0 -0
  78. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/small_close.png +0 -0
  79. data/lib/generators/hobo/rapid/templates/themes/clean/public/images/spinner.gif +0 -0
  80. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/stylesheets/clean.css +16 -16
  81. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/stylesheets/rapid-ui.css +3 -3
  82. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/views/clean.dryml +1 -1
  83. data/lib/generators/hobo/resource/resource_generator.rb +23 -0
  84. data/lib/generators/hobo/routes/USAGE +9 -0
  85. data/lib/generators/hobo/routes/router.rb +115 -0
  86. data/lib/generators/hobo/routes/routes_generator.rb +40 -0
  87. data/lib/generators/hobo/routes/templates/hobo_routes.rb.erb +33 -0
  88. data/lib/generators/hobo/setup_wizard/USAGE +4 -0
  89. data/lib/generators/hobo/setup_wizard/setup_wizard_generator.rb +274 -0
  90. data/lib/generators/hobo/subsite.rb +48 -0
  91. data/lib/generators/hobo/subsite/subsite_generator.rb +16 -0
  92. data/{rails_generators/hobo_subsite → lib/generators/hobo/subsite}/templates/application.dryml +0 -0
  93. data/{rails_generators/hobo_subsite/templates/controller.rb → lib/generators/hobo/subsite/templates/controller.rb.erb} +1 -1
  94. data/lib/generators/hobo/subsite_taglib/subsite_taglib_generator.rb +16 -0
  95. data/{rails_generators/hobo_admin_site/templates/site_taglib.dryml → lib/generators/hobo/subsite_taglib/templates/taglib.dryml.erb} +9 -10
  96. data/lib/generators/hobo/taglib.rb +12 -0
  97. data/lib/generators/hobo/test_framework/test_framework_generator.rb +72 -0
  98. data/lib/generators/hobo/test_options.rb +19 -0
  99. data/{rails_generators/hobo_user_controller → lib/generators/hobo/user_controller}/templates/accept_invitation.dryml +0 -0
  100. data/lib/generators/hobo/user_controller/templates/controller.rb.erb +31 -0
  101. data/lib/generators/hobo/user_controller/user_controller_generator.rb +25 -0
  102. data/lib/generators/hobo/user_mailer/templates/activation.erb +9 -0
  103. data/{rails_generators/hobo_user_model → lib/generators/hobo/user_mailer}/templates/forgot_password.erb +2 -2
  104. data/{rails_generators/hobo_user_model → lib/generators/hobo/user_mailer}/templates/invite.erb +2 -2
  105. data/lib/generators/hobo/user_mailer/templates/mailer.rb.erb +25 -0
  106. data/lib/generators/hobo/user_mailer/user_mailer_generator.rb +33 -0
  107. data/lib/generators/hobo/user_model/USAGE +12 -0
  108. data/{rails_generators/hobo_user_model/templates/model.rb → lib/generators/hobo/user_model/templates/model_injection.rb.erb} +40 -20
  109. data/lib/generators/hobo/user_model/user_model_generator.rb +23 -0
  110. data/lib/generators/hobo/user_resource/user_resource_generator.rb +27 -0
  111. data/lib/hobo.rb +29 -129
  112. data/lib/hobo/controller.rb +37 -47
  113. data/lib/hobo/controller/authentication_support.rb +109 -0
  114. data/lib/hobo/{model_controller.rb → controller/model.rb} +71 -79
  115. data/lib/hobo/{user_controller.rb → controller/user.rb} +59 -49
  116. data/lib/hobo/engine.rb +80 -0
  117. data/lib/hobo/extensions/action_controller/hobo_methods.rb +44 -0
  118. data/lib/hobo/extensions/action_mailer/helper.rb +38 -0
  119. data/lib/{action_view_extensions/helpers → hobo/extensions/action_view}/tag_helper.rb +5 -2
  120. data/lib/hobo/extensions/action_view/translation_helper.rb +25 -0
  121. data/lib/hobo/extensions/active_model/name.rb +16 -0
  122. data/lib/hobo/extensions/active_model/translation.rb +35 -0
  123. data/lib/{active_record/association_collection.rb → hobo/extensions/active_record/associations/collection.rb} +8 -17
  124. data/lib/{active_record/association_proxy.rb → hobo/extensions/active_record/associations/proxy.rb} +6 -7
  125. data/lib/hobo/extensions/active_record/associations/reflection.rb +23 -0
  126. data/lib/hobo/extensions/active_record/associations/scope.rb +35 -0
  127. data/lib/hobo/extensions/active_record/hobo_methods.rb +11 -0
  128. data/lib/hobo/extensions/active_record/permissions.rb +159 -0
  129. data/lib/hobo/extensions/active_record/relation_with_origin.rb +28 -0
  130. data/lib/hobo/extensions/array.rb +27 -0
  131. data/lib/hobo/extensions/enumerable.rb +12 -0
  132. data/lib/hobo/extensions/i18n.rb +17 -0
  133. data/lib/hobo/{hobo_helper.rb → helper.rb} +58 -31
  134. data/lib/hobo/helper/translations.rb +54 -0
  135. data/lib/hobo/helper/translations/normalizer.rb +39 -0
  136. data/lib/hobo/model.rb +61 -95
  137. data/lib/hobo/model/accessible_associations.rb +178 -0
  138. data/lib/hobo/{find_for.rb → model/find_for.rb} +17 -17
  139. data/lib/hobo/model/guest.rb +25 -0
  140. data/lib/hobo/model/include_in_save.rb +55 -0
  141. data/lib/hobo/model/lifecycles.rb +119 -0
  142. data/lib/hobo/model/lifecycles/actions.rb +146 -0
  143. data/lib/hobo/model/lifecycles/creator.rb +74 -0
  144. data/lib/hobo/model/lifecycles/lifecycle.rb +243 -0
  145. data/lib/hobo/model/lifecycles/state.rb +22 -0
  146. data/lib/hobo/model/lifecycles/transition.rb +70 -0
  147. data/lib/hobo/model/permissions.rb +448 -0
  148. data/lib/hobo/model/scopes.rb +38 -0
  149. data/lib/hobo/model/scopes/apply_scopes.rb +21 -0
  150. data/lib/hobo/model/scopes/automatic_scopes.rb +428 -0
  151. data/lib/hobo/model/user_base.rb +184 -0
  152. data/lib/hobo/model/view_hints.rb +123 -0
  153. data/{rapid_generators → lib/hobo/rapid/generators}/rapid/cards.dryml.erb +2 -2
  154. data/{rapid_generators → lib/hobo/rapid/generators}/rapid/forms.dryml.erb +3 -3
  155. data/{rapid_generators → lib/hobo/rapid/generators}/rapid/pages.dryml.erb +38 -51
  156. data/lib/hobo/rapid/helper.rb +166 -0
  157. data/{taglibs → lib/hobo/rapid/taglibs}/rapid.dryml +6 -5
  158. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_core.dryml +286 -118
  159. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_document_tags.dryml +2 -2
  160. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_editing.dryml +45 -45
  161. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_forms.dryml +190 -158
  162. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_generics.dryml +12 -9
  163. data/lib/hobo/rapid/taglibs/rapid_i18n.dryml +107 -0
  164. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_lifecycles.dryml +7 -7
  165. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_navigation.dryml +15 -15
  166. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_pages.dryml +37 -36
  167. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_plus.dryml +107 -43
  168. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_summary.dryml +28 -57
  169. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_support.dryml +9 -9
  170. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_user_pages.dryml +41 -40
  171. data/lib/hobo/routes.rb +31 -0
  172. data/{doctest → test/doctest}/hobo/hobo_helper.rdoctest +11 -11
  173. data/test/irt/generators/admin_subsite.irt +27 -0
  174. data/test/irt/generators/assets.irt +16 -0
  175. data/test/irt/generators/controller.irt +6 -0
  176. data/test/irt/generators/front_controller.irt +30 -0
  177. data/test/irt/generators/helper.rb +31 -0
  178. data/test/irt/generators/model.irt +28 -0
  179. data/test/irt/generators/partials/_account_user_model_tests.rb +21 -0
  180. data/test/irt/generators/partials/_accounts_users_controller_tests.rb +15 -0
  181. data/test/irt/generators/partials/_default_user_model_tests.rb +21 -0
  182. data/test/irt/generators/partials/_default_users_controller_tests.rb +16 -0
  183. data/test/irt/generators/partials/_house_controller_tests.rb +15 -0
  184. data/test/irt/generators/partials/_house_model_tests.rb +18 -0
  185. data/test/irt/generators/partials/_subsite_taglib_admin.rb +4 -0
  186. data/test/irt/generators/partials/_subsite_taglib_admin_invite_only.rb +3 -0
  187. data/test/irt/generators/partials/_subsite_taglib_noopt.rb +4 -0
  188. data/test/irt/generators/partials/_subsite_taglib_variables.rb +27 -0
  189. data/test/irt/generators/partials/_user_mailer_tests.rb +19 -0
  190. data/test/irt/generators/rapid.irt +29 -0
  191. data/test/irt/generators/resource.irt +8 -0
  192. data/test/irt/generators/subsite.irt +52 -0
  193. data/test/irt/generators/subsite_taglib.irt +23 -0
  194. data/test/irt/generators/test_framework.irt +62 -0
  195. data/test/irt/generators/user_controller.irt +10 -0
  196. data/test/irt/generators/user_mailer.irt +20 -0
  197. data/test/irt/generators/user_model.irt +10 -0
  198. data/test/irt/generators/user_resource.irt +14 -0
  199. data/test/irt/readme.txt +7 -0
  200. data/test/permissions/models/models.rb +27 -24
  201. data/test/permissions/test_permissions.rb +104 -104
  202. metadata +239 -217
  203. data/lib/active_record/association_reflection.rb +0 -20
  204. data/lib/active_record/viewhints_validations_interceptor.rb +0 -9
  205. data/lib/hobo/accessible_associations.rb +0 -183
  206. data/lib/hobo/authentication_support.rb +0 -131
  207. data/lib/hobo/generator.rb +0 -26
  208. data/lib/hobo/guest.rb +0 -25
  209. data/lib/hobo/include_in_save.rb +0 -55
  210. data/lib/hobo/lifecycles.rb +0 -137
  211. data/lib/hobo/lifecycles/actions.rb +0 -142
  212. data/lib/hobo/lifecycles/creator.rb +0 -72
  213. data/lib/hobo/lifecycles/lifecycle.rb +0 -249
  214. data/lib/hobo/lifecycles/state.rb +0 -22
  215. data/lib/hobo/lifecycles/transition.rb +0 -70
  216. data/lib/hobo/model_router.rb +0 -290
  217. data/lib/hobo/permissions.rb +0 -451
  218. data/lib/hobo/permissions/associations.rb +0 -175
  219. data/lib/hobo/rapid_helper.rb +0 -157
  220. data/lib/hobo/scopes.rb +0 -43
  221. data/lib/hobo/scopes/apply_scopes.rb +0 -23
  222. data/lib/hobo/scopes/association_proxy_extensions.rb +0 -62
  223. data/lib/hobo/scopes/automatic_scopes.rb +0 -421
  224. data/lib/hobo/scopes/named_scope_extensions.rb +0 -39
  225. data/lib/hobo/tasks/rails.rb +0 -4
  226. data/lib/hobo/translations.rb +0 -93
  227. data/lib/hobo/undefined_access_error.rb +0 -5
  228. data/lib/hobo/user.rb +0 -182
  229. data/lib/hobo/view_hints.rb +0 -115
  230. data/rails/init.rb +0 -10
  231. data/rails_generators/hobo/USAGE +0 -4
  232. data/rails_generators/hobo/hobo_generator.rb +0 -53
  233. data/rails_generators/hobo/templates/application.dryml +0 -1
  234. data/rails_generators/hobo/templates/initializer.rb +0 -2
  235. data/rails_generators/hobo_admin_site/USAGE +0 -16
  236. data/rails_generators/hobo_admin_site/hobo_admin_site_generator.rb +0 -45
  237. data/rails_generators/hobo_admin_site/templates/admin.css +0 -2
  238. data/rails_generators/hobo_admin_site/templates/users_index.dryml +0 -5
  239. data/rails_generators/hobo_front_controller/hobo_front_controller_generator.rb +0 -95
  240. data/rails_generators/hobo_front_controller/templates/functional_test.rb +0 -8
  241. data/rails_generators/hobo_front_controller/templates/helper.rb +0 -2
  242. data/rails_generators/hobo_model/USAGE +0 -25
  243. data/rails_generators/hobo_model/hobo_model_generator.rb +0 -43
  244. data/rails_generators/hobo_model/templates/fixtures.yml +0 -6
  245. data/rails_generators/hobo_model/templates/hints.rb +0 -7
  246. data/rails_generators/hobo_model/templates/unit_test.rb +0 -8
  247. data/rails_generators/hobo_model_controller/USAGE +0 -30
  248. data/rails_generators/hobo_model_controller/hobo_model_controller_generator.rb +0 -46
  249. data/rails_generators/hobo_model_controller/templates/controller.rb +0 -7
  250. data/rails_generators/hobo_model_controller/templates/functional_test.rb +0 -8
  251. data/rails_generators/hobo_model_controller/templates/helper.rb +0 -2
  252. data/rails_generators/hobo_model_resource/USAGE +0 -38
  253. data/rails_generators/hobo_model_resource/hobo_model_resource_generator.rb +0 -73
  254. data/rails_generators/hobo_model_resource/templates/controller.rb +0 -7
  255. data/rails_generators/hobo_model_resource/templates/functional_test.rb +0 -8
  256. data/rails_generators/hobo_model_resource/templates/helper.rb +0 -2
  257. data/rails_generators/hobo_rapid/hobo_rapid_generator.rb +0 -94
  258. data/rails_generators/hobo_subsite/USAGE +0 -16
  259. data/rails_generators/hobo_subsite/hobo_subsite_generator.rb +0 -73
  260. data/rails_generators/hobo_subsite/templates/site_taglib.dryml +0 -13
  261. data/rails_generators/hobo_user_controller/USAGE +0 -34
  262. data/rails_generators/hobo_user_controller/hobo_user_controller_generator.rb +0 -65
  263. data/rails_generators/hobo_user_controller/templates/controller.rb +0 -29
  264. data/rails_generators/hobo_user_controller/templates/functional_test.rb +0 -8
  265. data/rails_generators/hobo_user_controller/templates/helper.rb +0 -2
  266. data/rails_generators/hobo_user_model/USAGE +0 -16
  267. data/rails_generators/hobo_user_model/hobo_user_model_generator.rb +0 -46
  268. data/rails_generators/hobo_user_model/templates/fixtures.yml +0 -19
  269. data/rails_generators/hobo_user_model/templates/mailer.rb +0 -29
  270. data/rails_generators/hobo_user_model/templates/unit_test.rb +0 -8
  271. data/script/destroy +0 -14
  272. data/script/generate +0 -14
  273. data/taglibs/rapid_translations.dryml +0 -36
  274. data/tasks/environments.rake +0 -19
  275. data/tasks/hobo_tasks.rake +0 -58
  276. data/test/generators/test_generator_helper.rb +0 -29
  277. data/test/generators/test_helper.rb +0 -1
  278. data/test/generators/test_hobo_model_controller_generator.rb +0 -56
@@ -1,20 +0,0 @@
1
- class ActiveRecord::Reflection::AssociationReflection
2
-
3
- alias_method :association_name, :name
4
-
5
- def klass_with_create_polymorphic_class
6
- if options[:polymorphic]
7
- begin
8
- klass_without_create_polymorphic_class
9
- rescue NameError => e
10
- name = "#{active_record.name}::#{class_name}"
11
- Object.class_eval "class #{name}; end"
12
- active_record.const_get class_name
13
- end
14
- else
15
- klass_without_create_polymorphic_class
16
- end
17
- end
18
- alias_method_chain :klass, :create_polymorphic_class
19
-
20
- end
@@ -1,9 +0,0 @@
1
- module Hobo
2
- module ViewHintsValidationsInterceptor
3
- def human_attribute_name(attribute_key_name, opt={})
4
- view_hints_field_names = self.view_hints.field_names
5
- attribute_key_name!="" && view_hints_field_names.include?(attribute_key_name.to_sym) ?
6
- view_hints_field_names[attribute_key_name.to_sym] : super
7
- end
8
- end
9
- end
@@ -1,183 +0,0 @@
1
- module Hobo
2
-
3
- module AccessibleAssociations
4
-
5
- extend self
6
-
7
- def prepare_has_many_assignment(association, association_name, array_or_hash)
8
- owner = association.proxy_owner
9
-
10
- array = params_hash_to_array(array_or_hash)
11
- array.map! do |record_hash_or_string|
12
- if association.conditions.nil?
13
- finder = association.member_class
14
- else
15
- finder = association.member_class.scoped :conditions => association.conditions
16
- end
17
- find_or_create_and_update(owner, association_name, finder, record_hash_or_string) do |id|
18
- # The block is required to either locate find an existing record in the collection, or build a new one
19
- if id
20
- # TODO: We don't really want to find these one by one
21
- association.find(id)
22
- else
23
- association.build
24
- end
25
- end
26
- end
27
- array.compact
28
- end
29
-
30
-
31
- def find_or_create_and_update(owner, association_name, finder, record_hash_or_string)
32
- if record_hash_or_string.is_a?(String)
33
- return nil if record_hash_or_string.blank?
34
-
35
- # An ID or a name - the passed block will find the record
36
- record = find_by_name_or_id(finder, record_hash_or_string)
37
-
38
- elsif record_hash_or_string.is_a?(Hash)
39
- # A hash of attributes
40
- hash = record_hash_or_string
41
-
42
- # Remove completely blank hashes
43
- return nil if hash.values.all?(&:blank?)
44
-
45
- id = hash.delete(:id)
46
-
47
- record = yield id
48
- record.attributes = hash
49
- if owner.new_record? && record.new_record?
50
- # work around
51
- # https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3510-has_many-build-does-not-set-reverse-reflection
52
- # https://hobo.lighthouseapp.com/projects/8324/tickets/447-validation-problems-with-has_many-accessible-true
53
- reverse = owner.class.reverse_reflection(association_name)
54
- if reverse && reverse.macro==:belongs_to
55
- method = "#{reverse.name}=".to_sym
56
- record.send(method, owner) if record.respond_to? method
57
- end
58
- else
59
- owner.include_in_save(association_name, record) unless owner.class.reflections[association_name].options[:through]
60
- end
61
- else
62
- # It's already a record
63
- record = record_hash_or_string
64
- end
65
- record
66
- end
67
-
68
-
69
- def params_hash_to_array(array_or_hash)
70
- if array_or_hash.is_a?(Hash)
71
- array = array_or_hash.get(*array_or_hash.keys.sort_by(&:to_i))
72
- elsif array_or_hash.is_a?(String)
73
- # Due to the way that rails works, there's no good way to tell
74
- # the difference between an empty array and a params hash that
75
- # just isn't making any updates to the array. So we're
76
- # hacking this in: if you pash an empty string where an array
77
- # is expected, we assume you wanted an empty array.
78
- []
79
- else
80
- array_or_hash
81
- end
82
- end
83
-
84
-
85
- def find_by_name_or_id(finder, id_or_name)
86
- if id_or_name =~ /^@(.*)/
87
- id = $1
88
- finder.find(id)
89
- else
90
- finder.named(id_or_name)
91
- end
92
- end
93
-
94
- def finder_for_belongs_to(record, name)
95
- refl = record.class.reflections[name]
96
- conditions = ActiveRecord::Associations::BelongsToAssociation.new(record, refl).conditions
97
- finder = refl.klass.scoped(:conditions => conditions)
98
- end
99
-
100
- end
101
-
102
- classy_module(AccessibleAssociations) do
103
-
104
- include Hobo::IncludeInSave
105
-
106
- # --- has_many mass assignment support --- #
107
-
108
- def self.has_many_with_accessible(name, options={}, &block)
109
- has_many_without_accessible(name, options, &block)
110
-
111
- if options[:accessible]
112
- class_eval %{
113
- def #{name}_with_accessible=(array_or_hash)
114
- __items = Hobo::AccessibleAssociations.prepare_has_many_assignment(#{name}, :#{name}, array_or_hash)
115
- self.#{name}_without_accessible = __items
116
- # ensure the loaded array contains any changed records
117
- self.#{name}.proxy_target[0..-1] = __items
118
- end
119
- }, __FILE__, __LINE__ - 7
120
- alias_method_chain :"#{name}=", :accessible
121
- end
122
- end
123
- metaclass.alias_method_chain :has_many, :accessible
124
-
125
-
126
-
127
- # --- belongs_to assignment support --- #
128
-
129
- def self.belongs_to_with_accessible(name, options={}, &block)
130
- belongs_to_without_accessible(name, options, &block)
131
-
132
- if options[:accessible]
133
- class_eval %{
134
- def #{name}_with_accessible=(record_hash_or_string)
135
- finder = Hobo::AccessibleAssociations.finder_for_belongs_to(self, :#{name})
136
- record = Hobo::AccessibleAssociations.find_or_create_and_update(self, :#{name}, finder, record_hash_or_string) do |id|
137
- if id
138
- raise ArgumentError, "attempted to update the wrong record in belongs_to association #{self}##{name}" unless
139
- #{name} && id.to_s == self.#{name}.id.to_s
140
- #{name}
141
- else
142
- finder.new
143
- end
144
- end
145
- self.#{name}_without_accessible = record
146
- end
147
- }, __FILE__, __LINE__ - 15
148
- alias_method_chain :"#{name}=", :accessible
149
- else
150
- # Not accessible - but finding by name and ID is still supported
151
- class_eval %{
152
- def #{name}_with_finder=(record_or_string)
153
- record = if record_or_string.is_a?(String)
154
- finder = Hobo::AccessibleAssociations.finder_for_belongs_to(self, :#{name})
155
- Hobo::AccessibleAssociations.find_by_name_or_id(finder, record_or_string)
156
- else # it is a record
157
- record_or_string
158
- end
159
- self.#{name}_without_finder = record
160
- end
161
- }, __FILE__, __LINE__ - 12
162
- alias_method_chain :"#{name}=", :finder
163
- end
164
- end
165
- metaclass.alias_method_chain :belongs_to, :accessible
166
-
167
-
168
- # Add :accessible to the valid keys so AR doesn't complain
169
-
170
- def self.valid_keys_for_has_many_association_with_accessible
171
- valid_keys_for_has_many_association_without_accessible + [:accessible]
172
- end
173
- metaclass.alias_method_chain :valid_keys_for_has_many_association, :accessible
174
-
175
- def self.valid_keys_for_belongs_to_association_with_accessible
176
- valid_keys_for_belongs_to_association_without_accessible + [:accessible]
177
- end
178
- metaclass.alias_method_chain :valid_keys_for_belongs_to_association, :accessible
179
-
180
-
181
- end
182
-
183
- end
@@ -1,131 +0,0 @@
1
- module Hobo
2
-
3
- module AuthenticationSupport
4
-
5
- # Filter method to enforce a login requirement.
6
- def logged_in?
7
- not current_user.guest?
8
- end
9
-
10
-
11
- # Check if the user is authorized.
12
- #
13
- # Override this method in your controllers if you want to restrict access
14
- # to only a few actions or if you want to check if the user
15
- # has the correct rights.
16
- #
17
- # Example:
18
- #
19
- # # only allow nonbobs
20
- # def authorize?
21
- # current_user.login != "bob"
22
- # end
23
- def authorized?
24
- true
25
- end
26
-
27
- #
28
- # To require logins for all actions, use this in your controllers:
29
- #
30
- # before_filter :login_required
31
- #
32
- # To require logins for specific actions, use this in your controllers:
33
- #
34
- # before_filter :login_required, :only => [ :edit, :update ]
35
- #
36
- # To skip this in a subclassed controller:
37
- #
38
- # skip_before_filter :login_required
39
- #
40
- def login_required(user_model=nil)
41
- auth_model = user_model || User.default_user_model
42
- if current_user.guest?
43
- username, passwd = get_auth_data
44
- self.current_user = auth_model.authenticate(username, passwd) || nil if username && passwd && auth_model
45
- end
46
- if logged_in? && authorized? && (user_model.nil? || current_user.is_a?(user_model))
47
- true
48
- else
49
- access_denied(auth_model)
50
- end
51
- end
52
-
53
- # Redirect as appropriate when an access request fails.
54
- #
55
- # The default action is to redirect to the login screen.
56
- #
57
- # Override this method in your controllers if you want to have special
58
- # behavior in case the user is not authorized
59
- # to access the requested action. For example, a popup window might
60
- # simply close itself.
61
- def access_denied(user_model)
62
- respond_to do |accepts|
63
- accepts.html do
64
- store_location
65
- redirect_to(login_url(user_model))
66
- end
67
- accepts.xml do
68
- headers["Status"] = "Unauthorized"
69
- headers["WWW-Authenticate"] = %(Basic realm="Web Password")
70
- render :text => ht("hobo.messages.unauthenticated", :default=>["Couldn't authenticate you"]), :status => '401 Unauthorized'
71
- end
72
- end
73
- false
74
- end
75
-
76
- # Store the URI of the current request in the session.
77
- #
78
- # We can return to this location by calling #redirect_back_or_default.
79
- def store_location
80
- session[:return_to] = request.request_uri
81
- end
82
-
83
- # Redirect to the URI stored by the most recent store_location call or
84
- # to the passed default.
85
- def redirect_back_or_default(default)
86
- session[:return_to] ? redirect_to(session[:return_to]) : redirect_to(default)
87
- session[:return_to] = nil
88
- end
89
-
90
- # When called with before_filter :login_from_cookie will check for an :auth_token
91
- # cookie and log the user back in if apropriate
92
- def login_from_cookie
93
- if (user = authenticated_user_from_cookie)
94
- user.remember_me
95
- self.current_user = user
96
- create_auth_cookie
97
- end
98
- end
99
-
100
-
101
- def authenticated_user_from_cookie
102
- !logged_in? and
103
- cookie = cookies[:auth_token] and
104
- (token, model_name = cookie.split) and
105
- user_model = model_name._?.safe_constantize and
106
- user = user_model.find_by_remember_token(token) and
107
- user.remember_token? and
108
- user
109
- end
110
-
111
- def create_auth_cookie
112
- cookies[:auth_token] = { :value => "#{current_user.remember_token} #{current_user.class.name}",
113
- :expires => current_user.remember_token_expires_at }
114
- end
115
-
116
- private
117
- @@http_auth_headers = %w(X-HTTP_AUTHORIZATION HTTP_AUTHORIZATION Authorization)
118
- # gets BASIC auth info
119
- def get_auth_data
120
- auth_key = @@http_auth_headers.detect { |h| request.env.has_key?(h) }
121
- auth_data = request.env[auth_key].to_s.split unless auth_key.blank?
122
- username, pw = if auth_data && auth_data[0] == 'Basic'
123
- Base64.decode64(auth_data[1]).split(':')[0..1]
124
- else
125
- [nil, nil]
126
- end
127
- end
128
-
129
- end
130
-
131
- end
@@ -1,26 +0,0 @@
1
- require 'find'
2
- require "rails_generator"
3
-
4
- class Hobo::Generator < Rails::Generator::Base
5
-
6
- def with_source_in(path)
7
- root = source_path(path)
8
- Find.find(root) do |f|
9
- Find.prune if File.basename(f) == ".svn"
10
- full_path = f[(source_root.length)..-1]
11
- rel_path = f[(root.length)..-1]
12
- yield full_path, rel_path
13
- end
14
- end
15
-
16
- def create_all(m, src, dest)
17
- with_source_in(src) do |full, rel|
18
- if File.directory?(source_path(full))
19
- m.directory File.join(dest, rel)
20
- else
21
- m.file full, File.join(dest, rel)
22
- end
23
- end
24
- end
25
-
26
- end
data/lib/hobo/guest.rb DELETED
@@ -1,25 +0,0 @@
1
- module Hobo
2
-
3
- class Guest
4
-
5
- alias_method :has_hobo_method?, :respond_to?
6
-
7
- def to_s
8
- "guest"
9
- end
10
-
11
- def guest?
12
- true
13
- end
14
-
15
- def signed_up?
16
- false
17
- end
18
-
19
- def login
20
- "guest"
21
- end
22
-
23
- end
24
-
25
- end
@@ -1,55 +0,0 @@
1
- module Hobo
2
-
3
- IncludeInSave = classy_module do
4
-
5
- attr_accessor :included_in_save
6
-
7
- validate :validate_included_in_save
8
- before_save :save_included
9
- after_save :clear_included_in_save
10
-
11
- def include_in_save(association, *records)
12
- self.included_in_save ||= Hash.new {|h, k| h[k] = []}
13
- included_in_save[association.to_sym].concat records
14
- end
15
-
16
- def validate_included_in_save
17
- if included_in_save
18
- included_in_save._?.each_pair do |association, records|
19
- next if self.class.reflections[association].options[:validate]==false
20
- added = false
21
- records.each do |record|
22
- # we want to call valid? on each one, but only add the error to self once
23
-
24
- record.with_acting_user(acting_user) do
25
- unless record.valid?
26
- unless added
27
- errors.add association, "..."
28
- added = true
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
36
-
37
-
38
- def save_included
39
- if included_in_save
40
- included_in_save.each_pair do |association, records|
41
- records.each do |record|
42
- # save_without_validation means without transactions too
43
- record.with_acting_user(acting_user) { record.save_without_validation }
44
- end
45
- end
46
- end
47
- end
48
-
49
- def clear_included_in_save
50
- included_in_save._?.clear
51
- end
52
-
53
- end
54
-
55
- end