lib/sanitizable/macro.rb
# Defines one or multiple columns that should be sanitized. The method used
# for sanitizing can be defined via the :with key and can either contain the name
# of any method that is implemented on the particular class or a custom Proc.
# Additionally, an Array of Symbols or Procs can be speficied. Alternatively a block
# can be supplied as sanitizer.
#
# -----
#
# === Example:
#   class User < ActiveRecord::Base   
#     sanitizes :first_name, :last_name, with: :strip
#     sanitizes :email, with: [:strip, :downcase]
#     sanitizes :biography, with: ->(biography) { biography.squish }
#     sanitizes :username do |username|
#       # strip leading "@" characters as used in Twitter usernames
#       username.strip.downcase.sub(/\A@/, '')
#     end
#   end
Defines one or multiple columns that should be sanitized. The method used
for sanitizing can be defined via the :with key and can either contain the name
of any method that is implemented on the particular class or a custom Proc.
Additionally, an Array of Symbols or Procs can be speficied. Alternatively a block
can be supplied as sanitizer.




Defines one or multiple columns that should be sanitized . The method used for sanitizing can be defined via the : with key and can either contain the name of any method that is implemented on the particular class or a custom Proc . Additionally an Array of Symbols or Procs can be speficied . Alternatively a block can be supplied as sanitizer .
def sanitizes(*attribute_names, &block)  
      include Model unless self.include?(Model)
      options = attribute_names.extract_options!.assert_valid_keys(:with, :on)
      options[:with] = block || options[:with]
      raise ArgumentError, "#{self.name}#sanitizes must define a :with option or have a block" unless options[:with]
      raise ArgumentError, "#{self.name}#sanitizes must define at least one attribute" if attribute_names.empty?
      self.sanitizable_attributes += attribute_names.map do |attribute_name|
        AttributeSanitizer.new(attribute_name.to_s, options.dup)
      end
      self.sanitizable_attributes.uniq!
    end
def sanitizes ( * attribute_names , & block ) include Model unless self . include? ( Model ) options = attribute_names . extract_options! . assert_valid_keys ( :with , :on ) options [ :with ] = block || options [ :with ] raise ArgumentError , "#{self.name}#sanitizes must define a :with option or have a block" unless options [ :with ] raise ArgumentError , "#{self.name}#sanitizes must define at least one attribute" if attribute_names . empty? self . sanitizable_attributes += attribute_names . map do | attribute_name | AttributeSanitizer . new ( attribute_name . to_s , options . dup ) end self . sanitizable_attributes . uniq! end
Defines one or multiple columns that should be sanitized.
Defines one or multiple columns that should be sanitized .
attribute_names
<not_specific>
block
<not_specific>