module Sequel::Plugins::ForceEncoding

The force_encoding plugin allows you force specific encodings for all strings that are used by the model. When model instances are loaded from the database, all values in the hash that are strings are forced to the given encoding. Whenever you update a model column attribute, the resulting value is forced to a given encoding if the value is a string. There are two ways to specify the encoding. You can either do so in the plugin call itself, or via the forced_encoding class accessor.

Usage:

# Force all strings to be UTF-8 encoded in a all model subclasses
# (called before loading subclasses)
Sequel::Model.plugin :force_encoding, 'UTF-8'

# Force the encoding for the Album model to UTF-8
Album.plugin :force_encoding
Album.forced_encoding = 'UTF-8'