commands 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +3 -3
  2. data/commands.gemspec +1 -1
  3. data/lib/commands.rb +25 -20
  4. metadata +2 -2
data/README.md CHANGED
@@ -20,9 +20,9 @@ Usage
20
20
 
21
21
  When your console boots, it'll automatically have a `commands` object instantiated (aliased to `c`). The following methods are delegated to this object: rake, test, generate, destroy, update. It's used like this:
22
22
 
23
- > generate "scaffold post title:string"
24
- > rake "db:migrate"
25
- > test "models/person"
23
+ > generate "scaffold post title:string"
24
+ > rake "db:migrate"
25
+ > test "models/person"
26
26
 
27
27
 
28
28
  Work needed
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'commands'
3
- s.version = '0.0.1'
3
+ s.version = '0.0.2'
4
4
  s.author = 'David Heinemeier Hansson'
5
5
  s.email = 'david@37signals.com'
6
6
  s.summary = 'Run Rake/Rails commands through the console'
@@ -1,4 +1,5 @@
1
1
  require 'rake'
2
+ require 'rails/generators'
2
3
 
3
4
  class Commands
4
5
  module ConsoleMethods
@@ -6,8 +7,6 @@ class Commands
6
7
  @commands ||= Commands.new
7
8
  end
8
9
 
9
- alias_method :c, :commands
10
-
11
10
  delegate :rake, :test, :generate, :destroy, :update, to: :commands
12
11
  end
13
12
 
@@ -15,34 +14,32 @@ class Commands
15
14
 
16
15
  def initialize
17
16
  load Rails.root.join('Rakefile')
17
+ Rails.application.load_generators
18
18
  end
19
19
 
20
20
  def rake(task, *args)
21
- ActiveRecord::Base.logger.silence do
22
- Rake::Task[task].invoke(*args)
21
+ silence_logger { Rake::Task[task].invoke(*args) }
23
22
 
24
- # Rake by default only allows tasks to be run once per session
25
- Rake.application.tasks.each(&:reenable)
26
- end
23
+ # Rake by default only allows tasks to be run once per session
24
+ Rake.application.tasks.each(&:reenable)
25
+
26
+ nil
27
+ rescue SystemExit
28
+ # Swallow exit/abort calls as we'll never want to exit the IRB session
27
29
  nil
28
30
  end
29
31
 
30
32
  # FIXME: Turn this into calls directly to the test classes, so we don't have to load environment again.
31
33
  # Also need to toggle the environment to test and back to dev after running.
32
34
  def test(what = nil)
33
- ActiveRecord::Base.logger.silence do
34
- case what
35
- when NilClass, :all
36
- rake "test:units"
37
- when String
38
- ENV['TEST'] = "test/#{what}_test.rb"
39
- rake "test:single"
40
- ENV['TEST'] = nil
41
- end
35
+ case what
36
+ when NilClass, :all
37
+ rake "test:units"
38
+ when String
39
+ ENV['TEST'] = "test/#{what}_test.rb"
40
+ rake "test:single"
41
+ ENV['TEST'] = nil
42
42
  end
43
- nil
44
- rescue SystemExit
45
- nil
46
43
  end
47
44
 
48
45
  def generate(argv = nil)
@@ -62,7 +59,6 @@ class Commands
62
59
  def generator(name, argv = nil)
63
60
  if argv.nil?
64
61
  # FIXME: I don't know why we can't just catch SystemExit here, then we wouldn't need this if block
65
- require 'rails/generators'
66
62
  Rails::Generators.help name
67
63
  else
68
64
  ARGV.replace argv.nil? ? [nil] : argv.split(" ")
@@ -72,6 +68,15 @@ class Commands
72
68
 
73
69
  nil
74
70
  end
71
+
72
+ # Only just ensured that this method is available in rails/master, so need a guard for a bit.
73
+ def silence_logger
74
+ if ActiveRecord::Base.logger.respond_to? :silence
75
+ ActiveRecord::Base.logger.silence { yield }
76
+ else
77
+ yield
78
+ end
79
+ end
75
80
  end
76
81
 
77
82
  require 'rails/console/app'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commands
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-20 00:00:00.000000000 Z
12
+ date: 2012-12-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails