Class: Stockboy::Translations::DefaultTrue

Inherits:
Stockboy::Translator show all
Defined in:
lib/stockboy/translations/default_true.rb

Overview

Translate missing values to boolean true

This is a useful fallback for translation errors from boolean fields.

Job template DSL

Registered as :or_true. Use with:

attributes do
  active as: [:boolean, :or_true]
end

Examples:

bool = Stockboy::Translator::Boolean.new

record.active = nil
bool.translate(record, :active) # => true

record.active = false
bool.translate(record, :active) # => false

record.active = true
bool.translate(record, :active) # => true

Instance Attribute Summary

Attributes inherited from Stockboy::Translator

#field_key

Instance Method Summary collapse

Methods inherited from Stockboy::Translator

#call, #initialize, #inspect

Constructor Details

This class inherits a constructor from Stockboy::Translator

Instance Method Details

#translate(context) ⇒ Boolean

Returns:



33
34
35
36
37
38
# File 'lib/stockboy/translations/default_true.rb', line 33

def translate(context)
  value = field_value(context, field_key)

  return true if value.nil?
  return value
end