Class: Pod::TemplateConfigurator
- Inherits:
-
Object
- Object
- Pod::TemplateConfigurator
- Defined in:
- lib/yk_command/project/setup/TemplateConfigurator.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#pod_name ⇒ Object
readonly
Returns the value of attribute pod_name.
-
#pods_for_podfile ⇒ Object
readonly
Returns the value of attribute pods_for_podfile.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#prefixes ⇒ Object
readonly
Returns the value of attribute prefixes.
-
#temp_path ⇒ Object
readonly
Returns the value of attribute temp_path.
-
#test_example_file ⇒ Object
readonly
Returns the value of attribute test_example_file.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #add_line_to_pch(line) ⇒ Object
- #add_pod_to_podfile(podname) ⇒ Object
- #add_pods_to_podfile ⇒ Object
- #add_yk_pods ⇒ Object
- #ask(question) ⇒ Object
- #ask_with_answers(question, possible_answers) ⇒ Object
- #clean_template_files ⇒ Object
- #customise_prefix ⇒ Object
- #date ⇒ Object
-
#ensure_carthage_compatibility ⇒ Object
—————————————-#.
- #github_user_name ⇒ Object
-
#initialize(pod_name, framework, prefix, author, temp_path, is_simple) ⇒ TemplateConfigurator
constructor
A new instance of TemplateConfigurator.
- #podfile_path ⇒ Object
- #reinitialize_git_repo ⇒ Object
- #rename_classes_folder ⇒ Object
- #rename_template_files ⇒ Object
- #replace_variables_in_files ⇒ Object
- #run ⇒ Object
- #run_pod_install ⇒ Object
- #set_test_framework(test_type, extension, folder) ⇒ Object
- #user_email ⇒ Object
-
#user_name ⇒ Object
—————————————-#.
- #validate_user_details ⇒ Object
- #year ⇒ Object
Constructor Details
#initialize(pod_name, framework, prefix, author, temp_path, is_simple) ⇒ TemplateConfigurator
Returns a new instance of TemplateConfigurator.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 14 def initialize(pod_name,framework,prefix,,temp_path,is_simple) @temp_path = temp_path @pod_name = pod_name @framework = framework @prefix = prefix @author = @is_simple = is_simple @pods_for_podfile = [] @prefixes = [] @message_bank = MessageBank.new(self) end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
12 13 14 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 12 def email @email end |
#pod_name ⇒ Object (readonly)
Returns the value of attribute pod_name.
12 13 14 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 12 def pod_name @pod_name end |
#pods_for_podfile ⇒ Object (readonly)
Returns the value of attribute pods_for_podfile.
12 13 14 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 12 def pods_for_podfile @pods_for_podfile end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
12 13 14 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 12 def prefix @prefix end |
#prefixes ⇒ Object (readonly)
Returns the value of attribute prefixes.
12 13 14 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 12 def prefixes @prefixes end |
#temp_path ⇒ Object (readonly)
Returns the value of attribute temp_path.
12 13 14 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 12 def temp_path @temp_path end |
#test_example_file ⇒ Object (readonly)
Returns the value of attribute test_example_file.
12 13 14 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 12 def test_example_file @test_example_file end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
12 13 14 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 12 def username @username end |
Instance Method Details
#add_line_to_pch(line) ⇒ Object
178 179 180 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 178 def add_line_to_pch line @prefixes << line end |
#add_pod_to_podfile(podname) ⇒ Object
164 165 166 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 164 def add_pod_to_podfile podname @pods_for_podfile << podname end |
#add_pods_to_podfile ⇒ Object
168 169 170 171 172 173 174 175 176 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 168 def add_pods_to_podfile podfile = File.read "#{$current_dir}/#{podfile_path}" podfile_content = @pods_for_podfile.map do |pod| "pod '" + pod + "'" end.join("\n ") podfile.gsub!("${INCLUDED_PODS}", podfile_content) File.open("#{$current_dir}/#{podfile_path}", "w") { |file| file.puts podfile } end |
#add_yk_pods ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 109 def add_yk_pods # self.add_pod_to_podfile "YKCategoryComponent" self.add_pod_to_podfile "YKModuleLifeCircleComponent" self.add_pod_to_podfile "YKRouterComponent" if @framework == "swift" # self.add_pod_to_podfile "SnapKit" self.add_pod_to_podfile "YKModuleServiceComponent.swift" else self.add_pod_to_podfile "YKModuleServiceComponent" end end |
#ask(question) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 26 def ask(question) answer = "" loop do puts "\n#{question}?" @message_bank.show_prompt answer = gets.chomp break if answer.length > 0 print "\nYou need to provide an answer." end answer end |
#ask_with_answers(question, possible_answers) ⇒ Object
41 42 43 44 45 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 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 41 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 "\nPossible answers are [" print_info.call end answer end |
#clean_template_files ⇒ Object
140 141 142 143 144 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 140 def clean_template_files ["./**/.gitkeep", "configure", "_CONFIGURE.rb", "README.md", "LICENSE", "templates", "setup", "CODE_OF_CONDUCT.md"].each do |asset| `rm -rf #{$current_dir}/#{asset}` end end |
#customise_prefix ⇒ Object
182 183 184 185 186 187 188 189 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 182 def customise_prefix prefix_path = "Example/Tests/Tests-Prefix.pch" return unless File.exists? prefix_path pch = File.read prefix_path pch.gsub!("${INCLUDED_PREFIXES}", @prefixes.join("\n ") ) File.open(prefix_path, "w") { |file| file.puts pch } end |
#date ⇒ Object
248 249 250 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 248 def date Time.now.strftime "%m/%d/%Y" end |
#ensure_carthage_compatibility ⇒ Object
—————————————-#
124 125 126 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 124 def ensure_carthage_compatibility # FileUtils.ln_s("#{$current_dir}/Example/Pods/Pods.xcodeproj", "#{$current_dir}/_Pods.xcodeproj") end |
#github_user_name ⇒ Object
234 235 236 237 238 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 234 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 |
#podfile_path ⇒ Object
252 253 254 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 252 def podfile_path 'Example/Podfile' end |
#reinitialize_git_repo ⇒ Object
211 212 213 214 215 216 217 218 219 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 211 def reinitialize_git_repo Dir.chdir("#{$current_dir}") do `rm -rf .git` `git init` `git add -A` end end |
#rename_classes_folder ⇒ Object
205 206 207 208 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 205 def rename_classes_folder # FileUtils.mv "#{@pod_name}/Pod", @pod_name FileUtils.mv "#{$current_dir}/Pod", "#{$current_dir}/#{@pod_name}" end |
#rename_template_files ⇒ Object
199 200 201 202 203 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 199 def rename_template_files FileUtils.mv "#{$current_dir}/POD_README.md", "#{$current_dir}/README.md" FileUtils.mv "#{$current_dir}/POD_LICENSE", "#{$current_dir}/LICENSE" FileUtils.mv "#{$current_dir}/NAME.podspec", "#{$current_dir}/#{pod_name}.podspec" end |
#replace_variables_in_files ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 146 def replace_variables_in_files # file_names = ['POD_LICENSE', 'POD_README.md', 'NAME.podspec', '.travis.yml', podfile_path] file_names = ['POD_LICENSE', 'POD_README.md', 'NAME.podspec', podfile_path] file_names.each do |file_name| # text = File.read(file_name) text = File.read("#{$current_dir}/#{file_name}") # text = File.read("./#{file_name}") text.gsub!("${POD_NAME}", @pod_name) text.gsub!("${REPO_NAME}", @pod_name.gsub('+', '-')) text.gsub!("${USER_NAME}", user_name) text.gsub!("${USER_EMAIL}", user_email) text.gsub!("${YEAR}", year) text.gsub!("${DATE}", date) # File.open(file_name, "w") { |file| file.puts text } File.open("#{$current_dir}/#{file_name}", "w") { |file| file.puts text } end end |
#run ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 80 def run # @message_bank.welcome_message if @framework == "swift" ConfigureSwift.perform(configurator: self) else ConfigureIOS.perform(configurator: self) end replace_variables_in_files clean_template_files rename_template_files if @is_simple != true add_yk_pods end add_pods_to_podfile customise_prefix rename_classes_folder ensure_carthage_compatibility reinitialize_git_repo run_pod_install # @message_bank.farewell_message end |
#run_pod_install ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 128 def run_pod_install puts "\nRunning " + "pod install".magenta + " on your new library." puts "" Dir.chdir("#{$current_dir}/Example") do # system "pod install" end # `git add #{$current_dir}/Example/#{pod_name}.xcodeproj/project.pbxproj` # `git commit -m "Initial commit"` end |
#set_test_framework(test_type, extension, folder) ⇒ Object
191 192 193 194 195 196 197 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 191 def set_test_framework(test_type, extension, folder) content_path = "setup/test_examples/" + test_type + "." + extension tests_path = "templates/" + folder + "/Example/Tests/Tests." + extension tests = File.read tests_path tests.gsub!("${TEST_EXAMPLE}", File.read(content_path) ) File.open(tests_path, "w") { |file| file.puts tests } end |
#user_email ⇒ Object
240 241 242 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 240 def user_email (ENV['GIT_COMMITTER_EMAIL'] || `git config user.email`).strip end |
#user_name ⇒ Object
—————————————-#
227 228 229 230 231 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 227 def user_name # (ENV['GIT_COMMITTER_NAME'] || github_user_name || `git config user.name` || `<GITHUB_USERNAME>` ).strip (ENV['GIT_COMMITTER_NAME'] || `git config user.name` || `<GITHUB_USERNAME>` ).strip end |
#validate_user_details ⇒ Object
221 222 223 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 221 def validate_user_details return (user_email.length > 0) && (user_name.length > 0) end |
#year ⇒ Object
244 245 246 |
# File 'lib/yk_command/project/setup/TemplateConfigurator.rb', line 244 def year Time.now.year.to_s end |