Class: RailsPushAndMigrate::Base
- Inherits:
-
Object
- Object
- RailsPushAndMigrate::Base
- Defined in:
- lib/rails-push-and-migrate/base.rb
Instance Attribute Summary collapse
-
#branch ⇒ Object
Returns the value of attribute branch.
-
#remote ⇒ Object
Returns the value of attribute remote.
Instance Method Summary collapse
- #assets_changed? ⇒ Boolean
- #diff_files ⇒ Object
- #git_push_cmd ⇒ Object
- #has_migration? ⇒ Boolean
-
#initialize(remote, branch) ⇒ Base
constructor
A new instance of Base.
- #migrate_cmd ⇒ Object
- #print_and_execute(cmd) ⇒ Object
- #print_and_execute!(cmd) ⇒ Object
- #remote_branch ⇒ Object
- #run ⇒ Object
- #with_named_repo ⇒ Object
Constructor Details
#initialize(remote, branch) ⇒ Base
Returns a new instance of Base.
4 5 6 7 8 |
# File 'lib/rails-push-and-migrate/base.rb', line 4 def initialize(remote, branch) @branch = branch @remote = remote diff_files end |
Instance Attribute Details
#branch ⇒ Object
Returns the value of attribute branch.
3 4 5 |
# File 'lib/rails-push-and-migrate/base.rb', line 3 def branch @branch end |
#remote ⇒ Object
Returns the value of attribute remote.
3 4 5 |
# File 'lib/rails-push-and-migrate/base.rb', line 3 def remote @remote end |
Instance Method Details
#assets_changed? ⇒ Boolean
35 36 37 |
# 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 ⇒ Object
14 15 16 17 18 19 20 21 |
# 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 ⇒ Object
39 40 41 |
# File 'lib/rails-push-and-migrate/base.rb', line 39 def git_push_cmd "git push #{remote} #{branch}:#{remote_branch}" end |
#has_migration? ⇒ Boolean
31 32 33 |
# File 'lib/rails-push-and-migrate/base.rb', line 31 def has_migration? diff_files.include?("db/schema.rb") end |
#migrate_cmd ⇒ Object
43 44 45 |
# File 'lib/rails-push-and-migrate/base.rb', line 43 def migrate_cmd raise NotImplementedError end |
#print_and_execute(cmd) ⇒ Object
47 48 49 50 |
# File 'lib/rails-push-and-migrate/base.rb', line 47 def print_and_execute(cmd) puts "Executing #{cmd}" system cmd end |
#print_and_execute!(cmd) ⇒ Object
52 53 54 55 56 |
# File 'lib/rails-push-and-migrate/base.rb', line 52 def print_and_execute!(cmd) unless print_and_execute(cmd) raise "Failed to execute #{cmd}" end end |
#remote_branch ⇒ Object
10 11 12 |
# File 'lib/rails-push-and-migrate/base.rb', line 10 def remote_branch "master" end |
#run ⇒ Object
58 59 60 61 |
# 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 ⇒ Object
23 24 25 26 27 28 29 |
# 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 |