Module: KeyType::ClassMethods

Defined in:
app/models/concerns/key_type.rb

Instance Method Summary collapse

Instance Method Details

#format_value_before_type_cast(val, key_type) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/concerns/key_type.rb', line 12

def format_value_before_type_cast(val, key_type)
  return val if val.nil? || val.contains_erb?
  if key_type.present?
    case key_type.to_sym
      when :json, :array
        val = JSON.dump(val)
      when :yaml, :hash
        val = YAML.dump val
        val.sub!(/\A---\s*$\n/, '')
    end
  end
  val
end