Class: Metaverse::Base
- Inherits:
-
Object
- Object
- Metaverse::Base
- Defined in:
- lib/metaverse/base.rb
Instance Method Summary collapse
- #branches ⇒ Object
- #checkConsistency ⇒ Object
- #checkDirtiness ⇒ Object
- #checkout(name) ⇒ Object
- #createFeature(name) ⇒ Object
- #createSnapshot(name) ⇒ Object
- #deploy(state = nil) ⇒ Object
- #diff(branch = nil) ⇒ Object
- #getBranches ⇒ Object
-
#initialize(path) ⇒ Base
constructor
A new instance of Base.
- #loadFeature(name) ⇒ Object
- #loadSnapshot(name) ⇒ Object
- #readConfig(path) ⇒ Object
- #repos ⇒ Object
- #status ⇒ Object
- #systemState ⇒ Object
- #update(remote) ⇒ Object
Constructor Details
#initialize(path) ⇒ Base
Returns a new instance of Base.
9 10 11 12 13 14 15 |
# File 'lib/metaverse/base.rb', line 9 def initialize path @logger = Logger.new STDOUT readConfig "#{path}/.meta.yml" @reposPaths = Metaverse::Iterator.new path, @ignoredRepos @reposPaths.build @repos = @reposPaths.map {|repo| Metaverse::Repo.new repo} end |
Instance Method Details
#branches ⇒ Object
80 81 82 |
# File 'lib/metaverse/base.rb', line 80 def branches @repos.each { |repo| puts "#{repo.name}@#{repo.currentBranch}" } end |
#checkConsistency ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/metaverse/base.rb', line 93 def checkConsistency currentBranch = systemState if currentBranch.last != @repos.length branchName = currentBranch.first inconsistentRepos = @repos.reject { |repo| repo.currentBranch == branchName }.map &:name puts 'The system is in an inconsistent state. Please check the following repos :'.red, inconsistentRepos return false end puts 'The system is consistent'.green true end |
#checkDirtiness ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/metaverse/base.rb', line 109 def checkDirtiness dirtyRepos = @repos.reject { |repo| !repo.dirty? }.map &:name if dirtyRepos.length == 0 puts 'The system is clean'.green else puts 'The system is dirty. Please check the following repos :'.red , dirtyRepos end dirtyRepos.length == 0 end |
#checkout(name) ⇒ Object
26 27 28 |
# File 'lib/metaverse/base.rb', line 26 def checkout name @repos.each { |repo| repo.checkout name } if checkConsistency && checkDirtiness end |
#createFeature(name) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/metaverse/base.rb', line 38 def createFeature name branchName = "feature/#{name}" @repos.each { |repo| repo.branch branchName repo.checkout branchName } if checkConsistency && checkDirtiness end |
#createSnapshot(name) ⇒ Object
30 31 32 |
# File 'lib/metaverse/base.rb', line 30 def createSnapshot name @repos.each { |repo| repo.tag name } if checkConsistency && checkDirtiness end |
#deploy(state = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/metaverse/base.rb', line 62 def deploy state = nil @repos.each { |repo| if state === nil state = repo.currentBranch end repo.checkout state repo.deploy state } if checkConsistency && checkDirtiness end |
#diff(branch = nil) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/metaverse/base.rb', line 72 def diff branch = nil if branch === nil branch = 'develop' end @repos.each { |repo| repo.countDiffBranches branch, repo.currentBranch} end |
#getBranches ⇒ Object
50 51 52 |
# File 'lib/metaverse/base.rb', line 50 def getBranches @repos.each { |repo| repo.branch } end |
#loadFeature(name) ⇒ Object
46 47 48 |
# File 'lib/metaverse/base.rb', line 46 def loadFeature name @repos.each { |repo| repo.checkout "feature/#{name}" } if checkConsistency && checkDirtiness end |
#loadSnapshot(name) ⇒ Object
34 35 36 |
# File 'lib/metaverse/base.rb', line 34 def loadSnapshot name @repos.each { |repo| repo.checkout "tags/#{name}" } if checkConsistency && checkDirtiness end |
#readConfig(path) ⇒ Object
122 123 124 125 126 127 |
# File 'lib/metaverse/base.rb', line 122 def readConfig path config = YAML.load File.open(path) @originRemote = config['remotes']['main'] @ownRemote = config['remotes']['own'] @ignoredRepos = config['ignore'] || [] end |
#repos ⇒ Object
22 23 24 |
# File 'lib/metaverse/base.rb', line 22 def repos @repos end |
#status ⇒ Object
17 18 19 20 |
# File 'lib/metaverse/base.rb', line 17 def status checkConsistency checkDirtiness end |
#systemState ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/metaverse/base.rb', line 84 def systemState branches = Hash.new 0 @repos.each {|repo| branches[repo.currentBranch] += 1} state = branches.max{|a,b| a[1] <=> b[1]} state[0] = state.first.strip state end |
#update(remote) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/metaverse/base.rb', line 54 def update remote @repos.each { |repo| puts "In repo #{repo.name}".blue repo.fetch "#{remote || @originRemote}" repo.reset "#{remote || @originRemote}/#{systemState[0]}" } if checkConsistency && checkDirtiness end |