Skip to content

Commit

Permalink
A dash of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed Dec 21, 2012
1 parent 7d2e0dc commit acece26
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions lib/commands.rb
@@ -1,4 +1,5 @@
require 'rake'
require 'rails/generators'

class Commands
module ConsoleMethods
Expand All @@ -19,31 +20,28 @@ def initialize
end

def rake(task, *args)
ActiveRecord::Base.logger.silence do
Rake::Task[task].invoke(*args)
ActiveRecord::Base.logger.silence { Rake::Task[task].invoke(*args) }

# Rake by default only allows tasks to be run once per session
Rake.application.tasks.each(&:reenable)
end
# Rake by default only allows tasks to be run once per session
Rake.application.tasks.each(&:reenable)

nil
rescue SystemExit
# Swallow exit/abort calls as we'll never want to exit the IRB session
nil
end

# FIXME: Turn this into calls directly to the test classes, so we don't have to load environment again.
# Also need to toggle the environment to test and back to dev after running.
def test(what = nil)
ActiveRecord::Base.logger.silence do
case what
when NilClass, :all
rake "test:units"
when String
ENV['TEST'] = "test/#{what}_test.rb"
rake "test:single"
ENV['TEST'] = nil
end
case what
when NilClass, :all
rake "test:units"
when String
ENV['TEST'] = "test/#{what}_test.rb"
rake "test:single"
ENV['TEST'] = nil
end
nil
rescue SystemExit
nil
end

def generate(argv = nil)
Expand All @@ -63,7 +61,6 @@ def destroy(argv = nil)
def generator(name, argv = nil)
if argv.nil?
# FIXME: I don't know why we can't just catch SystemExit here, then we wouldn't need this if block
require 'rails/generators'
Rails::Generators.help name
else
ARGV.replace argv.nil? ? [nil] : argv.split(" ")
Expand Down

0 comments on commit acece26

Please sign in to comment.