Forums » General Forum »
0.4.2 breaks :prefix option
Added by Anonymous 196 days ago
Hi Andrew,
thanks for adding the :class_name and :dependent options now.
Unfortunately, in 0.4.2 I found the :prefix option broken which is one of the key
features of classy-inheritance, actually. ;)
That's why I recommend writing tests for everything.
The error I get:
@/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/hash/keys.rb:47:in `assert_valid_keys': Unknown key(s): prefix (ArgumentError)
from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations.rb:1370:in `create_belongs_to_reflection'
from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations.rb:870:in `belongs_to'
from /Library/Ruby/Gems/1.8/gems/classy-inheritance-0.4.2/lib/classy-inheritance.rb:74:in `define_relationship'
from /Library/Ruby/Gems/1.8/gems/classy-inheritance-0.4.2/lib/classy-inheritance.rb:27:in `depends_on'
from /Users/pascal/Development/ODAdata/ODAmoz/vendor/plugins/contactable/lib/contactable.rb:8:in `has_contact'
from /Users/pascal/Development/ODAdata/ODAmoz/app/models/donor.rb:13
from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:215:in `load_without_new_constant_marking'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:215:in `load_file'
... 69 levels...
from /Library/Ruby/Gems/1.8/gems/rails-2.1.0/lib/commands/server.rb:39
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in `require'
from ./script/server:3
@
Hope you will be able to fix that soon, shouldn't be a big deal imho.
Best
Pascal
Replies
RE: 0.4.2 breaks :prefix option - Added by Anonymous 196 days ago
In addition there still has been a problem with the class_name option,
even though it got passed through to the relation, it wasn't recognized when
trying to generate the actual model.
So here is a patch for both issues:
diff --git a/lib/classy-inheritance.rb b/lib/classy-inheritance.rb
index 29d03a8..2da1da5 100644
--- a/lib/classy-inheritance.rb
+++ b/lib/classy-inheritance.rb
@@ -39,7 +39,7 @@ module Stonean
define_can_be_method_on_requisite_class(model_sym, options[:as])
end
- options[:attrs].each{|attr| define_accessors(model_sym, attr, options[:prefix])}
+ options[:attrs].each{|attr| define_accessors(model_sym, attr, options[:prefix], options[:class_name])}
end
@@ -65,7 +65,7 @@ module Stonean
def define_relationship(model_sym, options)
opts = options.dup
- opts.delete(:attrs)
+ opts.delete_if { |k, v| [:attrs, :prefix].include?(k) }
if opts[:as]
as_opt = opts.delete(:as)
opts = polymorphic_constraints(as_opt).merge(opts)
@@ -115,7 +115,7 @@ module Stonean
end
end
- def define_accessors(model_sym, attr, prefix)
+ def define_accessors(model_sym, attr, prefix, class_name)
accessor_method_name = ( prefix ? "#{model_sym}_#{attr}" : attr)
define_method accessor_method_name do
@@ -126,7 +126,7 @@ module Stonean
model_defined = eval("self.#{model_sym}")
unless model_defined
- klass = model_sym.to_s.classify
+ klass = class_name || model_sym.to_s.classify
eval("self.#{model_sym} = #{klass}.new")
end
Pascal
RE: 0.4.2 breaks :prefix option - Added by Andrew Stone 196 days ago
Pascal, thanks for the notice and an update has been released: 0.4.4. My next order of business is to create some tests for this project.