acts_as_filterable is a plugin that was hacked together (originally a monkey patch) to avoid repeating the same text filtering logic that was re-implemented all over the place in a legacy domain model.
You might ask why we just didn’t convert the column value. That would be the right way to go but with tens of millions of rows and numerous legacy apps that expect the data to be a character string; the alternative seemed much more appealing for the time being :). So putting this in place would avoid the garbage data coming in moving forward and assure that the logic is implemented in a sane (and re-usable) way. Hopefully someone else can find a use for it as well…
-
filter_for_digits: leaves only numeric values
-
filter_for_uppercase: uppercase all alpha characters
-
filter_for_lowercase: lowercase all alpha characters
-
filter_for_whitespace: strips and non-essential whitespace out of a string (leaving only single whitespace characters).
Features I’d like to add in the future:
-
Additional macros that filter decimal values, etc.
-
Rails 1.2+ (up to rails-3.0.0.rc)
-
Tested on Ruby 1.8.6, 1.8.7, 1.9.1, 1.9.2
config.gem "acts_as_filterable"
gem "acts_as_filterable", "0.3.0"
gem install acts_as_filterable --source http://rubygems.org
ruby setup.rb install
class MyModel < ActiveRecord::Base filter_for_digits :phone_number, :fax_number end
in your config/initializers/acts_as_filterable.rb
ActsAsFilterable.configure do |config| config.add_filter :foo do |value| # code to modify and return value goes here end end
If something is broken or you need a feature; you know the deal. Don’t be part of the problem. Patches or pull requests are welcome.
Copyright © 2010 Rob Ares. See LICENSE for details.