hobo 0.7.5 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. data/{hobo_files/plugin/CHANGES.txt → CHANGES.txt} +391 -0
  2. data/Manifest +146 -0
  3. data/{hobo_files/plugin/README → README} +0 -0
  4. data/bin/hobo +13 -26
  5. data/dryml_generators/rapid/cards.dryml.erb +55 -0
  6. data/dryml_generators/rapid/forms.dryml.erb +43 -0
  7. data/dryml_generators/rapid/pages.dryml.erb +284 -0
  8. data/hobo.gemspec +168 -0
  9. data/init.rb +9 -0
  10. data/lib/action_view_extensions/helpers/tag_helper.rb +7 -0
  11. data/lib/active_record/association_collection.rb +54 -0
  12. data/{hobo_files/plugin/lib → lib}/active_record/association_proxy.rb +12 -4
  13. data/{hobo_files/plugin/lib → lib}/active_record/association_reflection.rb +7 -1
  14. data/{hobo_files/plugin/lib → lib}/extensions/test_case.rb +17 -17
  15. data/{hobo_files/plugin/lib → lib}/hobo.rb +193 -100
  16. data/{hobo_files/plugin/lib → lib}/hobo/authentication_support.rb +8 -8
  17. data/{hobo_files/plugin/lib → lib}/hobo/bundle.rb +90 -89
  18. data/{hobo_files/plugin/lib → lib}/hobo/composite_model.rb +21 -21
  19. data/{hobo_files/plugin/lib → lib}/hobo/controller.rb +38 -25
  20. data/{hobo_files/plugin/lib → lib}/hobo/dev_controller.rb +10 -6
  21. data/lib/hobo/dryml.rb +167 -0
  22. data/{hobo_files/plugin/lib → lib}/hobo/dryml/dryml_builder.rb +28 -25
  23. data/lib/hobo/dryml/dryml_generator.rb +210 -0
  24. data/{hobo_files/plugin/lib → lib}/hobo/dryml/dryml_support_controller.rb +1 -1
  25. data/lib/hobo/dryml/parser.rb +3 -0
  26. data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/attribute.rb +6 -6
  27. data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/base_parser.rb +16 -16
  28. data/lib/hobo/dryml/parser/document.rb +57 -0
  29. data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/element.rb +7 -7
  30. data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/elements.rb +9 -9
  31. data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/source.rb +3 -3
  32. data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/text.rb +3 -3
  33. data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/tree_parser.rb +3 -3
  34. data/{hobo_files/plugin/lib → lib}/hobo/dryml/part_context.rb +26 -26
  35. data/{hobo_files/plugin/lib → lib}/hobo/dryml/scoped_variables.rb +15 -15
  36. data/{hobo_files/plugin/lib → lib}/hobo/dryml/tag_parameters.rb +10 -10
  37. data/{hobo_files/plugin/lib → lib}/hobo/dryml/taglib.rb +43 -37
  38. data/{hobo_files/plugin/lib → lib}/hobo/dryml/template.rb +290 -208
  39. data/{hobo_files/plugin/lib → lib}/hobo/dryml/template_environment.rb +173 -115
  40. data/{hobo_files/plugin/lib → lib}/hobo/dryml/template_handler.rb +19 -24
  41. data/lib/hobo/find_for.rb +95 -0
  42. data/{hobo_files/plugin/lib → lib}/hobo/generator.rb +2 -1
  43. data/{hobo_files/plugin/lib → lib}/hobo/guest.rb +12 -4
  44. data/{hobo_files/plugin/lib → lib}/hobo/hobo_helper.rb +146 -117
  45. data/lib/hobo/include_in_save.rb +43 -0
  46. data/lib/hobo/lifecycles.rb +94 -0
  47. data/lib/hobo/lifecycles/actions.rb +73 -0
  48. data/lib/hobo/lifecycles/creator.rb +76 -0
  49. data/lib/hobo/lifecycles/lifecycle.rb +205 -0
  50. data/lib/hobo/lifecycles/state.rb +23 -0
  51. data/lib/hobo/lifecycles/transition.rb +66 -0
  52. data/{hobo_files/plugin/lib → lib}/hobo/model.rb +306 -217
  53. data/{hobo_files/plugin/lib → lib}/hobo/model_controller.rb +342 -213
  54. data/{hobo_files/plugin/lib → lib}/hobo/model_router.rb +151 -120
  55. data/{hobo_files/plugin/lib → lib}/hobo/model_support.rb +9 -9
  56. data/{hobo_files/plugin/lib → lib}/hobo/rapid_helper.rb +30 -23
  57. data/{hobo_files/plugin/lib → lib}/hobo/scopes.rb +22 -68
  58. data/{hobo_files/plugin/lib → lib}/hobo/scopes/apply_scopes.rb +5 -5
  59. data/lib/hobo/scopes/association_proxy_extensions.rb +47 -0
  60. data/{hobo_files/plugin/lib → lib}/hobo/scopes/automatic_scopes.rb +104 -79
  61. data/lib/hobo/scopes/named_scope_extensions.rb +27 -0
  62. data/{hobo_files/plugin/lib → lib}/hobo/static_tags +1 -11
  63. data/{hobo_files/plugin/lib → lib}/hobo/undefined.rb +1 -1
  64. data/{hobo_files/plugin/lib → lib}/hobo/undefined_access_error.rb +0 -0
  65. data/{hobo_files/plugin/lib → lib}/hobo/user.rb +27 -25
  66. data/{hobo_files/plugin/lib → lib}/hobo/user_controller.rb +80 -34
  67. data/{hobo_files/plugin/generators → rails_generators}/hobo/hobo_generator.rb +7 -7
  68. data/rails_generators/hobo/templates/application.css +0 -0
  69. data/{hobo_files/plugin/generators → rails_generators}/hobo/templates/application.dryml +0 -2
  70. data/{hobo_files/plugin/generators → rails_generators}/hobo/templates/dryml-support.js +0 -0
  71. data/{hobo_files/plugin/generators → rails_generators}/hobo/templates/guest.rb +0 -0
  72. data/rails_generators/hobo/templates/initializer.rb +9 -0
  73. data/{hobo_files/plugin/generators → rails_generators}/hobo_front_controller/USAGE +0 -0
  74. data/{hobo_files/plugin/generators → rails_generators}/hobo_front_controller/hobo_front_controller_generator.rb +1 -3
  75. data/{hobo_files/plugin/generators → rails_generators}/hobo_front_controller/templates/controller.rb +1 -1
  76. data/{hobo_files/plugin/generators → rails_generators}/hobo_front_controller/templates/functional_test.rb +0 -0
  77. data/{hobo_files/plugin/generators → rails_generators}/hobo_front_controller/templates/helper.rb +0 -0
  78. data/rails_generators/hobo_front_controller/templates/index.dryml +25 -0
  79. data/{hobo_files/plugin/generators → rails_generators}/hobo_model/USAGE +0 -0
  80. data/{hobo_files/plugin/generators → rails_generators}/hobo_model/hobo_model_generator.rb +0 -0
  81. data/{hobo_files/plugin/generators → rails_generators}/hobo_model/templates/fixtures.yml +0 -0
  82. data/{hobo_files/plugin/generators → rails_generators}/hobo_model/templates/model.rb +0 -0
  83. data/{hobo_files/plugin/generators → rails_generators}/hobo_model/templates/unit_test.rb +0 -0
  84. data/{hobo_files/plugin/generators → rails_generators}/hobo_model_controller/USAGE +0 -0
  85. data/{hobo_files/plugin/generators → rails_generators}/hobo_model_controller/hobo_model_controller_generator.rb +0 -7
  86. data/{hobo_files/plugin/generators → rails_generators}/hobo_model_controller/templates/controller.rb +0 -0
  87. data/{hobo_files/plugin/generators → rails_generators}/hobo_model_controller/templates/functional_test.rb +0 -0
  88. data/{hobo_files/plugin/generators → rails_generators}/hobo_model_controller/templates/helper.rb +0 -0
  89. data/{hobo_files/plugin/generators → rails_generators}/hobo_model_resource/hobo_model_resource_generator.rb +0 -0
  90. data/{hobo_files/plugin/generators → rails_generators}/hobo_model_resource/templates/controller.rb +0 -0
  91. data/{hobo_files/plugin/generators → rails_generators}/hobo_model_resource/templates/functional_test.rb +0 -0
  92. data/{hobo_files/plugin/generators → rails_generators}/hobo_model_resource/templates/helper.rb +0 -0
  93. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/hobo_rapid_generator.rb +21 -11
  94. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/IE7.js +1 -1
  95. data/rails_generators/hobo_rapid/templates/blank.gif +0 -0
  96. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/hobo-rapid.css +0 -0
  97. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/hobo-rapid.js +175 -104
  98. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/lowpro.js +0 -0
  99. data/rails_generators/hobo_rapid/templates/nicEditorIcons.gif +0 -0
  100. data/rails_generators/hobo_rapid/templates/nicedit.js +91 -0
  101. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/reset.css +0 -0
  102. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/images/fieldbg.gif +0 -0
  103. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/images/pencil.png +0 -0
  104. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/images/small_close.png +0 -0
  105. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/images/spinner.gif +0 -0
  106. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/stylesheets/clean.css +80 -71
  107. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/stylesheets/rapid-ui.css +6 -1
  108. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/views/clean.dryml +4 -4
  109. data/rails_generators/hobo_subsite/hobo_subsite_generator.rb +73 -0
  110. data/rails_generators/hobo_subsite/templates/application.dryml +1 -0
  111. data/rails_generators/hobo_subsite/templates/controller.rb +5 -0
  112. data/rails_generators/hobo_subsite/templates/site_taglib.dryml +13 -0
  113. data/{hobo_files/plugin/generators → rails_generators}/hobo_user_controller/USAGE +0 -0
  114. data/{hobo_files/plugin/generators → rails_generators}/hobo_user_controller/hobo_user_controller_generator.rb +0 -0
  115. data/{hobo_files/plugin/generators → rails_generators}/hobo_user_controller/templates/controller.rb +0 -0
  116. data/{hobo_files/plugin/generators → rails_generators}/hobo_user_controller/templates/functional_test.rb +0 -0
  117. data/{hobo_files/plugin/generators → rails_generators}/hobo_user_controller/templates/helper.rb +0 -0
  118. data/{hobo_files/plugin/generators → rails_generators}/hobo_user_model/USAGE +0 -0
  119. data/rails_generators/hobo_user_model/hobo_user_model_generator.rb +30 -0
  120. data/{hobo_files/plugin/generators → rails_generators}/hobo_user_model/templates/fixtures.yml +0 -0
  121. data/rails_generators/hobo_user_model/templates/forgot_password.erb +10 -0
  122. data/rails_generators/hobo_user_model/templates/mailer.rb +14 -0
  123. data/rails_generators/hobo_user_model/templates/model.rb +55 -0
  124. data/{hobo_files/plugin/generators → rails_generators}/hobo_user_model/templates/unit_test.rb +0 -0
  125. data/script/destroy +14 -0
  126. data/script/generate +14 -0
  127. data/{hobo_files/plugin/taglibs → taglibs}/core.dryml +6 -7
  128. data/{hobo_files/plugin/taglibs → taglibs}/rapid.dryml +36 -67
  129. data/{hobo_files/plugin/taglibs → taglibs}/rapid_document_tags.dryml +7 -24
  130. data/{hobo_files/plugin/taglibs → taglibs}/rapid_editing.dryml +51 -50
  131. data/{hobo_files/plugin/taglibs → taglibs}/rapid_forms.dryml +62 -56
  132. data/taglibs/rapid_generics.dryml +33 -0
  133. data/taglibs/rapid_lifecycles.dryml +43 -0
  134. data/{hobo_files/plugin/taglibs → taglibs}/rapid_navigation.dryml +23 -23
  135. data/taglibs/rapid_pages.dryml +183 -0
  136. data/{hobo_files/plugin/taglibs → taglibs}/rapid_plus.dryml +30 -5
  137. data/{hobo_files/plugin/taglibs → taglibs}/rapid_support.dryml +3 -4
  138. data/taglibs/rapid_user_pages.dryml +179 -0
  139. data/{hobo_files/plugin/tasks → tasks}/environments.rake +0 -0
  140. data/{hobo_files/plugin/tasks → tasks}/fix_dryml.rake +0 -0
  141. data/{hobo_files/plugin/tasks → tasks}/generate_tag_reference.rb +21 -22
  142. data/tasks/hobo_tasks.rake +32 -0
  143. data/test/test_generator_helper.rb +29 -0
  144. data/test/test_helper.rb +1 -0
  145. data/test/test_hobo_model_controller_generator.rb +56 -0
  146. data/{hobo_files/plugin/uninstall.rb → uninstall.rb} +0 -0
  147. metadata +240 -225
  148. data/README.txt +0 -18
  149. data/hobo_files/plugin/LICENSE.txt +0 -22
  150. data/hobo_files/plugin/Rakefile +0 -96
  151. data/hobo_files/plugin/generators/hobo_front_controller/templates/index.dryml +0 -24
  152. data/hobo_files/plugin/generators/hobo_front_controller/templates/search.dryml +0 -19
  153. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/banner.gif +0 -0
  154. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-bodytop.gif +0 -0
  155. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-corner-01.gif +0 -0
  156. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-corner-02.gif +0 -0
  157. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-corner-03.gif +0 -0
  158. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-corner-04.gif +0 -0
  159. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-shadow-bottom.gif +0 -0
  160. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-shadow-left.gif +0 -0
  161. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-shadow-right.gif +0 -0
  162. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-shadow-top.gif +0 -0
  163. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header-blue.gif +0 -0
  164. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header-dblue.gif +0 -0
  165. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header-green.gif +0 -0
  166. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header-purple.gif +0 -0
  167. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header-red.gif +0 -0
  168. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/logo.gif +0 -0
  169. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/plus.png +0 -0
  170. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/spinner.gif +0 -0
  171. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/txt-list-img-dblue.gif +0 -0
  172. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/txt-list-img-green.gif +0 -0
  173. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/txt-list-img-purple.gif +0 -0
  174. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/txt-list-img-red.gif +0 -0
  175. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-corner-01.gif +0 -0
  176. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-corner-02.gif +0 -0
  177. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-corner-03.gif +0 -0
  178. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-corner-04.gif +0 -0
  179. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-shadow-bottom.gif +0 -0
  180. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-shadow-left.gif +0 -0
  181. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-shadow-right.gif +0 -0
  182. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-shadow-top.gif +0 -0
  183. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/stylesheets/application.css +0 -400
  184. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/views/application.dryml +0 -96
  185. data/hobo_files/plugin/generators/hobo_user_model/hobo_user_model_generator.rb +0 -25
  186. data/hobo_files/plugin/generators/hobo_user_model/templates/model.rb +0 -56
  187. data/hobo_files/plugin/init.rb +0 -101
  188. data/hobo_files/plugin/lib/action_view_extensions/base.rb +0 -15
  189. data/hobo_files/plugin/lib/active_record/has_many_association.rb +0 -55
  190. data/hobo_files/plugin/lib/active_record/has_many_through_association.rb +0 -20
  191. data/hobo_files/plugin/lib/hobo/dryml.rb +0 -165
  192. data/hobo_files/plugin/lib/hobo/dryml/parser/document.rb +0 -53
  193. data/hobo_files/plugin/lib/hobo/scopes/association_proxy_extensions.rb +0 -33
  194. data/hobo_files/plugin/lib/hobo/scopes/defined_scope_proxy_extender.rb +0 -90
  195. data/hobo_files/plugin/lib/hobo/scopes/scope_reflection.rb +0 -18
  196. data/hobo_files/plugin/lib/hobo/scopes/scoped_proxy.rb +0 -55
  197. data/hobo_files/plugin/taglib-docs/core.markdown +0 -165
  198. data/hobo_files/plugin/taglib-docs/rapid.markdown +0 -677
  199. data/hobo_files/plugin/taglib-docs/rapid_document_tags.markdown +0 -240
  200. data/hobo_files/plugin/taglib-docs/rapid_editing.markdown +0 -418
  201. data/hobo_files/plugin/taglib-docs/rapid_forms.markdown +0 -562
  202. data/hobo_files/plugin/taglib-docs/rapid_generics.markdown +0 -187
  203. data/hobo_files/plugin/taglib-docs/rapid_navigation.markdown +0 -214
  204. data/hobo_files/plugin/taglib-docs/rapid_pages.markdown +0 -530
  205. data/hobo_files/plugin/taglib-docs/rapid_plus.markdown +0 -65
  206. data/hobo_files/plugin/taglib-docs/rapid_support.markdown +0 -50
  207. data/hobo_files/plugin/taglib-docs/rapid_user_pages.markdown +0 -129
  208. data/hobo_files/plugin/taglibs/rapid_generics.dryml +0 -117
  209. data/hobo_files/plugin/taglibs/rapid_pages.dryml +0 -359
  210. data/hobo_files/plugin/taglibs/rapid_user_pages.dryml +0 -104
  211. data/hobo_files/plugin/tasks/dump_fixtures.rake +0 -70
  212. data/hobo_files/plugin/tasks/hobo_tasks.rake +0 -17
@@ -1,13 +1,13 @@
1
1
  module Hobo
2
-
2
+
3
3
  module AuthenticationSupport
4
-
4
+
5
5
  # Filter method to enforce a login requirement.
6
6
  def logged_in?
7
7
  not current_user.guest?
8
8
  end
9
-
10
-
9
+
10
+
11
11
  # Check if the user is authorized.
12
12
  #
13
13
  # Override this method in your controllers if you want to restrict access
@@ -39,7 +39,7 @@ module Hobo
39
39
  #
40
40
  def login_required(user_model=nil)
41
41
  auth_model = user_model || User.default_user_model
42
- if current_user.guest?
42
+ if current_user.guest?
43
43
  username, passwd = get_auth_data
44
44
  self.current_user = auth_model.authenticate(username, passwd) || nil if username && passwd && auth_model
45
45
  end
@@ -91,7 +91,7 @@ module Hobo
91
91
  # cookie and log the user back in if apropriate
92
92
  def login_from_cookie
93
93
  return unless (token = cookies[:auth_token]) && !logged_in?
94
-
94
+
95
95
  user_model = token[:user_model].constantize
96
96
  user = user_model.find_by_remember_token(token)
97
97
  if user && user.remember_token?
@@ -100,7 +100,7 @@ module Hobo
100
100
  create_auth_cookie
101
101
  end
102
102
  end
103
-
103
+
104
104
  def create_auth_cookie
105
105
  cookies[:auth_token] = { :value => current_user.remember_token ,
106
106
  :expires => current_user.remember_token_expires_at,
@@ -121,5 +121,5 @@ module Hobo
121
121
  end
122
122
 
123
123
  end
124
-
124
+
125
125
  end
@@ -1,65 +1,65 @@
1
1
  module ::Hobo
2
-
2
+
3
3
  class Bundle
4
-
4
+
5
5
  @bundles = HashWithIndifferentAccess.new
6
-
6
+
7
7
  class << self
8
-
8
+
9
9
  # Hobo::Bundle.bundles is a hash of all instantiated bundles by name
10
10
  attr_accessor :bundles
11
-
11
+
12
12
  # Used by subclasses, e.g MyBundle.plugin is the name of the
13
13
  # plugin the bundle came from
14
14
  attr_reader :plugin
15
-
15
+
16
16
  attr_reader :model_declarations, :controller_declarations
17
-
17
+
18
18
  attr_accessor :dirname
19
-
19
+
20
20
  def inherited(base)
21
21
  filename = caller[0].match(/^(.*):\d+/)[1]
22
22
  base.dirname = filename.match(%r(^.*/plugins/[^/]+))[0]
23
23
  end
24
24
 
25
-
25
+
26
26
  def load_models_and_controllers
27
27
  return if models_and_controllers_loaded?
28
-
28
+
29
29
  @plugin = File.basename(dirname)
30
-
30
+
31
31
  @model_declarations = []
32
32
  @controller_declarations = []
33
-
33
+
34
34
  class_eval do
35
35
  eval_ruby_files("#{dirname}/models", @models)
36
36
  eval_ruby_files("#{dirname}/controllers", @controllers)
37
37
  end
38
38
  end
39
-
39
+
40
40
  def [](bundle_name)
41
41
  bundles[bundle_name]
42
42
  end
43
-
43
+
44
44
 
45
45
  private
46
-
46
+
47
47
  def bundle_model(name, &block)
48
48
  @model_declarations << [name, block]
49
49
  end
50
50
 
51
-
51
+
52
52
  def bundle_model_controller(model_name, &block)
53
53
  @controller_declarations << [model_name, block]
54
54
  end
55
55
 
56
-
56
+
57
57
  def models_and_controllers_loaded?
58
58
  @model_declarations
59
59
  end
60
-
61
-
62
-
60
+
61
+
62
+
63
63
  def eval_ruby_files(dir, filenames)
64
64
  files = if filenames == [:none]
65
65
  []
@@ -68,65 +68,66 @@ module ::Hobo
68
68
  else
69
69
  filenames.map { |f| "#{dir}/#{f}.rb" }
70
70
  end
71
-
71
+
72
72
  files.each { |f| instance_eval(File.read(f), f, 1) }
73
73
  end
74
-
75
-
74
+
75
+
76
76
  # Declarations
77
-
77
+
78
78
  def models(*models)
79
79
  @models = models
80
80
  end
81
-
81
+
82
82
  def controllers(*controllers)
83
83
  @controllers = controllers.map {|c| case c.to_s
84
84
  when /controller$/, "all", "none" then c
85
- else "#{c.to_s.pluralize}_controller"
85
+ else "#{c.to_s.pluralize}_controller"
86
86
  end }
87
87
  end
88
-
88
+
89
89
  end
90
-
90
+
91
91
  def initialize(*args)
92
+ caller_options = args.extract_options!
93
+
92
94
  self.class.load_models_and_controllers
93
-
94
- options = defaults.with_indifferent_access
95
- options.recursive_update(args.extract_options!)
96
-
97
95
  self.name = args.first || self.class.name.match(/[^:]+$/)[0].underscore
98
96
  Bundle.bundles[name] = self
99
-
97
+
98
+ options = defaults(caller_options).with_indifferent_access
99
+ options.recursive_update(caller_options)
100
+
100
101
  @renames, @options = separate_renames(options)
101
-
102
+
102
103
  includes
103
104
 
104
105
  create_models
105
106
  create_controllers
106
-
107
+
107
108
  init
108
109
  end
109
-
110
+
110
111
  attr_accessor :renames, :options, :name
111
-
112
+
112
113
  # optionally overridden by the bundle subclass
113
114
  def includes; end
114
115
  def init; end
115
- def defaults; {}; end
116
+ def defaults(options); {}; end
117
+
116
118
 
117
-
118
119
  def plugin
119
120
  self.class.plugin
120
121
  end
121
-
122
-
122
+
123
+
123
124
  def create_models
124
125
  self.class.model_declarations.each do |name, block|
125
126
  klass = make_class(new_name_for(name), ActiveRecord::Base)
126
-
127
+
127
128
  klass.meta_def :belongs_to_with_optional_polymorphism do |*args|
128
129
  opts = args.extract_options!
129
-
130
+
130
131
  if opts[:polymorphic] == :optional
131
132
  if bundle.options["polymorphic_#{name}"]
132
133
  opts[:polymorphic] = true
@@ -138,16 +139,16 @@ module ::Hobo
138
139
  belongs_to_without_optional_polymorphism(name, opts)
139
140
  end
140
141
  klass.meta_eval { alias_method_chain :belongs_to, :optional_polymorphism }
141
-
142
+
142
143
  klass.class_eval { hobo_model }
143
-
144
+
144
145
  # FIXME this extension breaks passing a block to belongs_to
145
146
  klass.meta_def :belongs_to_with_alias do |*args|
146
147
  opts = args.extract_options!
147
148
  name = args.first.to_sym
148
-
149
+
149
150
  alias_name = opts.delete(:alias)
150
-
151
+
151
152
  belongs_to_without_alias(name, opts)
152
153
 
153
154
  if alias_name && name != alias_name
@@ -155,26 +156,26 @@ module ::Hobo
155
156
  # make the aliased name available in the classes metadata
156
157
  klass.reflections[alias_name] = klass.reflections[name]
157
158
  end
158
-
159
+
159
160
  end
160
161
  klass.meta_eval { alias_method_chain :belongs_to, :alias }
161
162
 
162
- klass.class_eval(&block)
163
+ klass.class_eval(&block)
163
164
  end
164
165
  end
165
-
166
-
166
+
167
+
167
168
  def create_controllers
168
169
  bundle = self
169
170
  self.class.controller_declarations.each do |model_name, block|
170
- klass = make_class("#{new_name_for(model_name).to_s.pluralize}Controller", ::ApplicationController) do
171
+ klass = make_class("#{new_name_for(model_name).to_s.pluralize}Controller", ::ApplicationController) do
171
172
  hobo_model_controller
172
173
  end
173
174
  klass.class_eval(&block)
174
175
  end
175
176
  end
176
-
177
-
177
+
178
+
178
179
  def make_class(name, base_class, &b)
179
180
  bundle = self
180
181
  klass = Class.new(base_class) do
@@ -183,7 +184,7 @@ module ::Hobo
183
184
  def self.feature(name, &block)
184
185
  _feature(name, block)
185
186
  end
186
-
187
+
187
188
  def method_missing(name, *args)
188
189
  if name.to_s =~ /^_.*_$/
189
190
  self.class.bundle.magic_option(name)
@@ -192,11 +193,11 @@ module ::Hobo
192
193
  end
193
194
  end
194
195
  end
195
-
196
- klass.meta_def(:bundle) do
196
+
197
+ klass.meta_def(:bundle) do
197
198
  bundle
198
199
  end
199
-
200
+
200
201
  klass.meta_def(:_feature) do |feature, block|
201
202
  has_feature = bundle.options[feature]
202
203
  if has_feature
@@ -206,10 +207,10 @@ module ::Hobo
206
207
  else
207
208
  define_method("features_#{feature}?") { false }
208
209
  meta_def("features_#{feature}?") { false }
209
- end
210
+ end
210
211
  end
211
212
  silence_warnings { Object.const_set(name, klass) }
212
-
213
+
213
214
  klass.meta_def :method_missing do |name, *args|
214
215
  if name.to_s =~ /^_.*_$/
215
216
  bundle.magic_option(name)
@@ -217,43 +218,43 @@ module ::Hobo
217
218
  super
218
219
  end
219
220
  end
220
-
221
+
221
222
  klass.class_eval(&b) if b
222
-
223
+
223
224
  klass
224
225
  end
225
-
226
-
226
+
227
+
227
228
  def new_name_for(name)
228
229
  name = name.to_s
229
230
  underscore = name =~ /^[a-z]/
230
231
  name = name.camelize if underscore
231
-
232
- plural = !renames.has_key?(name) && (p = name.singularize) && renames.has_key?(p)
233
- name = p if plural
234
-
232
+
233
+ plural = !renames.has_key?(name) && (sing = name.singularize) && renames.has_key?(sing)
234
+ name = sing if plural
235
+
235
236
  # Keep a track of names we've seen to avoid cycles
236
237
  seen = [ name ]
237
-
238
+
238
239
  name = name.gsub(/_.*?_/) { |s| new_name_for(s[1..-2]) }
239
240
  while (newname = renames[name])
240
241
  name = newname
241
242
  name = name.gsub(/_.*?_/) { |s| new_name_for(s[1..-2]) }
242
243
 
243
244
  break if name.in?(seen)
244
- seen << name
245
+ seen << name
245
246
  end
246
-
247
+
247
248
  name = name.underscore if underscore
248
249
  name = name.pluralize if plural
249
250
  name = name.to_sym if underscore || plural
250
251
  name
251
252
  end
252
-
253
-
253
+
254
+
254
255
  def separate_renames(options)
255
256
  simple_options, renames = HashWithIndifferentAccess.new, HashWithIndifferentAccess.new
256
- options.each do |k, v|
257
+ options.each do |k, v|
257
258
  if k.to_s =~ /^[A-Z]/
258
259
  renames[k] = v.to_s
259
260
  else
@@ -262,12 +263,12 @@ module ::Hobo
262
263
  end
263
264
  [renames, simple_options]
264
265
  end
265
-
266
-
266
+
267
+
267
268
  def customize(name, &block)
268
269
  new_name_for(name).to_s.constantize.class_eval(&block)
269
270
  end
270
-
271
+
271
272
 
272
273
  def method_missing(name, *args)
273
274
  if name.to_s =~ /^_.*_$/
@@ -276,8 +277,8 @@ module ::Hobo
276
277
  super
277
278
  end
278
279
  end
279
-
280
-
280
+
281
+
281
282
  # Returns the option value or renamed class name from a 'magic'
282
283
  # name like _foo_ or _MyFoo_
283
284
  def magic_option(name)
@@ -288,34 +289,34 @@ module ::Hobo
288
289
  options[option_name]
289
290
  else
290
291
  new_name_for(option_name)
291
- end
292
+ end
292
293
  end
293
-
294
-
294
+
295
+
295
296
  def optional_bundle(*args)
296
297
  local_options = args.extract_options!
297
298
  class_name, option_name = args
298
299
  option_name ||= class_name.to_s.underscore
299
300
  _include_bundle(class_name, option_name, local_options) if self.options[option_name]
300
301
  end
301
-
302
-
302
+
303
+
303
304
  def include_bundle(*args)
304
305
  local_options = args.extract_options!
305
306
  class_name, option_name = args
306
307
  option_name ||= class_name.to_s.underscore
307
308
  _include_bundle(class_name, option_name, local_options)
308
309
  end
309
-
310
-
310
+
311
+
311
312
  def _include_bundle(class_name, option_name, local_options)
312
313
  external_options = self.options[option_name]
313
314
  external_options = {} if external_options.nil? || external_options == true
314
315
  name = "#{self.name}_#{option_name}"
315
-
316
+
316
317
  sub_bundle_options = external_options.merge(local_options).merge(renames)
317
318
  sub_bundle = class_name.to_s.constantize.new(name, sub_bundle_options)
318
-
319
+
319
320
  conflicting_renames = (renames.keys & sub_bundle.renames.keys).select { |k| renames[k] != sub_bundle.renames[k] }
320
321
  unless conflicting_renames.empty?
321
322
  raise ArgumentError, "Conflicting renames in included bundle '#{name}' of '#{self.name}': #{conflicting_renames * ', '}"
@@ -325,5 +326,5 @@ module ::Hobo
325
326
  end
326
327
 
327
328
  end
328
-
329
+
329
330
  end
@@ -1,39 +1,39 @@
1
1
  module Hobo
2
-
2
+
3
3
  class CompositeModel
4
-
4
+
5
5
  include ModelSupport
6
-
6
+
7
7
  class << self
8
-
8
+
9
9
  def find(id)
10
10
  ids = id.split('_')
11
11
  new(*ids.map_with_index{|id, i| @models[i].constantize.find(id)})
12
12
  end
13
-
13
+
14
14
  def compose(*models)
15
15
  @models = models.map &it.to_s.camelize
16
16
  attr_reader *models
17
17
  CompositeModel.composites ||= {}
18
18
  CompositeModel.composites[@models.sort] = self.name
19
-
19
+
20
20
  Hobo.register_model(self)
21
21
  end
22
-
22
+
23
23
  attr_accessor :composites
24
-
24
+
25
25
  attr_reader :models
26
-
26
+
27
27
  def new_for(objects)
28
28
  classes = objects.map{|o| o.class.name}.sort
29
29
  composite_class = CompositeModel.composites[classes].constantize rescue
30
30
  (raise ArgumentError, "No composite model for #{classes.inspect}")
31
31
  composite_class.new(*objects)
32
32
  end
33
-
33
+
34
34
  end
35
-
36
-
35
+
36
+
37
37
  def initialize(*objects)
38
38
  objects.each do |obj|
39
39
  raise ArgumentError, "invalid objects for composition: #{objects.inspect}" unless
@@ -41,33 +41,33 @@ module Hobo
41
41
  instance_variable_set("@#{obj.class.name.underscore}", obj)
42
42
  end
43
43
  end
44
-
45
-
44
+
45
+
46
46
  def has_hobo_method?(name)
47
47
  respond_to?(name)
48
48
  end
49
-
50
-
49
+
50
+
51
51
  def compose_with(object, use=nil)
52
52
  self_classes = use ? use.models : self.class.models
53
53
  from_self = (self_classes - [object.class.name]).map {|classname| send(classname.underscore)}
54
54
  CompositeModel.new_for(from_self + [object])
55
55
  end
56
56
 
57
-
57
+
58
58
  def typed_id
59
59
  "#{self.class.name.underscore}_#{id}"
60
60
  end
61
61
 
62
-
62
+
63
63
  def id
64
64
  objects = self.class.models.map {|m| instance_variable_get("@#{m.underscore}")}
65
65
  objects.*.id.join("_")
66
66
  end
67
-
67
+
68
68
  alias_method :to_param, :id
69
-
69
+
70
70
  end
71
71
 
72
72
  end
73
-
73
+