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.



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

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

Instance Attribute Details

#pod_nameObject (readonly)

Returns the value of attribute pod_name.



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

def pod_name
  @pod_name
end

#pods_for_podfileObject (readonly)

Returns the value of attribute pods_for_podfile.



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

def pods_for_podfile
  @pods_for_podfile
end

#prefixesObject (readonly)

Returns the value of attribute prefixes.



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

def prefixes
  @prefixes
end

#project_filenameObject (readonly)

Returns the value of attribute project_filename.



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

def project_filename
  @project_filename
end

#template_pathObject (readonly)

Returns the value of attribute template_path.



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

def template_path
  @template_path
end

Instance Method Details

#ask(question) ⇒ Object



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

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



46
47
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
# File 'lib/ios/module/setup/Template_Configurator.rb', line 46

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



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

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



27
28
29
# File 'lib/ios/module/setup/Template_Configurator.rb', line 27

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

#printMessage(message) ⇒ Object



22
23
24
25
# File 'lib/ios/module/setup/Template_Configurator.rb', line 22

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

#runObject



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

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

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

  run_swiftgen
  run_pod_install

  @message_bank.done_message
end

#run_pod_installObject



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

def run_pod_install
  if Dir.exists? "Example"
    Dir.chdir "Example" do
      printMessage("Rodando " + "pod install".magenta + " no projeto Exemplo")
      @message_bank.run_command "pod install"
      printDone
    end
  end
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.exists? "swiftgen.yml"
    printMessage("Rodando " + "swiftgen".magenta + " no módulo")
    @message_bank.run_command "swiftgen"
    printDone
  end
end

#user_emailObject



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

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

#user_nameObject



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

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