class ElectricMonk::Project

Attributes

failures[R]
name[R]
origin[R]
root[R]

Public Class Methods

new(root:, name:, origin:) click to toggle source
# File lib/electric_monk.rb, line 73
def initialize(root:, name:, origin:)
  @root = root
  @name = name
  @origin = origin
end

Public Instance Methods

clone_project() click to toggle source
# File lib/electric_monk.rb, line 93
def clone_project
  execute("git clone #{origin} #{name}", chdir: root)
end
exists?() click to toggle source
# File lib/electric_monk.rb, line 89
def exists?
  File.exist?(path)
end
valid?() click to toggle source
# File lib/electric_monk.rb, line 79
def valid?
  if remote_correct?
    if dirty_files? || unpushed_commits?
      @failures = "#{name}: #{dirty_files} dirty files and #{unpushed_commits} unpushed commits"
    end
  else
    @failures = "#{name}: Wrong remote '#{current_remote}'"
  end
end

Private Instance Methods

current_remote() click to toggle source
# File lib/electric_monk.rb, line 115
def current_remote
  execute("git remote get-url origin", chdir: path)
end
dirty_files() click to toggle source
# File lib/electric_monk.rb, line 103
def dirty_files
  execute("git status --short", chdir: path).lines.length
end
dirty_files?() click to toggle source
# File lib/electric_monk.rb, line 99
def dirty_files?
  dirty_files > 0
end
execute(cmd, chdir:) click to toggle source
# File lib/electric_monk.rb, line 127
def execute(cmd, chdir:)
  Open3.capture2e(cmd, chdir: chdir).first.strip
end
path() click to toggle source
# File lib/electric_monk.rb, line 123
def path
  File.join(root, name)
end
remote_correct?() click to toggle source
# File lib/electric_monk.rb, line 119
def remote_correct?
  origin == current_remote
end
unpushed_commits() click to toggle source
# File lib/electric_monk.rb, line 111
def unpushed_commits
  execute("git log --oneline --branches --not --remotes", chdir: path).lines.length
end
unpushed_commits?() click to toggle source
# File lib/electric_monk.rb, line 107
def unpushed_commits?
  unpushed_commits > 0
end