Home > acts_as_filterable

acts_as_filterable

Acts_as_filterable is a project mainly written in Ruby, based on the MIT license.

filter attributes, in different ways...

= acts_as_filterable

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.

== Background

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...

== Default filters in place:

  • 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.

= Runtime Dependencies

  • 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

= Install

== Rails 2.3

config.gem "acts_as_filterable"

== Rails 3 / Bundler

gem "acts_as_filterable", "0.3.0"

== RubyGems

gem install acts_as_filterable --source http://rubygems.org

== Regular Library install

ruby setup.rb install

= Usage

class MyModel < ActiveRecord::Base filter_for_digits :phone_number, :fax_number end

== Custom Filters

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

= Contributing

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

Copyright (c) 2010 Rob Ares. See LICENSE for details.

Previous:Trot