Sha256: 3401d7d6bc024c0f38161b0702cdd91b9801680f8ece75c128c0f07932eba76a

Contents?: true

Size: 763 Bytes

Versions: 35

Compression:

Stored size: 763 Bytes

Contents

module Sequel
  module Plugins
    # StringStripper is a very simple plugin that strips all input strings
    # when assigning to the model's values. Example:
    #
    #   album = Album.new(:name=>' A ')
    #   album.name # => '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
    module StringStripper
      module InstanceMethods
        # Strip value if it is a string, before attempting to assign
        # it to the model's values.
        def []=(k, v)
          v.is_a?(String) ? super(k, v.strip) : super
        end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
sequel-3.42.0 lib/sequel/plugins/string_stripper.rb
sequel-3.41.0 lib/sequel/plugins/string_stripper.rb
sequel-3.40.0 lib/sequel/plugins/string_stripper.rb
sequel-3.39.0 lib/sequel/plugins/string_stripper.rb
sequel-3.38.0 lib/sequel/plugins/string_stripper.rb
sequel-3.37.0 lib/sequel/plugins/string_stripper.rb
sequel-3.36.1 lib/sequel/plugins/string_stripper.rb
sequel-3.36.0 lib/sequel/plugins/string_stripper.rb
sequel-3.35.0 lib/sequel/plugins/string_stripper.rb
sequel-3.34.1 lib/sequel/plugins/string_stripper.rb
sequel-3.34.0 lib/sequel/plugins/string_stripper.rb
sequel-3.33.0 lib/sequel/plugins/string_stripper.rb
sequel-3.32.0 lib/sequel/plugins/string_stripper.rb
sequel-3.31.0 lib/sequel/plugins/string_stripper.rb
sequel-3.30.0 lib/sequel/plugins/string_stripper.rb
sequel-3.29.0 lib/sequel/plugins/string_stripper.rb
sequel-3.28.0 lib/sequel/plugins/string_stripper.rb
sequel-3.27.0 lib/sequel/plugins/string_stripper.rb
sequel-3.26.0 lib/sequel/plugins/string_stripper.rb
sequel-3.25.0 lib/sequel/plugins/string_stripper.rb