Class: Guard::Spork::SporkInstance
- Inherits:
-
Object
- Object
- Guard::Spork::SporkInstance
- Defined in:
- lib/guard/spork/spork_instance.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#process ⇒ Object
readonly
Returns the value of attribute process.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #command ⇒ Object
-
#initialize(type, port, env, options) ⇒ SporkInstance
constructor
A new instance of SporkInstance.
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(type, port, env, options) ⇒ SporkInstance
Returns a new instance of SporkInstance.
8 9 10 11 12 13 |
# File 'lib/guard/spork/spork_instance.rb', line 8 def initialize(type, port, env, ) @type = type @port = port @env = env @options = end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'lib/guard/spork/spork_instance.rb', line 6 def env @env end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/guard/spork/spork_instance.rb', line 6 def @options end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
6 7 8 |
# File 'lib/guard/spork/spork_instance.rb', line 6 def pid @pid end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
6 7 8 |
# File 'lib/guard/spork/spork_instance.rb', line 6 def port @port end |
#process ⇒ Object (readonly)
Returns the value of attribute process.
6 7 8 |
# File 'lib/guard/spork/spork_instance.rb', line 6 def process @process end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/guard/spork/spork_instance.rb', line 6 def type @type end |
Class Method Details
.spork_pids ⇒ Object
89 90 91 |
# File 'lib/guard/spork/spork_instance.rb', line 89 def self.spork_pids `ps aux | grep -v guard | awk '/spork/&&!/awk/{print $2;}'`.split("\n").map { |pid| pid.to_i } end |
Instance Method Details
#alive? ⇒ Boolean
46 47 48 |
# File 'lib/guard/spork/spork_instance.rb', line 46 def alive? pid && process.alive? end |
#command ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/guard/spork/spork_instance.rb', line 58 def command parts = [] if use_bundler? parts << "bundle" parts << "exec" end if use_foreman? parts << "foreman" parts << "run" end parts << "spork" if type == :test_unit parts << "testunit" elsif type == :cucumber parts << "cu" elsif type == :minitest parts << "minitest" end parts << "-p" parts << port.to_s parts << "-q" if [:quiet] if use_foreman? parts << "-e=#{[:foreman].fetch(:env, '.env')}" if end parts end |
#running? ⇒ Boolean
50 51 52 53 54 55 56 |
# File 'lib/guard/spork/spork_instance.rb', line 50 def running? return false unless alive? TCPSocket.new('127.0.0.1', port).close true rescue Errno::ECONNREFUSED false end |
#start ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/guard/spork/spork_instance.rb', line 30 def start executable, *cmd = command Compat::UI.debug "guard-spork command execution: #{cmd}" @process = ChildProcess.build(executable, *cmd) @process.environment.merge!(env) unless env.empty? @process.io.inherit! @process.start @pid = @process.pid end |
#stop ⇒ Object
42 43 44 |
# File 'lib/guard/spork/spork_instance.rb', line 42 def stop process.stop end |
#to_s ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/guard/spork/spork_instance.rb', line 15 def to_s case type when :rspec "RSpec" when :cucumber "Cucumber" when :test_unit "Test::Unit" when :minitest "MiniTest" else type.to_s end end |