Module: Sequel::Plugins::InputTransformer::ClassMethods
- Defined in:
- lib/sequel/plugins/input_transformer.rb
Instance Attribute Summary collapse
-
#input_transformers ⇒ Object
readonly
Hash of input transformer name symbols to transformer callables.
Instance Method Summary collapse
-
#add_input_transformer(transformer_name, &block) ⇒ Object
Add an input transformer to this model.
-
#freeze ⇒ Object
Freeze input transformers when freezing model class.
-
#input_transformer_order ⇒ Object
The order in which to call the input transformers.
-
#skip_input_transformer(transformer_name, *columns) ⇒ Object
Set columns that the transformer should skip.
-
#skip_input_transformer?(transformer_name, column) ⇒ Boolean
Return true if the transformer should not be called for the given column.
Instance Attribute Details
#input_transformers ⇒ Object (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.
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 |
#freeze ⇒ Object
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_order ⇒ Object
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.
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 |