lib/classy-inheritance.rb in classy-inheritance-0.4.3 vs lib/classy-inheritance.rb in classy-inheritance-0.4.4

- old
+ new

@@ -37,11 +37,11 @@ if options[:as] 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)} end def can_be(model_sym, options = {}) unless options[:as] @@ -113,21 +113,21 @@ find(*args) CODE end end - def define_accessors(model_sym, attr, prefix) - accessor_method_name = ( prefix ? "#{model_sym}_#{attr}" : attr) + def define_accessors(model_sym, attr, options) + accessor_method_name = ( options[:prefix] ? "#{model_sym}_#{attr}" : attr) define_method accessor_method_name do eval("self.#{model_sym} ? self.#{model_sym}.#{attr} : nil") end define_method "#{accessor_method_name}=" do |val| model_defined = eval("self.#{model_sym}") unless model_defined - klass = model_sym.to_s.classify + klass = options[:class_name] || model_sym.to_s.classify eval("self.#{model_sym} = #{klass}.new") end eval("self.#{model_sym}.#{attr}= val") end