Class: Spring
- Inherits:
-
Object
- Object
- Spring
- Defined in:
- lib/spring.rb,
lib/spring/env.rb,
lib/spring/sid.rb,
lib/spring/server.rb,
lib/spring/version.rb,
lib/spring/commands.rb,
lib/spring/application.rb,
lib/spring/application_manager.rb,
lib/spring/application_watcher.rb
Defined Under Namespace
Modules: Commands, SID Classes: Application, ApplicationManager, ApplicationWatcher, Env, Server
Constant Summary collapse
- SERVER_COMMAND =
[ File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME')), "-I", File.("../", __FILE__), "-r", "spring/server", "-r", "bundler/setup", "-e", "Spring::Server.boot" ]
- FORWARDED_SIGNALS =
%w(INT QUIT USR1 USR2 INFO)
- IGNORE_SIGNALS =
%w(INT QUIT)
- VERSION =
"0.0.5"
Class Attribute Summary collapse
-
.application_watcher ⇒ Object
Returns the value of attribute application_watcher.
-
.commands ⇒ Object
readonly
Returns the value of attribute commands.
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Class Method Summary collapse
- .command(name) ⇒ Object
- .command_registered?(name) ⇒ Boolean
- .register_command(name, klass, options = {}) ⇒ Object
- .run(args) ⇒ Object
Instance Method Summary collapse
-
#boot_server ⇒ Object
Boot the server into the process group of the current session.
-
#initialize ⇒ Spring
constructor
A new instance of Spring.
- #run(args) ⇒ Object
- #server_running? ⇒ Boolean
Constructor Details
Class Attribute Details
.application_watcher ⇒ Object
Returns the value of attribute application_watcher.
7 8 9 |
# File 'lib/spring/application.rb', line 7 def application_watcher @application_watcher end |
.commands ⇒ Object (readonly)
Returns the value of attribute commands.
5 6 7 |
# File 'lib/spring/commands.rb', line 5 def commands @commands end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
25 26 27 |
# File 'lib/spring.rb', line 25 def env @env end |
Class Method Details
.command(name) ⇒ Object
20 21 22 |
# File 'lib/spring/commands.rb', line 20 def self.command(name) commands.fetch name end |
.command_registered?(name) ⇒ Boolean
16 17 18 |
# File 'lib/spring/commands.rb', line 16 def self.command_registered?(name) commands.has_key?(name) end |
.register_command(name, klass, options = {}) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/spring/commands.rb', line 8 def self.register_command(name, klass, = {}) commands[name] = klass if [:alias] commands[[:alias]] = klass end end |
.run(args) ⇒ Object
21 22 23 |
# File 'lib/spring.rb', line 21 def self.run(args) exit new.run(args) end |
Instance Method Details
#boot_server ⇒ Object
Boot the server into the process group of the current session. This will cause it to be automatically killed once the session ends (i.e. when the user closes their terminal).
48 49 50 51 52 |
# File 'lib/spring.rb', line 48 def boot_server env.socket_path.unlink if env.socket_path.exist? Process.spawn(*SERVER_COMMAND, pgroup: SID.pgid) sleep 0.1 until env.socket_path.exist? end |
#run(args) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/spring.rb', line 54 def run(args) if self.class.command_registered?(args.first) run_command(args) else print_help end end |
#server_running? ⇒ Boolean
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/spring.rb', line 31 def server_running? if env.pidfile_path.exist? pidfile = env.pidfile_path.open('r') !pidfile.flock(File::LOCK_EX | File::LOCK_NB) else false end ensure if pidfile pidfile.flock(File::LOCK_UN) pidfile.close end end |