Class: Fastlane::ToolSwiftFunction

Inherits:
SwiftFunction show all
Defined in:
fastlane/lib/fastlane/swift_fastlane_function.rb

Instance Attribute Summary

Attributes inherited from SwiftFunction

#default_values_to_ignore, #function_description, #function_details, #function_name, #param_default_values, #param_descriptions, #param_is_strings, #param_names, #param_optionality_values, #param_type_overrides, #reserved_words, #return_type, #return_value, #sample_return_value

Instance Method Summary collapse

Methods inherited from SwiftFunction

#build_argument_list, #camel_case_lower, #determine_type_from_override, #fix_documentation_indentation, #get_type, #implementation, #initialize, #non_empty, #override_default_value_if_not_correct_type, #return_declaration, #return_statement, #sanitize_reserved_word, #swift_code, #swift_documentation, #swift_parameter_documentation, #swift_return_value_documentation, #swift_type_for_return_type

Constructor Details

This class inherits a constructor from Fastlane::SwiftFunction

Instance Method Details

#class_nameObject


306
307
308
309
# File 'fastlane/lib/fastlane/swift_fastlane_function.rb', line 306

def class_name
  function_name = camel_case_lower(string: self.function_name)
  return function_name.capitalize + "file"
end

#parametersObject


384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'fastlane/lib/fastlane/swift_fastlane_function.rb', line 384

def parameters
  unless @param_names
    return ""
  end

  param_names_and_types = @param_names.zip(param_default_values, param_optionality_values, param_type_overrides).map do |param, default_value, optional, param_type_override, is_string|
    type = get_type(param: param, default_value: default_value, optional: optional, param_type_override: param_type_override, is_string: is_string)

    param = camel_case_lower(string: param)
    param = sanitize_reserved_word(word: param)
    static_var_for_parameter_name = param

    "#{param}: #{type} = #{self.class_name.downcase}.#{static_var_for_parameter_name}"
  end

  return param_names_and_types
end

#protocol_nameObject


301
302
303
304
# File 'fastlane/lib/fastlane/swift_fastlane_function.rb', line 301

def protocol_name
  function_name = camel_case_lower(string: self.function_name)
  return function_name.capitalize + "fileProtocol"
end

#swift_default_implementationsObject


333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'fastlane/lib/fastlane/swift_fastlane_function.rb', line 333

def swift_default_implementations
  unless @param_names
    return []
  end

  swift_implementations = @param_names.zip(param_default_values, param_optionality_values, param_type_overrides).map do |param, default_value, optional, param_type_override|
    type = get_type(param: param, default_value: default_value, optional: optional, param_type_override: param_type_override)
    param = camel_case_lower(string: param)
    param = sanitize_reserved_word(word: param)
    var_for_parameter_name = param

    unless default_value.nil?
      if type == "Bool" || type == "[String]" || type == "Int" || default_value.kind_of?(Array)
        default_value = default_value.to_s
      elsif default_value.kind_of?(Hash)
        # we can't handle default values for Hashes, yet
        # see method parameters for similar behavior
        default_value = "[:]"
      else
        default_value = "\"#{default_value}\""
      end
    end

    # if we don't have a default value, but the param is options, just set a default value to nil
    if optional && default_value.nil?
      default_value = "nil"
    end

    # if we don't have a default value still, we need to assign them based on type
    if type == "String"
      default_value ||= "\"\""
    end

    if type == "Bool"
      default_value ||= "false"
    end

    if type == "[String]"
      default_value ||= "[]"
    end

    if type == "[String : Any]"
      default_value ||= "[:]"
    end

    "  var #{var_for_parameter_name}: #{type} { return #{default_value} }"
  end

  return swift_implementations
end

#swift_varsObject


311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'fastlane/lib/fastlane/swift_fastlane_function.rb', line 311

def swift_vars
  unless @param_names
    return []
  end
  swift_vars = @param_names.zip(param_default_values, param_optionality_values, param_type_overrides, param_descriptions).map do |param, default_value, optional, param_type_override, param_description|
    type = get_type(param: param, default_value: default_value, optional: optional, param_type_override: param_type_override)

    param = camel_case_lower(string: param)
    param = sanitize_reserved_word(word: param)
    static_var_for_parameter_name = param

    if param_description
      documentation = "  /// #{param_description}\n"
    end

    "\n#{documentation}"\
    "  var #{static_var_for_parameter_name}: #{type} { get }"
  end

  return swift_vars
end