Class: Stockboy::Translations::DefaultNil
- Inherits:
-
Stockboy::Translator
- Object
- Stockboy::Translator
- Stockboy::Translations::DefaultNil
- Defined in:
- lib/stockboy/translations/default_nil.rb
Overview
Translate missing values to nil
This is a useful fallback for empty values that should be cleared to nil.
Job template DSL
Registered as :or_nil
. Use with:
attributes do
product_code as: [->(r){raise "Invalid"}, :or_nil]
end
Instance Attribute Summary
Attributes inherited from Stockboy::Translator
Instance Method Summary collapse
Methods inherited from Stockboy::Translator
Constructor Details
This class inherits a constructor from Stockboy::Translator
Instance Method Details
#translate(context) ⇒ Object, NilClass
30 31 32 33 34 35 |
# File 'lib/stockboy/translations/default_nil.rb', line 30 def translate(context) value = field_value(context, field_key) return nil if (value).blank? return value end |