hobo 1.3.0.RC4 → 1.3.0.pre10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. data/CHANGES.txt +234 -282
  2. data/Rakefile +3 -3
  3. data/VERSION +1 -1
  4. data/app/controllers/dev_controller.rb +2 -2
  5. data/bin/hobo +3 -3
  6. data/config/routes.rb +1 -1
  7. data/doctests/hobo/lifecycles.rdoctest +1 -0
  8. data/doctests/hobo/model.rdoctest +5 -0
  9. data/doctests/hobo/multi_model_forms.rdoctest +5 -4
  10. data/doctests/hobo/scopes.rdoctest +8 -11
  11. data/doctests/prepare_testapp.rb +1 -2
  12. data/hobo.gemspec +2 -2
  13. data/lib/generators/hobo/admin_subsite/admin_subsite_generator.rb +11 -5
  14. data/lib/generators/hobo/admin_subsite/templates/admin.css +2 -20
  15. data/lib/generators/hobo/admin_subsite/templates/admin_tag_injection.erb +1 -3
  16. data/lib/generators/hobo/admin_subsite/templates/controller.rb.erb +5 -5
  17. data/lib/generators/hobo/admin_subsite/templates/users_index.dryml +1 -3
  18. data/lib/generators/hobo/basic/basic_generator.rb +17 -0
  19. data/lib/generators/hobo/{assets → basic}/templates/application.css +0 -0
  20. data/lib/generators/hobo/{assets → basic}/templates/application.dryml.erb +1 -1
  21. data/lib/generators/hobo/{assets → basic}/templates/dryml-support.js +2 -2
  22. data/lib/generators/hobo/{assets → basic}/templates/en_injection.yml +0 -0
  23. data/lib/generators/hobo/{assets → basic}/templates/guest.rb +0 -0
  24. data/lib/generators/hobo/controller.rb +1 -6
  25. data/lib/generators/hobo/front_controller/front_controller_generator.rb +3 -2
  26. data/{app/views/dev → lib/generators/hobo/front_controller/templates}/summary.dryml +10 -7
  27. data/lib/generators/hobo/hints/hints_generator.rb +12 -0
  28. data/lib/generators/hobo/hints/templates/hints.rb.erb +5 -0
  29. data/lib/generators/hobo/hints/templates/model_injection.rb.erb +36 -0
  30. data/lib/generators/hobo/i18n/i18n_generator.rb +9 -1
  31. data/lib/generators/hobo/i18n/templates/app.en.yml +1 -1
  32. data/lib/generators/hobo/i18n/templates/app.es-DO.yml +24 -0
  33. data/lib/generators/hobo/i18n/templates/app.it.yml +1 -5
  34. data/lib/generators/hobo/i18n/templates/app.pt-PT.yml +0 -1
  35. data/lib/generators/hobo/i18n/templates/default_count_injection.rb +10 -0
  36. data/lib/generators/hobo/i18n/templates/hobo.en.yml +10 -26
  37. data/lib/generators/hobo/i18n/templates/{hobo.es.yml → hobo.es-DO.yml} +10 -27
  38. data/lib/generators/hobo/i18n/templates/hobo.it.yml +4 -20
  39. data/lib/generators/hobo/i18n/templates/hobo.pt-PT.yml +9 -25
  40. data/lib/generators/hobo/model.rb +13 -0
  41. data/lib/generators/hobo/model/USAGE +3 -2
  42. data/lib/generators/hobo/model/model_generator.rb +1 -2
  43. data/lib/generators/hobo/rapid/rapid_generator.rb +0 -2
  44. data/lib/generators/hobo/rapid/templates/hobo-rapid.js +93 -78
  45. data/lib/generators/hobo/rapid/templates/ie7-recalc.js +21 -21
  46. data/lib/generators/hobo/rapid/templates/lowpro.js +31 -31
  47. data/lib/generators/hobo/rapid/templates/reset.css +1 -1
  48. data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/clean.css +16 -17
  49. data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/rapid-ui.css +3 -3
  50. data/lib/generators/hobo/rapid/templates/themes/clean/views/clean.dryml +1 -1
  51. data/lib/generators/hobo/resource/resource_generator.rb +1 -1
  52. data/lib/generators/hobo/routes/router.rb +4 -4
  53. data/lib/generators/hobo/routes/routes_generator.rb +1 -12
  54. data/lib/generators/hobo/routes/templates/hobo_routes.rb.erb +1 -1
  55. data/lib/generators/hobo/setup_wizard/setup_wizard_generator.rb +43 -88
  56. data/lib/generators/hobo/subsite.rb +5 -18
  57. data/lib/generators/hobo/subsite/subsite_generator.rb +1 -1
  58. data/lib/generators/hobo/subsite/templates/controller.rb.erb +1 -1
  59. data/lib/generators/hobo/subsite_taglib/templates/taglib.dryml.erb +2 -2
  60. data/lib/generators/hobo/test_framework/test_framework_generator.rb +7 -7
  61. data/lib/generators/hobo/user_controller/templates/controller.rb.erb +3 -8
  62. data/lib/generators/hobo/user_mailer/templates/activation.erb +2 -2
  63. data/lib/generators/hobo/user_mailer/templates/forgot_password.erb +2 -2
  64. data/lib/generators/hobo/user_mailer/templates/invite.erb +2 -2
  65. data/lib/generators/hobo/user_mailer/templates/mailer.rb.erb +17 -10
  66. data/lib/generators/hobo/user_mailer/user_mailer_generator.rb +1 -1
  67. data/lib/generators/hobo/user_model/USAGE +9 -2
  68. data/lib/generators/hobo/user_model/user_model_generator.rb +1 -2
  69. data/lib/hobo.rb +7 -13
  70. data/lib/hobo/controller.rb +14 -21
  71. data/lib/hobo/controller/authentication_support.rb +23 -1
  72. data/lib/hobo/controller/model.rb +53 -48
  73. data/lib/hobo/controller/{user_base.rb → user.rb} +36 -47
  74. data/lib/hobo/engine.rb +11 -25
  75. data/lib/hobo/extensions/action_controller/hobo_methods.rb +1 -25
  76. data/lib/hobo/extensions/active_model/translation.rb +1 -1
  77. data/lib/hobo/extensions/active_record/{associations/collection.rb → association_collection.rb} +3 -12
  78. data/lib/hobo/extensions/active_record/{associations/proxy.rb → association_proxy.rb} +7 -6
  79. data/lib/hobo/extensions/active_record/association_reflection.rb +19 -0
  80. data/lib/hobo/extensions/active_record/hobo_methods.rb +1 -1
  81. data/lib/hobo/extensions/active_record/scopes.rb +31 -0
  82. data/lib/hobo/extensions/array.rb +1 -13
  83. data/lib/hobo/helper.rb +6 -27
  84. data/lib/hobo/helper/translations.rb +90 -39
  85. data/lib/hobo/model.rb +20 -72
  86. data/lib/hobo/model/lifecycles.rb +11 -12
  87. data/lib/hobo/model/lifecycles/lifecycle.rb +4 -12
  88. data/lib/hobo/model/lifecycles/transition.rb +0 -1
  89. data/lib/hobo/model/permissions.rb +3 -2
  90. data/lib/hobo/model/scopes/apply_scopes.rb +1 -1
  91. data/lib/hobo/model/scopes/automatic_scopes.rb +80 -78
  92. data/lib/hobo/model/{user_base.rb → user.rb} +7 -9
  93. data/lib/hobo/rapid/generators/rapid/cards.dryml.erb +2 -2
  94. data/lib/hobo/rapid/generators/rapid/forms.dryml.erb +4 -5
  95. data/lib/hobo/rapid/generators/rapid/pages.dryml.erb +27 -26
  96. data/lib/hobo/rapid/helper.rb +5 -10
  97. data/lib/hobo/rapid/taglibs/rapid.dryml +1 -1
  98. data/lib/hobo/rapid/taglibs/rapid_core.dryml +42 -72
  99. data/lib/hobo/rapid/taglibs/rapid_document_tags.dryml +2 -2
  100. data/lib/hobo/rapid/taglibs/rapid_editing.dryml +16 -36
  101. data/lib/hobo/rapid/taglibs/rapid_forms.dryml +49 -87
  102. data/lib/hobo/rapid/taglibs/rapid_generics.dryml +2 -2
  103. data/lib/hobo/rapid/taglibs/rapid_i18n.dryml +75 -50
  104. data/lib/hobo/rapid/taglibs/rapid_lifecycles.dryml +5 -7
  105. data/lib/hobo/rapid/taglibs/rapid_navigation.dryml +2 -2
  106. data/lib/hobo/rapid/taglibs/rapid_pages.dryml +7 -8
  107. data/lib/hobo/rapid/taglibs/rapid_plus.dryml +43 -66
  108. data/lib/hobo/rapid/taglibs/rapid_summary.dryml +45 -16
  109. data/lib/hobo/rapid/taglibs/rapid_translations.dryml +36 -0
  110. data/lib/hobo/rapid/taglibs/rapid_user_pages.dryml +8 -8
  111. data/lib/hobo/routes.rb +23 -22
  112. data/lib/hobo/view_hints.rb +101 -0
  113. data/test/irt/generators/admin_subsite.irt +1 -1
  114. data/test/irt/generators/{assets.irt → basic.irt} +2 -2
  115. data/test/irt/generators/front_controller.irt +4 -2
  116. data/test/irt/generators/partials/_subsite_taglib_variables.rb +1 -1
  117. data/test/irt/generators/subsite.irt +1 -1
  118. data/test/permissions/test_permissions.rb +103 -103
  119. metadata +108 -69
  120. data/lib/generators/hobo/admin_subsite/USAGE +0 -25
  121. data/lib/generators/hobo/admin_subsite/templates/application.dryml +0 -1
  122. data/lib/generators/hobo/assets/USAGE +0 -5
  123. data/lib/generators/hobo/assets/assets_generator.rb +0 -18
  124. data/lib/generators/hobo/assets/templates/dryml_taglibs_initializer.rb +0 -1
  125. data/lib/generators/hobo/controller/USAGE +0 -3
  126. data/lib/generators/hobo/i18n/USAGE +0 -3
  127. data/lib/generators/hobo/i18n/templates/app.de.yml +0 -30
  128. data/lib/generators/hobo/i18n/templates/app.es.yml +0 -31
  129. data/lib/generators/hobo/i18n/templates/app.fr.yml +0 -26
  130. data/lib/generators/hobo/i18n/templates/app.nb.yml +0 -25
  131. data/lib/generators/hobo/i18n/templates/app.ru.yml +0 -24
  132. data/lib/generators/hobo/i18n/templates/hobo.de.yml +0 -204
  133. data/lib/generators/hobo/i18n/templates/hobo.fr.yml +0 -195
  134. data/lib/generators/hobo/i18n/templates/hobo.nb.yml +0 -198
  135. data/lib/generators/hobo/i18n/templates/hobo.ru.yml +0 -200
  136. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-ACD3E6-DBE1E5-H.png +0 -0
  137. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-DBE1E5-FCFEF5-H.png +0 -0
  138. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/300-3B5F87-ACD3E6-H.png +0 -0
  139. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/spinner.gif +0 -0
  140. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/stylesheets/clean-sidemenu.css +0 -81
  141. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/views/clean-sidemenu.dryml +0 -30
  142. data/lib/generators/hobo/resource/USAGE +0 -39
  143. data/lib/generators/hobo/subsite/USAGE +0 -24
  144. data/lib/generators/hobo/subsite_taglib/USAGE +0 -4
  145. data/lib/generators/hobo/test_framework/USAGE +0 -2
  146. data/lib/generators/hobo/user_controller/USAGE +0 -3
  147. data/lib/generators/hobo/user_mailer/USAGE +0 -2
  148. data/lib/generators/hobo/user_resource/USAGE +0 -10
  149. data/lib/hobo/extensions/action_view/translation_helper.rb +0 -25
  150. data/lib/hobo/extensions/active_record/associations/reflection.rb +0 -23
  151. data/lib/hobo/extensions/active_record/associations/scope.rb +0 -35
  152. data/lib/hobo/extensions/active_record/relation_with_origin.rb +0 -32
  153. data/lib/hobo/extensions/i18n.rb +0 -17
  154. data/lib/hobo/helper/translations/normalizer.rb +0 -39
  155. data/lib/hobo/model/view_hints.rb +0 -123
@@ -1,6 +1,6 @@
1
1
  module Hobo
2
2
  module Controller
3
- module UserBase
3
+ module User
4
4
 
5
5
  class << self
6
6
  def included(base)
@@ -12,7 +12,7 @@ module Hobo
12
12
  alias_method_chain :def_auto_actions, :user_actions
13
13
  end
14
14
 
15
- skip_before_filter :login_required, :only => [:login, :signup, :do_signup, :forgot_password, :reset_password, :do_reset_password,
15
+ skip_before_filter :login_required, :only => [:login, :signup, :forgot_password, :reset_password, :do_reset_password,
16
16
  :accept_invitation, :do_accept_invitation]
17
17
 
18
18
  include_taglib "rapid_user_pages", :plugin => "hobo"
@@ -52,7 +52,7 @@ module Hobo
52
52
 
53
53
  private
54
54
 
55
- def hobo_login(options={}, &block)
55
+ def hobo_login(options={})
56
56
  if logged_in?
57
57
  respond_to do |wants|
58
58
  wants.html { redirect_to home_page }
@@ -62,7 +62,8 @@ module Hobo
62
62
  end
63
63
 
64
64
  login_attr = model.human_attribute_name(model.login_attribute)
65
- options.reverse_merge!(:failure_notice => ht(:"#{model.to_s.underscore}.messages.login.error", :login=>login_attr, :default=>["You did not provide a valid #{login_attr} and password."]))
65
+ options.reverse_merge!(:success_notice => ht(:"users.messages.login.success", :default=>["You have logged in."]),
66
+ :failure_notice => ht(:"users.messages.login.error", :login=>login_attr, :default=>["You did not provide a valid #{login_attr} and password."]))
66
67
 
67
68
  if request.post?
68
69
  user = model.authenticate(params[:login], params[:password])
@@ -70,7 +71,33 @@ module Hobo
70
71
  flash[:error] = options[:failure_notice]
71
72
  hobo_ajax_response if request.xhr? && !performed?
72
73
  else
73
- self.sign_user_in(user, options){ yield if block_given?}
74
+ old_user = current_user
75
+ self.current_user = user
76
+
77
+ yield if block_given?
78
+
79
+ if !user.account_active?
80
+ # account not activate - cancel this login
81
+ self.current_user = old_user
82
+ unless performed?
83
+ respond_to do |wants|
84
+ wants.html {render :action => :account_disabled}
85
+ wants.js {hobo_ajax_response}
86
+ end
87
+ end
88
+ else
89
+ if params[:remember_me].present?
90
+ current_user.remember_me
91
+ create_auth_cookie
92
+ end
93
+ flash[:notice] ||= options[:success_notice]
94
+ unless performed?
95
+ respond_to do |wants|
96
+ wants.html {redirect_back_or_default(options[:redirect_to] || home_page) }
97
+ wants.js {hobo_ajax_response}
98
+ end
99
+ end
100
+ end
74
101
  end
75
102
  end
76
103
  end
@@ -86,7 +113,7 @@ module Hobo
86
113
  def hobo_do_signup(&b)
87
114
  do_creator_action(:signup) do
88
115
  if valid?
89
- flash[:notice] = ht(:"#{model.to_s.underscore}.messages.signup.success", :default=>["Thanks for signing up!"])
116
+ flash[:notice] = ht(:"users.messages.signup.success", :default=>["Thanks for signing up!"])
90
117
  end
91
118
  response_block(&b) or if valid?
92
119
  self.current_user = this if this.account_active?
@@ -100,7 +127,7 @@ module Hobo
100
127
 
101
128
 
102
129
  def hobo_logout(options={})
103
- options = options.reverse_merge(:notice => ht(:"#{model.to_s.underscore}.messages.logout", :default=>["You have logged out."]),
130
+ options = options.reverse_merge(:notice => ht(:"users.messages.logout", :default=>["You have logged out."]),
104
131
  :redirect_to => base_url)
105
132
 
106
133
  logout_current_user
@@ -128,7 +155,7 @@ module Hobo
128
155
  do_transition_action :reset_password do
129
156
  response_block(&b) or if valid?
130
157
  self.current_user = this
131
- flash[:notice] = ht(:"#{model.to_s.underscore}.messages.reset_password", :default=>["Your password has been reset"])
158
+ flash[:notice] = ht(:"users.messages.reset_password", :default=>["Your password has been reset"])
132
159
  respond_to do |wants|
133
160
  wants.html { redirect_to(home_page) }
134
161
  wants.js { hobo_ajax_response }
@@ -140,7 +167,7 @@ module Hobo
140
167
 
141
168
  def hobo_update_with_account_flash(*args)
142
169
  hobo_update_without_account_flash(*args) do
143
- flash[:notice] = ht(:"#{model.to_s.underscore}.messages.update.success", :default=>["Changes to your account were saved"]) if valid? && @this == current_user
170
+ flash[:notice] = ht(:"users.messages.update.success", :default=>["Changes to your account were saved"]) if valid? && @this == current_user
144
171
  yield if block_given?
145
172
  end
146
173
  end
@@ -156,44 +183,6 @@ module Hobo
156
183
  end
157
184
  end
158
185
 
159
- protected
160
- # If you are authenticating user on your own call this method -
161
- # hobo will remember signed-in user this way. Arguments:
162
- # user - user that you want to sign in
163
- # options - hash with messages (:success_notice, :redirect_to)
164
- # block - (optional) will be called after assigning current_user
165
- def sign_user_in(user, options={}, &block)
166
- options.reverse_merge!(:success_notice => ht(:"#{model.to_s.underscore}.messages.login.success", :default=>["You have logged in."]))
167
-
168
- old_user = current_user
169
- self.current_user = user
170
-
171
- yield if block_given?
172
-
173
- if !user.account_active?
174
- # account not activate - cancel this login
175
- self.current_user = old_user
176
- unless performed?
177
- respond_to do |wants|
178
- wants.html {render :action => :account_disabled}
179
- wants.js {hobo_ajax_response}
180
- end
181
- end
182
- else
183
- if params[:remember_me].present?
184
- current_user.remember_me
185
- create_auth_cookie
186
- end
187
- flash[:notice] ||= options[:success_notice]
188
- unless performed?
189
- respond_to do |wants|
190
- wants.html {redirect_back_or_default(options[:redirect_to] || home_page) }
191
- wants.js {hobo_ajax_response}
192
- end
193
- end
194
- end
195
- end
196
-
197
186
  end
198
187
  end
199
188
  end
@@ -13,9 +13,6 @@ module Hobo
13
13
  h.routes_path = Pathname.new File.expand_path('config/hobo_routes.rb', Rails.root)
14
14
  h.rapid_generators_path = Pathname.new File.expand_path('lib/hobo/rapid/generators', Hobo.root)
15
15
  h.auto_taglibs_path = Pathname.new File.expand_path('app/views/taglibs/auto', Rails.root)
16
- h.read_only_file_system = !!ENV['HEROKU_TYPE']
17
- h.show_translation_keys = false
18
- h.dryml_only_templates = false
19
16
  end
20
17
 
21
18
  ActiveSupport.on_load(:action_controller) do
@@ -24,55 +21,44 @@ module Hobo
24
21
  end
25
22
 
26
23
  ActiveSupport.on_load(:active_record) do
27
- require 'hobo/extensions/active_record/associations/collection'
28
- require 'hobo/extensions/active_record/associations/proxy'
29
- require 'hobo/extensions/active_record/associations/reflection'
24
+ require 'hobo/extensions/active_record/association_collection'
25
+ require 'hobo/extensions/active_record/association_proxy'
26
+ require 'hobo/extensions/active_record/association_reflection'
30
27
  require 'hobo/extensions/active_record/hobo_methods'
31
28
  require 'hobo/extensions/active_record/permissions'
32
- require 'hobo/extensions/active_record/associations/scope'
33
- require 'hobo/extensions/active_record/relation_with_origin'
29
+ require 'hobo/extensions/active_record/scopes'
34
30
  require 'hobo/extensions/active_model/name'
35
31
  require 'hobo/extensions/active_model/translation'
36
- # added legacy namespace for backward compatibility
37
- # TODO: remove the following line if Hobo::VERSION > 1.3.x
38
- Hobo::ViewHints = Hobo::Model::ViewHints
39
32
  end
40
33
 
41
34
  ActiveSupport.on_load(:action_view) do
42
35
  require 'hobo/extensions/action_view/tag_helper'
43
- require 'hobo/extensions/action_view/translation_helper'
44
- include Hobo::Helper::Translations::Normalizer
45
36
  end
46
37
 
47
38
  ActiveSupport.on_load(:before_initialize) do
48
39
  require 'hobo/undefined'
49
- HoboFields.never_wrap(Hobo::Undefined)
40
+
50
41
  h = config.hobo
51
42
  Dryml::DrymlGenerator.enable([h.rapid_generators_path], h.auto_taglibs_path)
52
- end
53
43
 
54
- initializer 'hobo.i18n' do |app|
55
- require 'hobo/extensions/i18n' if app.config.hobo.show_translation_keys
44
+ HoboFields.never_wrap(Hobo::Undefined)
56
45
  end
57
46
 
58
47
  initializer 'hobo.routes' do |app|
59
48
  h = app.config.hobo
60
49
  # generate at first boot, so no manual generation is required
61
- unless File.exists?(h.routes_path)
62
- raise Hobo::Error, "No #{h.routes_path} found!" if h.read_only_file_system
63
- Rails::Generators.invoke('hobo:routes', %w[-f -q])
64
- end
50
+ Rails::Generators.invoke('hobo:routes', %w[-f -q]) unless File.exists?(h.routes_path)
65
51
  app.routes_reloader.paths << h.routes_path
66
52
  app.config.to_prepare do
53
+ Rails::Generators.configure!
54
+ # generate before each request in development
67
55
  Rails::Generators.invoke('hobo:routes', %w[-f -q])
68
56
  end
69
57
  end
70
58
 
71
59
  initializer 'hobo.dryml' do |app|
72
- unless app.config.hobo.read_only_file_system
73
- app.config.to_prepare do
74
- Dryml::DrymlGenerator.run
75
- end
60
+ app.config.to_prepare do
61
+ Dryml::DrymlGenerator.run
76
62
  end
77
63
  end
78
64
 
@@ -2,7 +2,7 @@ ActionController::Base.class_eval do
2
2
 
3
3
  def self.hobo_user_controller
4
4
  include Hobo::Controller::Model
5
- include Hobo::Controller::UserBase
5
+ include Hobo::Controller::User
6
6
  end
7
7
 
8
8
  def self.hobo_model_controller
@@ -17,28 +17,4 @@ ActionController::Base.class_eval do
17
17
  base_url
18
18
  end
19
19
 
20
- # moved here from authentication_support.rb for easy overriding
21
- # Redirect as appropriate when an access request fails.
22
- #
23
- # The default action is to redirect to the login screen.
24
- #
25
- # Override this method in your controllers if you want to have special
26
- # behavior in case the user is not authorized
27
- # to access the requested action. For example, a popup window might
28
- # simply close itself.
29
- def access_denied(user_model)
30
- respond_to do |accepts|
31
- accepts.html do
32
- store_location
33
- redirect_to(login_url(user_model))
34
- end
35
- accepts.xml do
36
- headers["Status"] = "Unauthorized"
37
- headers["WWW-Authenticate"] = %(Basic realm="Web Password")
38
- render :text => t("hobo.messages.unauthenticated", :default=>["Couldn't authenticate you"]), :status => '401 Unauthorized'
39
- end
40
- end
41
- false
42
- end
43
-
44
20
  end
@@ -21,7 +21,7 @@ ActiveModel::Translation.class_eval do
21
21
  # otherwise it returns "".
22
22
  def attribute_help(attribute, options = {})
23
23
  defaults = lookup_ancestors.map do |klass|
24
- :"#{self.i18n_scope}.attribute_help.#{klass.to_s.underscore}.#{attribute}"
24
+ :"#{self.i18n_scope}.attribute_help.#{klass.model_name.underscore}.#{attribute}"
25
25
  end
26
26
 
27
27
  defaults << :"attribute_help.#{attribute}"
@@ -28,17 +28,12 @@ module ActiveRecord
28
28
  # DO NOT call super here - AssociationProxy's version loads the collection, and that's bad.
29
29
  # TODO: this really belongs in Rails; migrate it there ASAP
30
30
  def respond_to?(*args)
31
- return super if has_one_collection?
32
- proxy_respond_to?(*args) || [].respond_to?(*args)
31
+ proxy_respond_to?(*args) || Array.new.respond_to?(*args)
33
32
  end
34
33
 
34
+ # TODO: send this patch into Rails. There's no reason to load the collection just to find out it acts like an array.
35
35
  def is_a?(klass)
36
- if has_one_collection?
37
- load_target
38
- @target.is_a?(klass)
39
- else
40
- [].is_a?(klass)
41
- end
36
+ [].is_a?(klass)
42
37
  end
43
38
 
44
39
  def member_class
@@ -57,10 +52,6 @@ module ActiveRecord
57
52
  end
58
53
  end
59
54
 
60
- def has_one_collection?
61
- proxy_reflection.macro == :has_one
62
- end
63
-
64
55
  end
65
56
  end
66
57
  end
@@ -2,16 +2,17 @@ module ActiveRecord
2
2
  module Associations
3
3
  class AssociationProxy #:nodoc:
4
4
 
5
- def origin
6
- proxy_owner
7
- end
5
+ def origin
6
+ proxy_owner
7
+ end
8
8
 
9
- def origin_attribute
10
- proxy_reflection.name
11
- end
9
+ def origin_attribute
10
+ proxy_reflection.name
11
+ end
12
12
 
13
13
  private
14
14
 
15
+
15
16
  def raise_on_type_mismatch(record)
16
17
  # Don't complain if the interface type of a polymorphic association doesn't exist
17
18
  klass = @reflection.klass rescue nil
@@ -0,0 +1,19 @@
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
+ Object.class_eval "class #{e.missing_name} < ActiveRecord::Base; set_table_name '#{active_record.name.tableize}'; end"
11
+ e.missing_name.constantize
12
+ end
13
+ else
14
+ klass_without_create_polymorphic_class
15
+ end
16
+ end
17
+ alias_method_chain :klass, :create_polymorphic_class
18
+
19
+ end
@@ -5,7 +5,7 @@ ActiveRecord::Base.class_eval do
5
5
  end
6
6
  def self.hobo_user_model
7
7
  include Hobo::Model
8
- include Hobo::Model::UserBase
8
+ include Hobo::Model::User
9
9
  end
10
10
  alias_method :has_hobo_method?, :respond_to_without_attributes?
11
11
  end
@@ -0,0 +1,31 @@
1
+ # Add support for :scope => :my_scope to associations
2
+
3
+ ActiveRecord::Associations::ThroughAssociationScope.class_eval do
4
+
5
+ def construct_scope_with_scope
6
+ s = construct_scope_without_scope
7
+ s[:find][:scope] = @reflection.options[:scope]
8
+ s
9
+ end
10
+ alias_method_chain :construct_scope, :scope
11
+
12
+ end
13
+
14
+ ActiveRecord::SpawnMethods.class_eval do
15
+
16
+ def apply_finder_options_with_scope(options)
17
+ scopes = []
18
+ Array.wrap(options.delete(:scope)).each do |s|
19
+ if s.is_a?(Hash)
20
+ s.each_pair{|k,v| scopes << [k,v] }
21
+ else
22
+ scopes << [s]
23
+ end
24
+ end
25
+ relation = apply_finder_options_without_scope(options)
26
+ return relation if scopes.empty?
27
+ scopes.inject(relation) {|r, s| r.send *s }
28
+ end
29
+ alias_method_chain :apply_finder_options, :scope
30
+
31
+ end
@@ -1,13 +1,10 @@
1
1
  # Add support for type metadata to arrays
2
-
3
- require 'will_paginate/array'
4
-
5
2
  class Array
6
3
 
7
4
  attr_accessor :member_class, :origin, :origin_attribute
8
5
 
9
6
  def to_url_path
10
- base_path = origin.try.to_url_path
7
+ base_path = origin_object.try.to_url_path
11
8
  "#{base_path}/#{origin_attribute}" unless base_path.blank?
12
9
  end
13
10
 
@@ -15,13 +12,4 @@ class Array
15
12
  origin and origin_id = origin.try.typed_id and "#{origin_id}:#{origin_attribute}"
16
13
  end
17
14
 
18
- def paginate_with_hobo_metadata(*args, &block)
19
- collection = paginate_without_hobo_metadata(*args, &block)
20
- collection.member_class = member_class
21
- collection.origin = try.proxy_owner
22
- collection.origin_attribute = try.proxy_reflection._?.name
23
- collection
24
- end
25
- alias_method_chain :paginate, :hobo_metadata
26
-
27
15
  end
@@ -58,7 +58,7 @@ module Hobo
58
58
  options[:subsite] ||= self.subsite
59
59
  subsite, method = options.get :subsite, :method
60
60
 
61
- if obj.respond_to?(:member_class) && obj.respond_to?(:origin) && obj.origin
61
+ if obj.respond_to?(:member_class) && obj.respond_to?(:origin)
62
62
  # Asking for URL of a collection, e.g. category/1/adverts or category/1/adverts/new
63
63
 
64
64
  refl = obj.origin.class.reverse_reflection(obj.origin_attribute)
@@ -112,10 +112,7 @@ module Hobo
112
112
 
113
113
  def app_name(add_subsite=true)
114
114
  an = Rails.application.config.hobo.app_name
115
- if add_subsite && subsite
116
- subsite_name = t 'hobo.admin.subsite_name', :default => subsite.titleize
117
- an = an + " - #{subsite_name}"
118
- end
115
+ an = an + " - #{subsite.titleize}" if add_subsite && subsite
119
116
  an
120
117
  end
121
118
 
@@ -126,18 +123,6 @@ module Hobo
126
123
  end
127
124
 
128
125
 
129
- def recognize_page_path
130
- Rails.application.routes.recognize_path(params[:page_path]||request.fullpath)
131
- end
132
-
133
- def url_for_page_path(options={})
134
- url_for recognize_page_path.merge(options)
135
- end
136
-
137
- def controller_action_from_page_path
138
- recognize_page_path.values_at(:controller,:action)
139
- end
140
-
141
126
  def _as_params(name, obj)
142
127
  if obj.is_a? Array
143
128
  obj.map {|x| _as_params("#{name}[]", x)}.join("&")
@@ -179,10 +164,6 @@ module Hobo
179
164
  object.respond_to?(:typed_id) ? "model::#{typed_id(object, attribute).to_s.dasherize}" : ""
180
165
  end
181
166
 
182
- def update_elements_class(updates)
183
- 'update::'+comma_split(updates).join(':') unless updates.blank?
184
- end
185
-
186
167
  def can_create?(object=this)
187
168
  if object.is_a?(Class) and object < ActiveRecord::Base
188
169
  object = object.new
@@ -252,8 +233,7 @@ module Hobo
252
233
  # TODO: Man does this need a big cleanup!
253
234
 
254
235
  if args.empty?
255
- # if we're repeating over an array, this_field ends up with the current index. Is this useful to anybody?
256
- if this_parent && this_field && !this_field.is_a?(Integer)
236
+ if this_parent && this_field
257
237
  object = this_parent
258
238
  field = this_field
259
239
  else
@@ -348,19 +328,19 @@ module Hobo
348
328
 
349
329
 
350
330
  # Login url for a given user record or user class
351
- def forgot_password_url(user_class=Hobo::Model::UserBase.default_user_model)
331
+ def forgot_password_url(user_class=Hobo::Model::User.default_user_model)
352
332
  send("#{user_class.name.underscore}_forgot_password_url") rescue nil
353
333
  end
354
334
 
355
335
 
356
336
  # Login url for a given user record or user class
357
- def login_url(user_class=Hobo::Model::UserBase.default_user_model)
337
+ def login_url(user_class=Hobo::Model::User.default_user_model)
358
338
  send("#{user_class.name.underscore}_login_url") rescue nil
359
339
  end
360
340
 
361
341
 
362
342
  # Sign-up url for a given user record or user class
363
- def signup_url(user_class=Hobo::Model::UserBase.default_user_model)
343
+ def signup_url(user_class=Hobo::Model::User.default_user_model)
364
344
  send("#{user_class.name.underscore}_signup_url") rescue nil
365
345
  end
366
346
 
@@ -400,7 +380,6 @@ module Hobo
400
380
  options = args.extract_options!
401
381
  target = args.empty? || args.first.is_a?(Symbol) ? this : args.shift
402
382
  action = args.first
403
- return false if action.nil? && target.try.new_record?
404
383
 
405
384
  if target.respond_to?(:member_class) && (origin = target.try.origin)
406
385
  klass = origin.class