| Module | Sequel::Plugins::InputTransformer |
| In: |
lib/sequel/plugins/input_transformer.rb
|
InputTransformer is a plugin that allows generic transformations of input values in model column setters. Example:
Album.plugin :input_transformer
Album.add_input_transformer(:reverser){|v| v.is_a?(String) ? v.reverse : v}
album = Album.new(name: 'foo')
album.name # => 'oof'
You can specifically set some columns to skip some input input transformers:
Album.skip_input_transformer(:reverser, :foo) Album.new(foo: 'bar').foo # => 'bar'
Usage:
# Make all model subclass instances support input transformers (called before loading subclasses) Sequel::Model.plugin :input_transformer # Make the Album class support input transformers Album.plugin :input_transformer
# File lib/sequel/plugins/input_transformer.rb, line 27
27: def self.apply(model, *)
28: model.instance_exec do
29: @input_transformers = {}
30: @skip_input_transformer_columns = {}
31: end
32: end