class RailsPushAndMigrate::Base

Attributes

branch[RW]
remote[RW]

Public Class Methods

new(remote, branch) click to toggle source
# File lib/rails-push-and-migrate/base.rb, line 4
def initialize(remote, branch)
  @branch = branch
  @remote = remote
  diff_files
end

Public Instance Methods

assets_changed?() click to toggle source
# File lib/rails-push-and-migrate/base.rb, line 35
def assets_changed?
  diff_files.select {|f| f.include? "app/assets"}.any?
end
diff_files() click to toggle source
# File lib/rails-push-and-migrate/base.rb, line 14
def diff_files
  @diff_files ||= (
    with_named_repo do |repo_name|
      puts "Execute git diff #{repo_name}/#{remote_branch}..#{branch} --name-only"
      `git diff #{repo_name}/#{remote_branch}..#{branch} --name-only`.split("\n")
    end
  )
end
git_push_cmd() click to toggle source
# File lib/rails-push-and-migrate/base.rb, line 39
def git_push_cmd
  "git push #{remote} #{branch}:#{remote_branch}"
end
has_migration?() click to toggle source
# File lib/rails-push-and-migrate/base.rb, line 31
def has_migration?
  diff_files.include?("db/schema.rb")
end
migrate_cmd() click to toggle source
# File lib/rails-push-and-migrate/base.rb, line 43
def migrate_cmd
  raise NotImplementedError
end
print_and_execute(cmd) click to toggle source
print_and_execute!(cmd) click to toggle source
remote_branch() click to toggle source
# File lib/rails-push-and-migrate/base.rb, line 10
def remote_branch
  "master"
end
run() click to toggle source
# File lib/rails-push-and-migrate/base.rb, line 58
def run
  print_and_execute! git_push_cmd
  print_and_execute!(migrate_cmd) if has_migration?
end
with_named_repo() { |"auto-push-repo"| ... } click to toggle source
# File lib/rails-push-and-migrate/base.rb, line 23
def with_named_repo
  system "git remote add auto-push-repo #{remote}"
  system "git remote update auto-push-repo"
  result = yield "auto-push-repo"
  system "git remote rm auto-push-repo"
  result
end