hobo 1.3.3 → 1.4.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- data/{CHANGES.txt → CHANGES-1.3.txt} +0 -0
- data/CHANGES-1.4.txt +678 -0
- data/Rakefile +13 -3
- data/TODO-1.4.txt +69 -0
- data/VERSION +1 -1
- data/app/helpers/hobo_debug_helper.rb +16 -0
- data/app/helpers/hobo_deprecated_helper.rb +45 -0
- data/app/helpers/hobo_helper_base.rb +8 -0
- data/app/helpers/hobo_permissions_helper.rb +136 -0
- data/app/helpers/hobo_route_helper.rb +196 -0
- data/{lib/hobo/helper/translations.rb → app/helpers/hobo_translations_helper.rb} +4 -7
- data/{lib/hobo/helper/translations/normalizer.rb → app/helpers/hobo_translations_normalizer_helper.rb} +3 -10
- data/app/helpers/hobo_type_helper.rb +24 -0
- data/app/helpers/hobo_view_hint_helper.rb +13 -0
- data/hobo.gemspec +3 -3
- data/lib/generators/hobo/admin_subsite/admin_subsite_generator.rb +0 -9
- data/lib/generators/hobo/admin_subsite/templates/application.dryml +2 -0
- data/lib/generators/hobo/admin_subsite/templates/gitkeep +0 -0
- data/lib/generators/hobo/admin_subsite/templates/site.css.erb +9 -0
- data/lib/generators/hobo/admin_subsite/templates/site.js.erb +10 -0
- data/lib/generators/hobo/assets/assets_generator.rb +16 -2
- data/lib/generators/hobo/assets/templates/application.css +9 -0
- data/lib/generators/hobo/assets/templates/application.dryml.erb +0 -5
- data/lib/generators/hobo/assets/templates/application.js +11 -0
- data/lib/generators/hobo/assets/templates/front.css +10 -0
- data/lib/generators/hobo/assets/templates/front.js +11 -0
- data/lib/generators/hobo/assets/templates/front_site.dryml.erb +6 -0
- data/lib/generators/hobo/assets/templates/gitkeep +0 -0
- data/lib/generators/hobo/dev_tweaks/dev_tweaks_generator.rb +31 -0
- data/lib/generators/hobo/i18n/templates/hobo.en.yml +1 -1
- data/lib/generators/hobo/install_plugin/USAGE +3 -0
- data/lib/generators/hobo/install_plugin/install_plugin_generator.rb +36 -0
- data/lib/generators/hobo/plugin.rb +112 -0
- data/lib/generators/hobo/setup_wizard/setup_wizard_generator.rb +31 -14
- data/lib/generators/hobo/subsite.rb +16 -2
- data/lib/generators/hobo/subsite/templates/gitkeep +0 -0
- data/lib/generators/hobo/subsite/templates/site.css.erb +9 -0
- data/lib/generators/hobo/subsite/templates/site.js.erb +10 -0
- data/lib/generators/hobo/subsite_taglib/templates/taglib.dryml.erb +0 -17
- data/lib/generators/hobo/test_framework/test_framework_generator.rb +1 -1
- data/lib/hobo.rb +3 -2
- data/lib/hobo/controller.rb +43 -24
- data/lib/hobo/controller/model.rb +63 -42
- data/lib/hobo/controller/user_base.rb +1 -3
- data/lib/hobo/engine.rb +1 -1
- data/lib/hobo/extensions/active_record/associations/association.rb +36 -0
- data/lib/hobo/extensions/active_record/associations/collection.rb +10 -19
- data/lib/hobo/extensions/active_record/associations/proxy.rb +3 -15
- data/lib/hobo/extensions/active_record/associations/scope.rb +2 -2
- data/lib/hobo/extensions/active_record/permissions.rb +32 -38
- data/lib/hobo/extensions/active_record/relation_with_origin.rb +5 -5
- data/lib/hobo/model.rb +12 -7
- data/lib/hobo/model/accessible_associations.rb +8 -15
- data/lib/hobo/model/lifecycles/creator.rb +1 -1
- data/lib/hobo/model/lifecycles/transition.rb +1 -1
- data/lib/hobo/model/permissions.rb +4 -4
- data/lib/hobo/model/scopes.rb +4 -17
- data/lib/hobo/model/scopes/automatic_scopes.rb +5 -13
- data/lib/hobo/rapid/helper.rb +1 -161
- data/lib/hobo/rapid/taglibs/rapid.dryml +3 -17
- data/test/doctest/hobo/hobo_helper.rdoctest +8 -44
- data/{doctests → test/doctest}/hobo/lifecycles.rdoctest +0 -0
- data/{doctests → test/doctest}/hobo/model.rdoctest +2 -4
- data/{doctests → test/doctest}/hobo/multi_model_forms.rdoctest +3 -24
- data/{doctests → test/doctest}/hobo/scopes.rdoctest +3 -53
- data/test/doctest/prepare_testapp.rb +11 -0
- data/test/irt/generators/admin_subsite.irt +1 -19
- data/test/irt/generators/assets.irt +4 -9
- data/test/irt/generators/controller.irt +0 -3
- data/test/irt/generators/front_controller.irt +0 -5
- data/test/irt/generators/{helper.rb → irt_helper.rb} +2 -2
- data/test/irt/generators/model.irt +1 -12
- data/test/irt/generators/partials/_account_user_model_tests.rb +0 -8
- data/test/irt/generators/partials/_accounts_users_controller_tests.rb +0 -2
- data/test/irt/generators/partials/_default_user_model_tests.rb +0 -8
- data/test/irt/generators/partials/_default_users_controller_tests.rb +0 -2
- data/test/irt/generators/partials/_house_controller_tests.rb +0 -2
- data/test/irt/generators/partials/_house_model_tests.rb +1 -9
- data/test/irt/generators/partials/_subsite_taglib_admin.rb +5 -2
- data/test/irt/generators/partials/_subsite_taglib_admin_invite_only.rb +1 -1
- data/test/irt/generators/partials/_subsite_taglib_noopt.rb +2 -2
- data/test/irt/generators/partials/_subsite_taglib_variables.rb +0 -15
- data/test/irt/generators/partials/_user_mailer_tests.rb +1 -3
- data/test/irt/generators/resource.irt +0 -3
- data/test/irt/generators/subsite.irt +6 -22
- data/test/irt/generators/subsite_taglib.irt +0 -18
- data/test/irt/generators/test_framework.irt +2 -5
- data/test/irt/generators/user_controller.irt +0 -3
- data/test/irt/generators/user_mailer.irt +0 -3
- data/test/irt/generators/user_model.irt +0 -3
- data/test/irt/generators/user_resource.irt +0 -3
- data/test/irt/readme.txt +6 -3
- metadata +116 -159
- data/app/controllers/dev_controller.rb +0 -25
- data/app/views/dev/summary.dryml +0 -102
- data/doctests/prepare_testapp.rb +0 -8
- data/lib/generators/hobo/admin_subsite/templates/admin.css +0 -20
- data/lib/generators/hobo/rapid/USAGE +0 -3
- data/lib/generators/hobo/rapid/rapid_generator.rb +0 -24
- data/lib/generators/hobo/rapid/templates/IE7.js +0 -2
- data/lib/generators/hobo/rapid/templates/blank.gif +0 -0
- data/lib/generators/hobo/rapid/templates/hobo-rapid.css +0 -94
- data/lib/generators/hobo/rapid/templates/hobo-rapid.js +0 -1015
- data/lib/generators/hobo/rapid/templates/ie7-recalc.js +0 -166
- data/lib/generators/hobo/rapid/templates/lowpro.js +0 -339
- data/lib/generators/hobo/rapid/templates/reset.css +0 -95
- data/lib/generators/hobo/rapid/templates/themes/clean/public/images/101-3B5F87-ACD3E6.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean/public/images/30-3E547A-242E42.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean/public/images/30-DBE1E5-FCFEF5.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean/public/images/300-ACD3E6-fff.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean/public/images/50-ACD3E6-fff.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean/public/images/fieldbg.gif +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean/public/images/pencil.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean/public/images/small_close.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean/public/images/spinner.gif +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/clean.css +0 -327
- data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/rapid-ui.css +0 -102
- data/lib/generators/hobo/rapid/templates/themes/clean/views/clean.dryml +0 -10
- data/lib/hobo/helper.rb +0 -460
- data/lib/hobo/rapid/taglibs/rapid_core.dryml +0 -808
- data/lib/hobo/rapid/taglibs/rapid_document_tags.dryml +0 -56
- data/lib/hobo/rapid/taglibs/rapid_editing.dryml +0 -287
- data/lib/hobo/rapid/taglibs/rapid_forms.dryml +0 -1156
- data/lib/hobo/rapid/taglibs/rapid_generics.dryml +0 -48
- data/lib/hobo/rapid/taglibs/rapid_i18n.dryml +0 -173
- data/lib/hobo/rapid/taglibs/rapid_lifecycles.dryml +0 -96
- data/lib/hobo/rapid/taglibs/rapid_navigation.dryml +0 -108
- data/lib/hobo/rapid/taglibs/rapid_pages.dryml +0 -259
- data/lib/hobo/rapid/taglibs/rapid_plus.dryml +0 -247
- data/lib/hobo/rapid/taglibs/rapid_summary.dryml +0 -283
- data/lib/hobo/rapid/taglibs/rapid_support.dryml +0 -102
- data/lib/hobo/rapid/taglibs/rapid_user_pages.dryml +0 -182
- data/test/irt/generators/rapid.irt +0 -29
@@ -15,8 +15,6 @@ module Hobo
|
|
15
15
|
skip_before_filter :login_required, :only => [:login, :signup, :do_signup, :forgot_password, :reset_password, :do_reset_password,
|
16
16
|
:accept_invitation, :do_accept_invitation]
|
17
17
|
|
18
|
-
include_taglib "rapid_user_pages", :plugin => "hobo"
|
19
|
-
|
20
18
|
alias_method_chain :hobo_update, :account_flash
|
21
19
|
end
|
22
20
|
|
@@ -112,7 +110,7 @@ module Hobo
|
|
112
110
|
|
113
111
|
def hobo_forgot_password
|
114
112
|
if request.post?
|
115
|
-
user = model.find_by_email_address(params[:email_address]
|
113
|
+
user = model.find_by_email_address(params[:email_address])
|
116
114
|
if user && (!block_given? || yield(user))
|
117
115
|
user.lifecycle.request_password_reset!(:nobody)
|
118
116
|
end
|
data/lib/hobo/engine.rb
CHANGED
@@ -24,6 +24,7 @@ module Hobo
|
|
24
24
|
end
|
25
25
|
|
26
26
|
ActiveSupport.on_load(:active_record) do
|
27
|
+
require 'hobo/extensions/active_record/associations/association'
|
27
28
|
require 'hobo/extensions/active_record/associations/collection'
|
28
29
|
require 'hobo/extensions/active_record/associations/proxy'
|
29
30
|
require 'hobo/extensions/active_record/associations/reflection'
|
@@ -41,7 +42,6 @@ module Hobo
|
|
41
42
|
ActiveSupport.on_load(:action_view) do
|
42
43
|
require 'hobo/extensions/action_view/tag_helper'
|
43
44
|
require 'hobo/extensions/action_view/translation_helper'
|
44
|
-
include Hobo::Helper::Translations::Normalizer
|
45
45
|
end
|
46
46
|
|
47
47
|
ActiveSupport.on_load(:before_initialize) do
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Associations
|
3
|
+
class Association #:nodoc:
|
4
|
+
def scoped
|
5
|
+
# Rails implementation just returns target_scope.merge(association_scope)
|
6
|
+
sc = target_scope.merge(association_scope)
|
7
|
+
|
8
|
+
# Hobo adds in scopes declared on the association, e.g. has_many ..... :scope => :foo
|
9
|
+
if (declared_scope = options[:scope])
|
10
|
+
if declared_scope.is_a? Array
|
11
|
+
declared_scope.inject(sc) { |result, element| result.merge(klass.send(element)) }
|
12
|
+
elsif declared_scope.is_a? Hash
|
13
|
+
method = declared_scope.keys.first
|
14
|
+
arg = declared_scope.values.first
|
15
|
+
sc.merge(klass.send(method, arg))
|
16
|
+
else
|
17
|
+
# It's just a symbol -- the name of a scope
|
18
|
+
sc.merge(klass.send(declared_scope))
|
19
|
+
end
|
20
|
+
else
|
21
|
+
sc
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def raise_on_type_mismatch(record)
|
28
|
+
# Don't complain if the interface type of a polymorphic association doesn't exist
|
29
|
+
klass = @reflection.klass rescue nil
|
30
|
+
unless klass.nil? || record.is_a?(klass)
|
31
|
+
raise ActiveRecord::AssociationTypeMismatch, "#{@reflection.klass} expected, got #{record.class}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module Associations
|
3
|
-
class
|
3
|
+
class CollectionProxy
|
4
4
|
|
5
5
|
include Hobo::Model::Scopes::ApplyScopes
|
6
6
|
|
7
7
|
|
8
8
|
def hobo_association_collection?
|
9
|
-
Hobo::Model.in?(
|
9
|
+
Hobo::Model.in?(proxy_association.owner.class.included_modules)
|
10
10
|
end
|
11
11
|
|
12
12
|
|
13
13
|
def new_candidate(attributes = {})
|
14
14
|
record = new
|
15
|
-
|
15
|
+
proxy_association.target.delete record
|
16
16
|
set_reverse_association(record) if hobo_association_collection?
|
17
17
|
record
|
18
18
|
end
|
@@ -20,45 +20,36 @@ module ActiveRecord
|
|
20
20
|
|
21
21
|
def user_new_candidate(user, attributes = {})
|
22
22
|
record = user_new(user, attributes)
|
23
|
-
|
23
|
+
proxy_association.target.delete record
|
24
24
|
set_reverse_association(record) if hobo_association_collection?
|
25
25
|
record
|
26
26
|
end
|
27
27
|
|
28
|
-
# DO NOT call super here - AssociationProxy's version loads the collection, and that's bad.
|
29
|
-
# TODO: this really belongs in Rails; migrate it there ASAP
|
30
|
-
def respond_to?(*args)
|
31
|
-
return super if has_one_collection?
|
32
|
-
proxy_respond_to?(*args) || [].respond_to?(*args)
|
33
|
-
end
|
34
|
-
|
35
28
|
def is_a?(klass)
|
36
29
|
if has_one_collection?
|
37
30
|
load_target
|
38
|
-
|
31
|
+
proxy_association.target.is_a?(klass)
|
39
32
|
else
|
40
33
|
[].is_a?(klass)
|
41
34
|
end
|
42
35
|
end
|
43
36
|
|
44
37
|
def member_class
|
45
|
-
|
38
|
+
proxy_association.reflection.klass
|
46
39
|
end
|
47
40
|
|
48
41
|
private
|
49
42
|
|
50
43
|
def set_reverse_association(object)
|
51
|
-
if
|
52
|
-
(refl =
|
44
|
+
if proxy_association.owner.new_record? &&
|
45
|
+
(refl = proxy_association.owner.class.reverse_reflection(proxy_association.reflection.name)) &&
|
53
46
|
refl.macro == :belongs_to
|
54
|
-
|
55
|
-
bta.replace(@owner)
|
56
|
-
object.instance_variable_set("@#{refl.name}", bta)
|
47
|
+
object.send("#{refl.name}=", proxy_association.owner)
|
57
48
|
end
|
58
49
|
end
|
59
50
|
|
60
51
|
def has_one_collection?
|
61
|
-
|
52
|
+
proxy_association.reflection.macro == :has_one
|
62
53
|
end
|
63
54
|
|
64
55
|
end
|
@@ -1,25 +1,13 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module Associations
|
3
|
-
class
|
4
|
-
|
3
|
+
class CollectionProxy #:nodoc:
|
5
4
|
def origin
|
6
|
-
|
5
|
+
proxy_association.owner
|
7
6
|
end
|
8
7
|
|
9
8
|
def origin_attribute
|
10
|
-
|
9
|
+
proxy_association.reflection.name
|
11
10
|
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def raise_on_type_mismatch(record)
|
16
|
-
# Don't complain if the interface type of a polymorphic association doesn't exist
|
17
|
-
klass = @reflection.klass rescue nil
|
18
|
-
unless klass.nil? || record.is_a?(klass)
|
19
|
-
raise ActiveRecord::AssociationTypeMismatch, "#{@reflection.klass} expected, got #{record.class}"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
11
|
end
|
24
12
|
end
|
25
13
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module ActiveRecord
|
4
4
|
module Associations
|
5
|
-
module ThroughAssociationScope
|
5
|
+
module ThroughAssociationScope # No such module in ActiveRecord any more - there is only ThroughAssociation
|
6
6
|
|
7
7
|
def construct_scope_with_scope
|
8
8
|
s = construct_scope_without_scope
|
@@ -12,7 +12,7 @@ module ActiveRecord
|
|
12
12
|
alias_method_chain :construct_scope, :scope
|
13
13
|
|
14
14
|
end
|
15
|
-
end
|
15
|
+
end if false # DISABLED Getting Rails 3.1 working
|
16
16
|
|
17
17
|
module SpawnMethods
|
18
18
|
|
@@ -6,15 +6,19 @@ ActiveRecord::Associations::HasManyAssociation.class_eval do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
|
9
|
-
def delete_records(records)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
def delete_records(records, method)
|
10
|
+
if method == :destroy
|
11
|
+
records.each { |r| r.is_a?(Hobo::Model) ? r.user_destroy(acting_user) : r.destroy }
|
12
|
+
update_counter(-records.length) unless inverse_updates_counter_cache?
|
13
|
+
else
|
14
|
+
keys = records.map { |r| r[reflection.association_primary_key] }
|
15
|
+
scope = scoped.where(reflection.association_primary_key => keys)
|
16
|
+
|
17
|
+
if method == :delete_all
|
18
|
+
update_counter(-scope.delete_all)
|
16
19
|
else
|
17
|
-
|
20
|
+
update_counter(-scope.update_all(reflection.foreign_key => nil))
|
21
|
+
end
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
@@ -23,34 +27,27 @@ ActiveRecord::Associations::HasManyAssociation.class_eval do
|
|
23
27
|
# and record in question are Hobo models
|
24
28
|
def nullify_keys(records)
|
25
29
|
if (user = acting_user)
|
26
|
-
records.each { |r| r.user_update_attributes!(user, @reflection.
|
30
|
+
records.each { |r| r.user_update_attributes!(user, @reflection.foreign_key => nil) if r.is_a?(Hobo::Model) }
|
27
31
|
end
|
28
32
|
|
29
33
|
# Normal ActiveRecord implementatin
|
30
34
|
ids = records.map { |record| record.quoted_id }.join(',')
|
31
35
|
@reflection.klass.update_all(
|
32
|
-
"#{@reflection.
|
33
|
-
"#{@reflection.
|
36
|
+
"#{@reflection.foreign_key} = NULL",
|
37
|
+
"#{@reflection.foreign_key} = #{@owner.quoted_id} AND #{@reflection.klass.primary_key} IN (#{ids})"
|
34
38
|
)
|
35
39
|
end
|
36
40
|
|
37
41
|
|
38
|
-
def
|
39
|
-
|
42
|
+
def insert_record_with_owner_attributes(record, force = true, raise = false)
|
43
|
+
set_owner_attributes(record)
|
40
44
|
if (user = acting_user) && record.is_a?(Hobo::Model)
|
41
|
-
|
42
|
-
record.user_save!(user)
|
43
|
-
else
|
44
|
-
record.user_save(user, validate)
|
45
|
-
end
|
45
|
+
with_acting_user(user) { insert_record_without_owner_attributes(record, force, raise) }
|
46
46
|
else
|
47
|
-
|
48
|
-
record.save!
|
49
|
-
else
|
50
|
-
record.save(:validate => validate)
|
51
|
-
end
|
47
|
+
insert_record_without_owner_attributes(record, force, raise)
|
52
48
|
end
|
53
49
|
end
|
50
|
+
alias_method_chain :insert_record, :owner_attributes
|
54
51
|
|
55
52
|
def viewable_by?(user, field=nil)
|
56
53
|
# view check on an example member record is not supported on associations with conditions
|
@@ -97,23 +94,20 @@ ActiveRecord::Associations::HasManyThroughAssociation.class_eval do
|
|
97
94
|
end
|
98
95
|
|
99
96
|
|
100
|
-
def
|
101
|
-
user = acting_user
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
else
|
106
|
-
return false unless (user ? record.user_save(user, validate) : record.save(validate))
|
107
|
-
end
|
97
|
+
def insert_record_with_owner_attributes(record, force = true, raise = false)
|
98
|
+
if (user = acting_user) && record.is_a?(Hobo::Model)
|
99
|
+
with_acting_user(user) { insert_record_without_owner_attributes(record, force, raise) }
|
100
|
+
else
|
101
|
+
insert_record_without_owner_attributes(record, force, raise)
|
108
102
|
end
|
109
|
-
|
110
|
-
@
|
111
|
-
|
103
|
+
# the following code was in Hobo 1.3, but isn't required if you have the :inverse_of option set
|
104
|
+
# klass = @reflection.through_reflection.klass
|
105
|
+
# @owner.send(@reflection.through_reflection.name).proxy_target << klass.send(:with_scope, :create => construct_join_attributes(record)) { user ? klass.user_create!(user) : klass.create! }
|
112
106
|
end
|
113
|
-
|
107
|
+
alias_method_chain :insert_record, :owner_attributes
|
114
108
|
|
115
109
|
# TODO - add dependent option support
|
116
|
-
def delete_records_with_hobo_permission_check(records)
|
110
|
+
def delete_records_with_hobo_permission_check(records, method)
|
117
111
|
klass = @reflection.through_reflection.klass
|
118
112
|
user = acting_user
|
119
113
|
if user && records.any? { |r|
|
@@ -122,13 +116,13 @@ ActiveRecord::Associations::HasManyThroughAssociation.class_eval do
|
|
122
116
|
}
|
123
117
|
raise Hobo::PermissionDeniedError, "#{@owner.class}##{proxy_reflection.name}.destroy"
|
124
118
|
end
|
125
|
-
delete_records_without_hobo_permission_check(records)
|
119
|
+
delete_records_without_hobo_permission_check(records, method)
|
126
120
|
end
|
127
121
|
alias_method_chain :delete_records, :hobo_permission_check
|
128
122
|
|
129
123
|
end
|
130
124
|
|
131
|
-
ActiveRecord::Associations::
|
125
|
+
ActiveRecord::Associations::AssociationProxy.class_eval do
|
132
126
|
|
133
127
|
# Helper - the user acting on the owner (if there is one)
|
134
128
|
def acting_user
|
@@ -20,20 +20,20 @@ module ActiveRecord
|
|
20
20
|
end
|
21
21
|
|
22
22
|
module Associations
|
23
|
-
class
|
23
|
+
class CollectionProxy
|
24
24
|
|
25
25
|
def scoped_with_origin
|
26
26
|
relation = scoped_without_origin.clone
|
27
|
-
relation.origin =
|
28
|
-
relation.origin_attribute =
|
27
|
+
relation.origin = proxy_association.owner
|
28
|
+
relation.origin_attribute = proxy_association.reflection.name
|
29
29
|
relation
|
30
30
|
end
|
31
31
|
alias_method_chain :scoped, :origin
|
32
32
|
|
33
33
|
def method_missing_with_origin(method, *args, &block)
|
34
34
|
res = method_missing_without_origin(method, *args, &block)
|
35
|
-
res.origin =
|
36
|
-
res.origin_attribute =
|
35
|
+
res.origin = proxy_association.owner if res.respond_to?(:origin)
|
36
|
+
res.origin_attribute = proxy_association.reflection.name if res.respond_to?(:origin_attribute)
|
37
37
|
res
|
38
38
|
end
|
39
39
|
alias_method_chain :method_missing, :origin
|
data/lib/hobo/model.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Hobo
|
2
|
-
|
3
2
|
module Model
|
3
|
+
require 'will_paginate/active_record'
|
4
4
|
|
5
5
|
class NoNameError < RuntimeError; end
|
6
6
|
|
@@ -167,23 +167,23 @@ module Hobo
|
|
167
167
|
# (ie X belongs_to Y (polymorphic), Z is a subclass of Y; @x.y_is?(some_z) will never pass)
|
168
168
|
class_eval %{
|
169
169
|
def #{name}_is?(target)
|
170
|
-
target.class.name == self.#{refl.options[:foreign_type]} && target.#{id_method} == self.#{refl.
|
170
|
+
target.class.name == self.#{refl.options[:foreign_type]} && target.#{id_method} == self.#{refl.foreign_key}
|
171
171
|
end
|
172
172
|
def #{name}_changed?
|
173
|
-
#{refl.
|
173
|
+
#{refl.foreign_key}_changed? || #{refl.options[:foreign_type]}_changed?
|
174
174
|
end
|
175
175
|
}
|
176
176
|
else
|
177
177
|
id_method = refl.options[:primary_key] || refl.klass.primary_key
|
178
178
|
class_eval %{
|
179
179
|
def #{name}_is?(target)
|
180
|
-
our_id = self.#{refl.
|
180
|
+
our_id = self.#{refl.foreign_key}
|
181
181
|
# if our_id is nil, only return true if target is nil
|
182
182
|
return target.nil? unless our_id
|
183
183
|
target.class <= ::#{refl.klass.name} && target.#{id_method} == our_id
|
184
184
|
end
|
185
185
|
def #{name}_changed?
|
186
|
-
#{refl.
|
186
|
+
#{refl.foreign_key}_changed?
|
187
187
|
end
|
188
188
|
}
|
189
189
|
end
|
@@ -298,7 +298,7 @@ module Hobo
|
|
298
298
|
r.klass >= self &&
|
299
299
|
!r.options[:conditions] &&
|
300
300
|
!r.options[:scope] &&
|
301
|
-
r.
|
301
|
+
r.foreign_key == refl.foreign_key
|
302
302
|
end
|
303
303
|
end
|
304
304
|
end
|
@@ -377,7 +377,12 @@ module Hobo
|
|
377
377
|
|
378
378
|
def attributes_with_hobo_type_conversion=(attributes, guard_protected_attributes=true)
|
379
379
|
converted = attributes.map_hash { |k, v| convert_type_for_mass_assignment(self.class.attr_type(k), v) }
|
380
|
-
|
380
|
+
# Avoid passing this third argument if possible, to avoid a deprecation warning in Rails 3.1
|
381
|
+
if guard_protected_attributes
|
382
|
+
send(:attributes_without_hobo_type_conversion=, converted)
|
383
|
+
else
|
384
|
+
send(:attributes_without_hobo_type_conversion=, converted, true)
|
385
|
+
end
|
381
386
|
end
|
382
387
|
|
383
388
|
|
@@ -5,11 +5,13 @@ module Hobo
|
|
5
5
|
extend self
|
6
6
|
|
7
7
|
def prepare_has_many_assignment(association, association_name, array_or_hash)
|
8
|
-
owner = association.
|
8
|
+
owner = association.proxy_association.owner
|
9
9
|
|
10
10
|
array = params_hash_to_array(array_or_hash)
|
11
11
|
array.map! do |record_hash_or_string|
|
12
|
-
finder = association.member_class
|
12
|
+
finder = association.member_class
|
13
|
+
conditions = association.proxy_association.reflection.conditions
|
14
|
+
finder = finder.scoped :conditions => conditions unless conditions == [[]] || conditions == [[],[]]
|
13
15
|
find_or_create_and_update(owner, association_name, finder, record_hash_or_string) do |id|
|
14
16
|
# The block is required to either locate find an existing record in the collection, or build a new one
|
15
17
|
if id
|
@@ -109,7 +111,7 @@ module Hobo
|
|
109
111
|
__items = Hobo::Model::AccessibleAssociations.prepare_has_many_assignment(#{name}, :#{name}, array_or_hash)
|
110
112
|
self.#{name}_without_accessible = __items
|
111
113
|
# ensure the loaded array contains any changed records
|
112
|
-
self
|
114
|
+
self.association(:#{name}).target[0..-1] = __items
|
113
115
|
end
|
114
116
|
}, __FILE__, __LINE__ - 7
|
115
117
|
alias_method_chain :"#{name}=", :accessible
|
@@ -160,18 +162,9 @@ module Hobo
|
|
160
162
|
metaclass.alias_method_chain :belongs_to, :accessible
|
161
163
|
|
162
164
|
|
163
|
-
# Add :accessible to the valid
|
164
|
-
|
165
|
-
|
166
|
-
valid_keys_for_has_many_association_without_accessible + [:accessible]
|
167
|
-
end
|
168
|
-
metaclass.alias_method_chain :valid_keys_for_has_many_association, :accessible
|
169
|
-
|
170
|
-
def self.valid_keys_for_belongs_to_association_with_accessible
|
171
|
-
valid_keys_for_belongs_to_association_without_accessible + [:accessible]
|
172
|
-
end
|
173
|
-
metaclass.alias_method_chain :valid_keys_for_belongs_to_association, :accessible
|
174
|
-
|
165
|
+
# Add :accessible to the valid options so AR doesn't complain
|
166
|
+
::ActiveRecord::Associations::Builder::BelongsTo.valid_options << :accessible
|
167
|
+
::ActiveRecord::Associations::Builder::HasMany.valid_options << :accessible
|
175
168
|
|
176
169
|
end
|
177
170
|
end
|