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_name, #param_default_values, #param_descriptions, #param_names, #param_optionality_values, #param_type_overrides, #reserved_words, #return_type

Instance Method Summary collapse

Methods inherited from SwiftFunction

#build_argument_list, #camel_case_lower, #determine_type_from_override, #get_type, #implementation, #initialize, #override_default_value_if_not_correct_type, #return_declaration, #return_statement, #sanitize_reserved_word, #swift_code, #swift_type_for_return_type

Constructor Details

This class inherits a constructor from Fastlane::SwiftFunction

Instance Method Details

#class_nameObject


238
239
240
241
# File 'fastlane/lib/fastlane/swift_fastlane_function.rb', line 238

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

#parametersObject


302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'fastlane/lib/fastlane/swift_fastlane_function.rb', line 302

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|
    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

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

  return param_names_and_types
end

#protocol_nameObject


233
234
235
236
# File 'fastlane/lib/fastlane/swift_fastlane_function.rb', line 233

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

#swift_default_implementationsObject


259
260
261
262
263
264
265
266
267
268
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
# File 'fastlane/lib/fastlane/swift_fastlane_function.rb', line 259

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
      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

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

  return swift_implementations
end

#swift_varsObject


243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'fastlane/lib/fastlane/swift_fastlane_function.rb', line 243

def swift_vars
  unless @param_names
    return []
  end
  swift_vars = @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)
    static_var_for_parameter_name = param
    "  var #{static_var_for_parameter_name}: #{type} { get }"
  end

  return swift_vars
end