Class: IOS::TemplateConfigurator

Inherits:
Object
  • Object
show all
Defined in:
lib/ios/module/setup/Template_Configurator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTemplateConfigurator

Returns a new instance of TemplateConfigurator.



13
14
15
16
17
18
19
20
21
22
# File 'lib/ios/module/setup/Template_Configurator.rb', line 13

def initialize()
  @pod_name = ""
  @project_filename = "Shell.xcworkspace"
  @pods_for_podfile = []
  @prefixes = []
  dir = App.gem_path
  @template_path = File.join(dir, "lib/ios/module/templates")
  @message_bank = MessageBank.new(self)
	  @tuist_commands = TuistCommands.new
end

Instance Attribute Details

#pod_nameObject (readonly)

Returns the value of attribute pod_name.



11
12
13
# File 'lib/ios/module/setup/Template_Configurator.rb', line 11

def pod_name
  @pod_name
end

#pods_for_podfileObject (readonly)

Returns the value of attribute pods_for_podfile.



11
12
13
# File 'lib/ios/module/setup/Template_Configurator.rb', line 11

def pods_for_podfile
  @pods_for_podfile
end

#prefixesObject (readonly)

Returns the value of attribute prefixes.



11
12
13
# File 'lib/ios/module/setup/Template_Configurator.rb', line 11

def prefixes
  @prefixes
end

#project_filenameObject (readonly)

Returns the value of attribute project_filename.



11
12
13
# File 'lib/ios/module/setup/Template_Configurator.rb', line 11

def project_filename
  @project_filename
end

#template_pathObject (readonly)

Returns the value of attribute template_path.



11
12
13
# File 'lib/ios/module/setup/Template_Configurator.rb', line 11

def template_path
  @template_path
end

#tuist_commandsObject (readonly)

Returns the value of attribute tuist_commands.



11
12
13
# File 'lib/ios/module/setup/Template_Configurator.rb', line 11

def tuist_commands
  @tuist_commands
end

Instance Method Details

#ask(question) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ios/module/setup/Template_Configurator.rb', line 33

def ask(question)
  answer = ""
  loop do
    puts "\n#{question}"

    @message_bank.show_prompt
    answer = STDIN.gets.chomp

    break if answer.length > 0

    print "\nInforme uma resposta"
  end
  answer
end

#ask_with_answers(question, possible_answers) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ios/module/setup/Template_Configurator.rb', line 48

def ask_with_answers(question, possible_answers)
  print "\n#{question}? ["

  print_info = Proc.new {
    possible_answers_string = possible_answers.each_with_index do |answer, i|
      _answer = (i == 0) ? answer.underlined : answer
      print " " + _answer
      print(" /") if i != possible_answers.length - 1
    end
    print " ]\n"
  }
  print_info.call

  answer = ""

  loop do
    @message_bank.show_prompt
    answer = STDIN.gets.downcase.chomp

    answer = "yes" if answer == "y"
    answer = "no" if answer == "n"

    # default to first answer
    if answer == ""
      answer = possible_answers[0].downcase
      print answer.yellow
    end

    break if possible_answers.map { |a| a.downcase }.include? answer

    print "\nRespostas possíveis ["
    print_info.call
  end

  answer
end

#github_user_nameObject



104
105
106
107
108
# File 'lib/ios/module/setup/Template_Configurator.rb', line 104

def github_user_name
  github_user_name = `security find-internet-password -s github.com | grep acct | sed 's/"acct"<blob>="//g' | sed 's/"//g'`.strip
  is_valid = github_user_name.empty? or github_user_name.include? '@'
  return is_valid ? nil : github_user_name
end

#printDoneObject



29
30
31
# File 'lib/ios/module/setup/Template_Configurator.rb', line 29

def printDone
  puts "\n✅ " + "DONE".green
end

#printMessage(message) ⇒ Object



24
25
26
27
# File 'lib/ios/module/setup/Template_Configurator.rb', line 24

def printMessage(message)
  puts ""
  puts "==> " + message
end

#runObject



85
86
87
88
89
90
91
92
93
94
# File 'lib/ios/module/setup/Template_Configurator.rb', line 85

def run
  raise "Para rodar a rotina, você deve estar na raiz do projeto" if not File.exist?(@project_filename)

  @pod_name = ask("Qual o nome do módulo?")
  ConfigureSwift.perform(configurator: self)

  run_swiftgen
  run_tuist_generate
  @message_bank.done_message
end

#run_swiftgenObject



119
120
121
122
123
124
125
# File 'lib/ios/module/setup/Template_Configurator.rb', line 119

def run_swiftgen
  if File.exist? "swiftgen.yml"
    printMessage("Rodando " + "swiftgen".magenta + " no módulo")
    @message_bank.run_command "swiftgen"
    printDone
  end
end

#run_tuist_generateObject



110
111
112
113
114
115
116
117
# File 'lib/ios/module/setup/Template_Configurator.rb', line 110

def run_tuist_generate
  if Dir.exist? "Example"
    Dir.chdir "Example" do
      @tuist_commands.generateExample(false)
      printDone
    end
  end
end

#user_emailObject



100
101
102
# File 'lib/ios/module/setup/Template_Configurator.rb', line 100

def user_email
  (ENV['GIT_COMMITTER_EMAIL'] || `git config user.email`).strip
end

#user_nameObject



96
97
98
# File 'lib/ios/module/setup/Template_Configurator.rb', line 96

def user_name
  (ENV['GIT_COMMITTER_NAME'] || github_user_name || `git config user.name` || `<GITHUB_USERNAME>`).strip
end