lib/classy-inheritance.rb in classy-inheritance-0.2.0 vs lib/classy-inheritance.rb in classy-inheritance-0.2.1
- old
+ new
@@ -40,11 +40,10 @@
end
options[:attrs].each{|attr| define_accessors(model_sym, attr)}
end
- private
def can_be(model_sym, options = {})
unless options[:as]
raise ArgumentError, ":as attribute required when calling can_be"
end
@@ -60,10 +59,12 @@
define_method "as_a_#{model_sym}" do
eval("#{klass}.send(:#{find_with_method},self.#{options[:as]}_id)")
end
end
+ private
+
def define_relationship(model_sym, options)
if options[:as]
has_one model_sym, polymorphic_constraints(options[:as])
else
belongs_to model_sym
@@ -120,11 +121,13 @@
end
def define_can_be_method_on_requisite_class(model_sym, polymorphic_name)
klass = model_sym.to_s.classify
requisite_klass = eval(klass)
- requisite_klass.send :can_be, self.name.underscore,
+ unless requisite_klass.respond_to?(self.name.underscore.to_sym)
+ requisite_klass.send :can_be, self.name.underscore,
:as => polymorphic_name
+ end
end
def polymorphic_constraints(polymorphic_name)
{ :foreign_key => "#{polymorphic_name}_id",
:conditions => "#{polymorphic_name}_type = '#{self.name}'"}