small patches for class option and postfix

Added by Brian Johnson 174 days ago

I implemented the following changes to add support for the :class options for depends_on and also added support for a configurable prefix and postfix. I needed these changes to work with Globalize because I had too many mysql text columns in one row. I created a separate description_localization model to contain my localized descriptions and tagged them with the language code. I'm also including the patch to globalize to call localized methods instead of attributes in case anybody else is interested, but it's only relevant for keep_translations_in_model. The classy inheritance patch should be of general interest I think.

classy-inheritance.rb

@ -50,7 +50,7 @
define_find_with_method(model_sym) - 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 @ -78,7 +78,7 @
private - [:as, :attrs, :prefix, :validates_presence_if, :validates_associated_if]
+ [:as, :attrs, :prefix, :postfix, :validates_presence_if, :validates_associated_if]
end @ -145,7 +145,8 @
end - accessor_method_name = ( options[:prefix] ? "#{model_sym}_#{attr}" : attr)
+ accessor_method_name = ( options[:prefix] ? "#{options[:prefix] true ? model_sym : options[:prefix]}_#{accessor_method_name}" : accessor_method_name)
+ accessor_method_name = ( options[:postfix] ? "#{attr}_#{options[:postfix] true ? model_sym : options[:postfix]}" : attr)

define_method accessor_method_name do
eval("self.#{model_sym} ? self.#{model_sym}.#{attr} : nil")

db_translate.rb from globalize

@ -465,7 +465,7 @
def #{facet}=(value)
unless Locale.base?
localized_method = "#{facet}_\#{Locale.language.code}"
- write_attribute(localized_method.to_sym, value) if respond_to?(localized_method.to_sym)
+ send("\#{localized_method}=", value) if respond_to?(localized_method.to_sym)
else
write_attribute(:#{facet}, value)
end


Replies

RE: small patches for class option and postfix - Added by Andrew Stone 174 days ago

Brian,

Fantastic! Thanks for the contribution. I'll get this in asap.

-andy

RE: small patches for class option and postfix - Added by Brian Johnson 174 days ago

I was trying to come up with a way to do a sort of reverse condition, where you could specify attributes that would be set on save. For instance, in my application, I need to tag each model with a language code, and the depends_on has a condition "language_code = 'es'" or whatever. I added a callback in my model to set the language code, but maybe there would be a good way to integrate it into the depends_on declaration? That way your conditions would work seamlessly on save. Without it, it saves, but it never gets linked back because the condition is not met. This is for the polymorphic case. Nice plugin, it has solved several problems for me in a very elegant way.

RE: small patches for class option and postfix - Added by Andrew Stone 171 days ago

Brian,

I'll give this some thought and see if I can think of anything that would make this simple. If I come up with something I'll post it to this forum (on a new thread).

Thanks again for your contributions,
andy

www.Get-Free-Date.com : Jewish dating agency - Added by Anonymous 27 days ago

Found this way to get free Jewish free date on the internet. If you have heard of Adult friend finder
then go to this website and get follow the procedure to get free adult friend finder gold membership.

As you go through the process you will get registered to the Jewish Frind finder service also.
Use the points to get a gold membership of the Jewish friend finder site instead of the AFF main site.

Once you are the gold member it is fairly easy to get to meet some Jewish mates for you.

You can go here <a href=http://www.get-free-date.com>Jewish Dating Agency</a>
Thanks