Skip to content

Instantly share code, notes, and snippets.

@cleytonmessias
Created January 21, 2014 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cleytonmessias/8546299 to your computer and use it in GitHub Desktop.
Save cleytonmessias/8546299 to your computer and use it in GitHub Desktop.
module Sanitizer
extend ActiveSupport::Concern
module ClassMethods
def sanitize(*args, opts)
target = opts[:on]
condition = opts[:if] || true
args.each do |column|
class_eval <<-RUBY
def #{column}=(value)
#{target}.send("#{column}=", Sanitize.clean(value)) if #{condition}.call
end
RUBY
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment