Module: Sequel::Plugins::Sanitize
- Defined in:
- lib/sequel_sanitize.rb,
lib/sequel_sanitize/version.rb
Overview
The Sanitize plugin basically does a ‘before_filter’ on specified fields, if no sanitizer is specified the default one is used
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Constant Summary collapse
- VERSION =
'0.0.2'.freeze
Class Method Summary collapse
-
.configure(model, opts = {}) ⇒ Object
Plugin configuration.
Class Method Details
.configure(model, opts = {}) ⇒ Object
Plugin configuration
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sequel_sanitize.rb', line 9 def self.configure(model, opts={}) model. = opts model..freeze model.class_eval do [:fields].each do |f| define_method("#{f}=") do |value| sanitizer = self.class.[:field_sanitize][f] do_downcase = self.class.[:field_downcase][f] sanitized = sanitizer.call(value) if sanitizer.respond_to?(:call) sanitized ||= self.send(sanitizer, value) if sanitizer sanitized = sanitized.downcase if do_downcase and sanitized.respond_to?(:downcase) super(sanitized) end end end end |