Module: Sequel::Plugins::InputTransformer::ClassMethods

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#input_transformersObject (readonly)

Hash of input transformer name symbols to transformer callables.



42
43
44
# File 'lib/sequel/plugins/input_transformer.rb', line 42

def input_transformers
  @input_transformers
end

Instance Method Details

#add_input_transformer(transformer_name, &block) ⇒ Object

Add an input transformer to this model.

Raises:



52
53
54
55
56
# File 'lib/sequel/plugins/input_transformer.rb', line 52

def add_input_transformer(transformer_name, &block)
  raise(Error, 'must provide both transformer name and block when adding input transformer') unless transformer_name && block
  @input_transformers[transformer_name] = block
  @skip_input_transformer_columns[transformer_name] = []
end

#freezeObject

Freeze input transformers when freezing model class



59
60
61
62
63
64
# File 'lib/sequel/plugins/input_transformer.rb', line 59

def freeze
  @input_transformers.freeze
  @skip_input_transformer_columns.freeze.each_value(&:freeze)

  super
end

#input_transformer_orderObject

The order in which to call the input transformers. For backwards compatibility only.



45
46
47
# File 'lib/sequel/plugins/input_transformer.rb', line 45

def input_transformer_order
  input_transformers.keys.reverse
end

#skip_input_transformer(transformer_name, *columns) ⇒ Object

Set columns that the transformer should skip.



67
68
69
# File 'lib/sequel/plugins/input_transformer.rb', line 67

def skip_input_transformer(transformer_name, *columns)
  @skip_input_transformer_columns[transformer_name].concat(columns).uniq!
end

#skip_input_transformer?(transformer_name, column) ⇒ Boolean

Return true if the transformer should not be called for the given column.

Returns:

  • (Boolean)


72
73
74
# File 'lib/sequel/plugins/input_transformer.rb', line 72

def skip_input_transformer?(transformer_name, column)
  @skip_input_transformer_columns[transformer_name].include?(column)
end