lib/classy-inheritance.rb in classy-inheritance-0.1.0 vs lib/classy-inheritance.rb in classy-inheritance-0.1.1
- old
+ new
@@ -30,11 +30,12 @@
validates_associated model_sym
# Before save functionality to create/update the requisite object
define_save_method(model_sym, options[:as])
- define_find_method(model_sym)
+ # Adds a find_with_<model_sym> class method
+ define_find_with_method(model_sym)
options[:attrs].each{|attr| define_accessors(model_sym, attr)}
end
@@ -59,20 +60,20 @@
end
before_save "save_requisite_#{model_sym}".to_sym
end
- def define_find_method(model_sym)
+ def define_find_with_method(model_sym)
self.class.send :define_method, "find_with_#{model_sym}" do |*args|
eval <<-CODE
if args[1] && args[1].is_a?(Hash)
if args[1].has_key?(:include)
inc_val = args[1][:include]
new_val = inc_val.is_a?(Array) ? inc_val.push(:#{:model_sym}) : [inc_val, :#{model_sym}]
args[1][:include] = new_val
else
- args[1].merge({:include => :#{model_sym}})
+ args[1].merge!({:include => :#{model_sym}})
end
else
args << {:include => :#{model_sym}}
end
find(*args)
@@ -99,10 +100,9 @@
def polymorphic_constraints(polymorphic_name)
{ :foreign_key => "#{polymorphic_name}_id",
:conditions => "#{polymorphic_name}_type = '#{self.name}'"}
end
-
end # ClassMethods
end # ClassyInheritance module
end # Stonean module
ActiveRecord::Base.send :include, Stonean::ClassyInheritance