Module: Sequel::Plugins::InputTransformer

Defined in:
lib/sequel/plugins/input_transformer.rb

Overview

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

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.apply(model) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/sequel/plugins/input_transformer.rb', line 25

def self.apply(model, *)
  model.instance_eval do
    @input_transformers = {}
    @input_transformer_order = []
    @skip_input_transformer_columns = {}
  end
end

.configure(model, transformer_name = nil, &block) ⇒ Object

If an input transformer is given in the plugin call, add it as a transformer



35
36
37
# File 'lib/sequel/plugins/input_transformer.rb', line 35

def self.configure(model, transformer_name=nil, &block)
  model.add_input_transformer(transformer_name, &block) if transformer_name || block
end