Class: BigKeeper::PodfileOperator
- Inherits:
-
Object
- Object
- BigKeeper::PodfileOperator
- Defined in:
- lib/big_keeper/util/podfile_operator.rb
Overview
Operator for podfile
Instance Method Summary collapse
- #find_and_replace(podfile, module_name, module_type, source) ⇒ Object
- #has(podfile, module_name) ⇒ Object
- #modules_with_type(podfile, modules, type) ⇒ Object
- #replace_all_module_release(podfile, module_names, version, source) ⇒ Object
Instance Method Details
#find_and_replace(podfile, module_name, module_type, source) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/big_keeper/util/podfile_operator.rb', line 34 def find_and_replace(podfile, module_name, module_type, source) temp_file = Tempfile.new('.Podfile.tmp') begin File.open(podfile, 'r') do |file| file.each_line do |line| if line.include?module_name temp_file.puts generate_module_config(module_name, module_type, source) else temp_file.puts line end end end temp_file.close FileUtils.mv(temp_file.path, podfile) ensure temp_file.close temp_file.unlink end end |
#has(podfile, module_name) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/big_keeper/util/podfile_operator.rb', line 8 def has(podfile, module_name) File.open(podfile, 'r') do |file| file.each_line do |line| if line.include?module_name return true end end end false end |
#modules_with_type(podfile, modules, type) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/big_keeper/util/podfile_operator.rb', line 19 def modules_with_type(podfile, modules, type) matched_modules = [] File.open(podfile, 'r') do |file| file.each_line do |line| modules.each do |module_name| if line =~ /pod\s*'#{module_name}',#{ModuleType.regex(type)}/ matched_modules << module_name break end end end end matched_modules end |
#replace_all_module_release(podfile, module_names, version, source) ⇒ Object
77 78 79 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/big_keeper/util/podfile_operator.rb', line 77 def replace_all_module_release(podfile, module_names, version, source) module_names.each do |module_name| PodfileOperator.new.find_and_replace(podfile, module_name, ModuleType::GIT, source) end # temp_file = Tempfile.new('.Podfile.tmp') # begin # File.open(podfile, 'r') do |file| # file.each_line do |line| # module_names.each do |module_name| # if line.include?module_name # temp_file.puts generate_module_config(module_name, ModuleType::GIT, source) # else # # temp_file.puts line # end # end # end # end # temp_file.close # FileUtils.mv(temp_file.path, podfile) # ensure # temp_file.close # temp_file.unlink # end end |