GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - richmolj/acts_as_filterable: filter attributes, in different ways...

BranchesTags
Open more actions menu

Latest commit

 

History

94 Commits
94 Commits

Folders and files

NameName
Last commit message
Last commit date
lib
lib
 
 
rails
rails
 
 
test
test
 
 
.document
.document
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.rdoc
README.rdoc
 
 
Rakefile
Rakefile
 
 
VERSION.yml
VERSION.yml
 
 
acts_as_filterable.gemspec
acts_as_filterable.gemspec
 
 
init.rb
init.rb
 
 
setup.rb
setup.rb
 
 

Repository files navigation

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 © 2010 Rob Ares. See LICENSE for details.

About

filter attributes, in different ways...

gemcutter.org/gems/acts_as_filterable

Resources

Readme
MIT license
Activity

Stars

1 star

Watchers

1 watching

Forks

1 fork
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.