Method: FastlaneCore::ConfigItem#auto_convert_value

Defined in:
fastlane_core/lib/fastlane_core/configuration/config_item.rb

#auto_convert_value(value) ⇒ Object

rubocop:disable Metrics/PerceivedComplexity Returns an updated value type (if necessary)



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'fastlane_core/lib/fastlane_core/configuration/config_item.rb', line 269

def auto_convert_value(value)
  return nil if value.nil?

  if data_type == Array
    return value.split(',') if value.kind_of?(String)
  elsif data_type == Integer
    return value.to_i if value.to_i.to_s == value.to_s
  elsif data_type == Float
    return value.to_f if value.to_f.to_s == value.to_s
  elsif data_type == Symbol
    return value.to_sym if value.to_sym.to_s == value.to_s
  elsif allow_shell_conversion
    return value.shelljoin if value.kind_of?(Array)
    return value.map { |k, v| "#{k.to_s.shellescape}=#{v.shellescape}" }.join(' ') if value.kind_of?(Hash)
  elsif data_type == Hash && value.kind_of?(String)
    begin
      parsed = JSON.parse(value)
      return parsed if parsed.kind_of?(Hash)
    rescue JSON::ParserError
    end
  elsif data_type != String
    # Special treatment if the user specified true, false, on, off or YES, NO
    # There is no boolean type, so we just do it here
    if %w(yes YES true TRUE on ON).include?(value)
      return true
    elsif %w(no NO false FALSE off OFF).include?(value)
      return false
    end
  end
  # rubocop:enable Metrics/PerceivedComplexity

  return value # fallback to not doing anything
end