Module: Scrubby
- Defined in:
- lib/scrubby.rb
Overview
scrubby
cleans up incoming ActiveRecord model attributes by hijacking attribute setters and reformatting the attribute value before passing it along to be set as usual.
- Author
-
Steve Richert
- Copyright
-
Copyright © 2010 Steve Richert
- License
-
MIT License (www.opensource.org/licenses/mit-license.php)
To enable scrubbing on a model, simply use the scrub
method:
class User < ActiveRecord::Base
scrub :name
end
user = User.new(:name => " Steve Richert ")
user.name # => "Steve Richert"
noname = User.new(:name => " ")
noname.name # => nil
See the scrub
class method documentation for more details.
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Class Method Details
.included(base) ⇒ Object
:nodoc:
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/scrubby.rb', line 22 def self.included(base) #:nodoc: base.class_eval do class_inheritable_hash :scrubbers self.scrubbers = {} extend ClassMethods include InstanceMethods alias_method_chain :write_attribute, :scrub end end |