Class: Gitcopier::Integrator
- Inherits:
-
Object
- Object
- Gitcopier::Integrator
- Defined in:
- lib/gitcopier.rb
Instance Method Summary collapse
-
#changed_files ⇒ Object
This method get relative path of all changed files to git root.
- #commit_log ⇒ Object
- #copy(source, des) ⇒ Object
-
#initialize(integrate_path, root_path) ⇒ Integrator
constructor
A new instance of Integrator.
- #integrate_all_changes ⇒ Object
- #print_integration_info ⇒ Object
Constructor Details
#initialize(integrate_path, root_path) ⇒ Integrator
Returns a new instance of Integrator.
13 14 15 16 17 18 |
# File 'lib/gitcopier.rb', line 13 def initialize(integrate_path, root_path) @root_path = root_path @integrate_path = integrate_path @decisions = Decisions.new(@root_path, @integrate_path) @decisions.load end |
Instance Method Details
#changed_files ⇒ Object
This method get relative path of all changed files to git root
21 22 23 24 25 |
# File 'lib/gitcopier.rb', line 21 def changed_files commit_log.split("\n").select do |line| line.match(/[ACDMRTUXB*]+\t.+/) end.map(&:strip) end |
#commit_log ⇒ Object
27 28 29 |
# File 'lib/gitcopier.rb', line 27 def commit_log @commit_log ||= raw_git_commit_log end |
#copy(source, des) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gitcopier.rb', line 31 def copy(source, des) # source is a directory, copy its content # TODO: create destination if it doesnt exist if source.end_with? '/' puts "Copy #{(source + '*').colorize(:green)} to #{des.colorize(:green)}." FileUtils.mkdir_p(des) FileUtils.cp_r(Dir["#{source}*"], des) else # source is a file, copy it to destination puts "Copy #{source.colorize(:green)} to #{des.colorize(:green)}." FileUtils.cp_r(source, des) end end |
#integrate_all_changes ⇒ Object
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 |
# File 'lib/gitcopier.rb', line 58 def integrate_all_changes STDIN.reopen('/dev/tty') print_integration_info dir_tree = DirTree.new(@root_path, changed_files) dir_tree.travel do |changed_file| decision = @decisions.get(changed_file) just_decided = decision.nil? unless decision decision = @decisions.prompt_decision(changed_file) unless decision end if decision.is_copy? print "Follow previous decision: " unless just_decided copy(@root_path + decision.source, @integrate_path + decision.des) next true elsif decision.is_follow? next nil else next false end end ensure print "\nSaving decisions for later usage...".colorize(:green) @decisions.save puts "Done.".colorize(:green) end |
#print_integration_info ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gitcopier.rb', line 44 def print_integration_info puts "=====================================================" puts " Integrating changes to #{@integrate_path}".colorize(:yellow) puts "=====================================================" commit, , date = commit_log.split("\n")[0..2] _, h = commit.split(' ') print "Commit: ", h.colorize(:yellow) _, a = .split(': ') print "\nAuthor: ", a.colorize(:yellow) _, d = date.split(': ') print "\nDate: ", d.colorize(:yellow), "\n" puts "=====================================================" end |