lib/classy-inheritance.rb in classy-inheritance-0.5.0 vs lib/classy-inheritance.rb in classy-inheritance-0.6.0

- old
+ new

@@ -48,11 +48,11 @@ # Adds a find_with_<model_sym> class method define_find_with_method(model_sym) if options[:as] - define_can_be_method_on_requisite_class(model_sym, options[:as]) + define_can_be_method_on_requisite_class(options[:class_name] || model_sym, options[:as]) end options[:attrs].each{|attr| define_accessors(model_sym, attr, options)} end @@ -76,11 +76,11 @@ end private def classy_options - [:as, :attrs, :prefix, :validates_presence_if, :validates_associated_if] + [:as, :attrs, :prefix, :postfix, :validates_presence_if, :validates_associated_if] end def delete_classy_options(options, *keepers) options.delete_if do |key,value| classy_options.include?(key) && !keepers.include?(key) @@ -143,10 +143,18 @@ CODE end end def define_accessors(model_sym, attr, options) - accessor_method_name = ( options[:prefix] ? "#{model_sym}_#{attr}" : attr) + accessor_method_name = attr + + if options[:prefix] + accessor_method_name = (options[:prefix] == true) ? "#{model_sym}_#{accessor_method_name}" : "#{options[:prefix]}_#{accessor_method_name}" + end + + if options[:postfix] + accessor_method_name = (options[:postfix] == true) ? "#{accessor_method_name}_#{model_sym}" : "#{accessor_method_name}_#{options[:postfix]}" + end define_method accessor_method_name do eval("self.#{model_sym} ? self.#{model_sym}.#{attr} : nil") end