spring 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -42,7 +42,10 @@ At the moment only MRI 1.9.3 / Rails 3.2 is supported.
42
42
 
43
43
  ## Usage
44
44
 
45
- Add `spring` to your gemfile and do a `bundle`.
45
+ Install the `spring` gem. You may wish to add it to your bundle, but
46
+ it's not necessary. If you do, I don't recommend invoking `spring`
47
+ via `bundle exec` as that will make it slow. Just call `spring`
48
+ on its own.
46
49
 
47
50
  You now have a `spring` command. Do a `rbenv rehash` if necessary. Note
48
51
  that on my machine I had over 700 gems installed, and activating the gem
@@ -79,8 +82,8 @@ That booted our app in the background:
79
82
 
80
83
  ```
81
84
  $ ps ax | grep spring
82
- 8692 pts/6 Sl 0:00 /home/turnip/.rbenv/versions/1.9.3-p194/bin/ruby -r bundler/setup -r spring/server -e Spring::Server.boot
83
- 8698 pts/6 Sl 0:02 /home/turnip/.rbenv/versions/1.9.3-p194/bin/ruby -r bundler/setup -r spring/server -e Spring::Server.boot
85
+ 8692 pts/6 Sl 0:00 /home/turnip/.rbenv/versions/1.9.3-p194/bin/ruby -I ... -r spring/server -r bundler/setup -e Spring::Server.boot
86
+ 8698 pts/6 Sl 0:02 /home/turnip/.rbenv/versions/1.9.3-p194/bin/ruby -I ... -r spring/server -r bundler/setup -e Spring::Server.boot
84
87
  ```
85
88
 
86
89
  We can see two processes, one is the Spring server, the other is the
@@ -118,8 +121,8 @@ automatically. Note that the application process id is 8698 above. Let's
118
121
  ```
119
122
  $ touch config/application.rb
120
123
  $ ps ax | grep spring
121
- 8692 pts/6 Sl 0:00 /home/turnip/.rbenv/versions/1.9.3-p194/bin/ruby -r bundler/setup -r spring/server -e Spring::Server.boot
122
- 8876 pts/6 Sl 0:00 /home/turnip/.rbenv/versions/1.9.3-p194/bin/ruby -r bundler/setup -r spring/server -e Spring::Server.boot
124
+ 8692 pts/6 Sl 0:00 /home/turnip/.rbenv/versions/1.9.3-p194/bin/ruby -I ... -r spring/server -r bundler/setup -e Spring::Server.boot
125
+ 8876 pts/6 Sl 0:00 /home/turnip/.rbenv/versions/1.9.3-p194/bin/ruby -I ... -r spring/server -r bundler/setup -e Spring::Server.boot
123
126
  ```
124
127
 
125
128
  The application process detected the change and exited. The server process
@@ -151,9 +154,9 @@ the application in development mode.
151
154
 
152
155
  ```
153
156
  $ ps ax | grep spring
154
- 8692 pts/6 Sl 0:00 /home/turnip/.rbenv/versions/1.9.3-p194/bin/ruby -r bundler/setup -r spring/server -e Spring::Server.boot
155
- 8876 pts/6 Sl 0:15 /home/turnip/.rbenv/versions/1.9.3-p194/bin/ruby -r bundler/setup -r spring/server -e Spring::Server.boot
156
- 9088 pts/6 Sl 0:01 /home/turnip/.rbenv/versions/1.9.3-p194/bin/ruby -r bundler/setup -r spring/server -e Spring::Server.boot
157
+ 8692 pts/6 Sl 0:00 /home/turnip/.rbenv/versions/1.9.3-p194/bin/ruby -I ... -r spring/server -r bundler/setup -e Spring::Server.boot
158
+ 8876 pts/6 Sl 0:15 /home/turnip/.rbenv/versions/1.9.3-p194/bin/ruby -I ... -r spring/server -r bundler/setup -e Spring::Server.boot
159
+ 9088 pts/6 Sl 0:01 /home/turnip/.rbenv/versions/1.9.3-p194/bin/ruby -I ... -r spring/server -r bundler/setup -e Spring::Server.boot
157
160
  ```
158
161
 
159
162
  Running rake is faster the second time:
@@ -10,8 +10,9 @@ require "spring/commands"
10
10
  class Spring
11
11
  SERVER_COMMAND = [
12
12
  File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME')),
13
- "-r", "bundler/setup",
13
+ "-I", File.expand_path("../", __FILE__),
14
14
  "-r", "spring/server",
15
+ "-r", "bundler/setup",
15
16
  "-e", "Spring::Server.boot"
16
17
  ]
17
18
 
@@ -51,6 +52,32 @@ class Spring
51
52
  end
52
53
 
53
54
  def run(args)
55
+ if self.class.command_registered?(args.first)
56
+ run_command(args)
57
+ else
58
+ print_help
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def print_help
65
+ puts <<-EOT
66
+ Usage: spring COMMAND [ARGS]
67
+
68
+ The most common spring commands are:
69
+ rake Run a rake task
70
+ console Start the Rails console
71
+ runner Execute a command with the Rails runner
72
+ generate Trigger a Rails generator
73
+
74
+ test Execute a Test::Unit test
75
+ rspec Execute an RSpec spec
76
+ EOT
77
+ false
78
+ end
79
+
80
+ def run_command(args)
54
81
  boot_server unless server_running?
55
82
 
56
83
  application, client = UNIXSocket.pair
@@ -91,8 +118,6 @@ class Spring
91
118
  server.close if server
92
119
  end
93
120
 
94
- private
95
-
96
121
  def rails_env_for(command_name)
97
122
  command = Spring.command(command_name)
98
123
 
@@ -5,8 +5,16 @@ class Spring
5
5
  attr_reader :commands
6
6
  end
7
7
 
8
- def self.register_command(name, klass)
9
- commands[name] = klass.new
8
+ def self.register_command(name, klass, options = {})
9
+ commands[name] = klass
10
+
11
+ if options[:alias]
12
+ commands[options[:alias]] = klass
13
+ end
14
+ end
15
+
16
+ def self.command_registered?(name)
17
+ commands.has_key?(name)
10
18
  end
11
19
 
12
20
  def self.command(name)
@@ -35,7 +43,7 @@ class Spring
35
43
  require File.expand_path(args.first)
36
44
  end
37
45
  end
38
- Spring.register_command "test", Test
46
+ Spring.register_command "test", Test.new
39
47
 
40
48
  class RSpec
41
49
  def env
@@ -51,7 +59,7 @@ class Spring
51
59
  ::RSpec::Core::Runner.run(args)
52
60
  end
53
61
  end
54
- Spring.register_command "rspec", RSpec
62
+ Spring.register_command "rspec", RSpec.new
55
63
 
56
64
  class Rake
57
65
  def setup
@@ -63,7 +71,7 @@ class Spring
63
71
  ::Rake.application.run
64
72
  end
65
73
  end
66
- Spring.register_command "rake", Rake
74
+ Spring.register_command "rake", Rake.new
67
75
 
68
76
  class Console
69
77
  def setup
@@ -75,7 +83,7 @@ class Spring
75
83
  ::Rails::Console.start(::Rails.application)
76
84
  end
77
85
  end
78
- Spring.register_command "console", Console
86
+ Spring.register_command "console", Console.new, alias: "c"
79
87
 
80
88
  class Generate
81
89
  def setup
@@ -87,7 +95,7 @@ class Spring
87
95
  require "rails/commands/generate"
88
96
  end
89
97
  end
90
- Spring.register_command "generate", Generate
98
+ Spring.register_command "generate", Generate.new, alias: "g"
91
99
 
92
100
  class Runner
93
101
  def call(args)
@@ -96,6 +104,6 @@ class Spring
96
104
  require "rails/commands/runner"
97
105
  end
98
106
  end
99
- Spring.register_command "runner", Runner
107
+ Spring.register_command "runner", Runner.new, alias: "r"
100
108
  end
101
109
  end
@@ -1,3 +1,3 @@
1
1
  class Spring
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -17,6 +17,6 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency 'activesupport'
20
+ gem.add_development_dependency 'activesupport'
21
21
  gem.add_development_dependency 'rake'
22
22
  end
@@ -122,6 +122,10 @@ class AppTest < ActiveSupport::TestCase
122
122
  assert_speedup
123
123
  end
124
124
 
125
+ test "help message when called without arguments" do
126
+ assert_stdout BINFILE, 'Usage: spring COMMAND [ARGS]'
127
+ end
128
+
125
129
  test "test changes are picked up" do
126
130
  assert_successful_run test_command
127
131
 
@@ -208,4 +212,8 @@ class AppTest < ActiveSupport::TestCase
208
212
  test "custom commands" do
209
213
  assert_stdout "#{BINFILE} custom", "omg"
210
214
  end
215
+
216
+ test "runner alias" do
217
+ assert_stdout "#{BINFILE} r 'puts 1'", "1"
218
+ end
211
219
  end
@@ -4,4 +4,4 @@ class CustomCommand
4
4
  end
5
5
  end
6
6
 
7
- Spring.register_command "custom", CustomCommand
7
+ Spring.register_command "custom", CustomCommand.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
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: 2013-01-13 00:00:00.000000000 Z
12
+ date: 2013-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -19,7 +19,7 @@ dependencies:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
- type: :runtime
22
+ type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false