class AppUp::Hooks::RailsUp
Constants
- BUNDLE_COMMAND
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/app_up/hooks/rails_up.rb, line 8 def initialize(*args) @commands = {} super(*args) end
Public Instance Methods
run()
click to toggle source
# File lib/app_up/hooks/rails_up.rb, line 13 def run shell.notify( "Running RailsUp\n----------") files.each do |file| exploded_path = Utils::Path.split(file) # allow rebundle on only Gemfile edit, in case you're # upping a gem, which probably doesn't have the Gemfile.lock # checked in if exploded_path.last.match(/Gemfile(\.lock)?|gemspec$/) add_command(:bundle, dir: exploded_path[0..-2]) end if exploded_path.include?("migrate") last_db_index = exploded_path.rindex("db") add_command(:migrate, dir: exploded_path[0...last_db_index]) end end enqueue_commands end
Private Instance Methods
add_command(action, dir:)
click to toggle source
# File lib/app_up/hooks/rails_up.rb, line 37 def add_command(action, dir:) @commands[dir] ||= [] @commands[dir] << action unless @commands[dir].include? action end
enqueue_commands()
click to toggle source
We need to ensure that bundle is run before migrate. So we group the commands by their root folder, and bundle first.
# File lib/app_up/hooks/rails_up.rb, line 45 def enqueue_commands if @commands.empty? shell.notify("Nothing to do") return end command_count = @commands.values.flatten.size.to_s i = 1 @commands.each do |dir, actions| migrate_block = Proc.new { ['test', 'development'].each do |env| shell.enqueue(:run, migrate(env), dir: dir) end } actions.each do |command| shell.enqueue(:notify, "#{i.to_s.rjust(command_count.length)}/#{command_count.to_s} #{command.to_s.ljust(7)} : #{Utils::Path.join(dir)}") i+=1 end if [:bundle, :migrate].all? { |c| actions.include?(c) } shell.enqueue(:run, BUNDLE_COMMAND, dir: dir, &migrate_block) elsif actions.include? :bundle shell.enqueue(:run, BUNDLE_COMMAND, dir: dir) elsif actions.include? :migrate migrate_block.call end end end
migrate(env)
click to toggle source
# File lib/app_up/hooks/rails_up.rb, line 75 def migrate(env) "RAILS_ENV=#{env} bundle exec rake #{options[:db_reset] ? 'db:drop' : ''} db:create 2> /dev/null;\n RAILS_ENV=#{env} bundle exec rake db:migrate" end