Class: PushDeploy

Inherits:
Object
  • Object
show all
Defined in:
lib/pushdeploy.rb

Constant Summary collapse

EMPTY_DIR =
'4b825dc642cb6eb9a060e54bf8d69288fbee4904'

Instance Method Summary collapse

Constructor Details

#initialize(args, &block) ⇒ PushDeploy

Returns a new instance of PushDeploy.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pushdeploy.rb', line 5

def initialize(args, &block)       

  puts 'Running after_deploy...'
  puts "!!!"
  puts args                                                           
  
  @deploy_to, @oldrev, @newrev = args.shift, args.shift, args.shift || 'HEAD'          
  puts "deploy !! #{@deploy_to}"
  if @oldrev == '0000000000000000000000000000000000000000'
    @oldrev = EMPTY_DIR
  elsif @oldrev.nil?
    @oldrev = '@{-1}'
  end    
  
  instance_exec(&block)
                            
end

Instance Method Details

#bundleObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pushdeploy.rb', line 23

def bundle
  return if @oldrev == '0'

  return unless File.exist?('Gemfile')
  if %x{git diff --name-only #{@oldrev} #{@newrev}} =~ /^Gemfile|\.gemspec$/
    begin
      # If Bundler in turn spawns Git, it can get confused by $GIT_DIR
      git_dir = ENV.delete('GIT_DIR')
      run "bundle check"
      unless $?.success?
        puts "Bundling..."
        run "bundle | grep -v '^Using ' | grep -v ' is complete'"
      end
    ensure
      ENV['GIT_DIR'] = git_dir
    end
  end
end

#migrateObject



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/pushdeploy.rb', line 46

def migrate
  return if @oldrev == '0'  
  
  schema = %x{git diff --name-status #{@oldrev} #{@newrev} -- db/schema.rb}
  if schema =~ /^A/
    run "bundle exec rake db:create"
  end 
  
  if `git diff HEAD^`.index("db/migrate")
   puts "Migrating.."
   run 'bundle exec rake db:migrate RAILS_ENV="production"'
  end
end

#run(command) ⇒ Object



42
43
44
# File 'lib/pushdeploy.rb', line 42

def run(command)
  Kernel.system "#{command} >&1"
end