module Sequel::Plugins::StringStripper

StringStripper is a plugin that strips all input strings when assigning to the model's values. Example:

album = Album.new(:name=>' A ')
album.name # => 'A'

SQL::Blob instances and all non-strings are not modified by this plugin. Additionally, strings passed to a blob column setter are also not modified. You can explicitly set other columns to skip the stripping:

Album.skip_string_stripping :foo
Album.new(:foo=>' A ').foo # => ' A '

Usage:

# Make all model subclass instances strip strings (called before loading subclasses)
Sequel::Model.plugin :string_stripper

# Make the Album class strip strings
Album.plugin :string_stripper

Public Class Methods

configure(model) click to toggle source

Set blob columns as skipping stripping when plugin is loaded.

# File lib/sequel/plugins/string_stripper.rb, line 26
def self.configure(model)
  model.instance_variable_set(:@skipped_string_stripping_columns, [])
  model.send(:set_skipped_string_stripping_columns)
end