Class: CukeForker::Worker
- Inherits:
-
Object
- Object
- CukeForker::Worker
- Includes:
- Observable
- Defined in:
- lib/cukeforker/worker.rb
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#feature ⇒ Object
readonly
Returns the value of attribute feature.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#out ⇒ Object
readonly
Returns the value of attribute out.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #args ⇒ Object
- #basename ⇒ Object
- #failed? ⇒ Boolean
- #finished? ⇒ Boolean
-
#initialize(feature, format, out, extra_args = []) ⇒ Worker
constructor
A new instance of Worker.
- #output ⇒ Object
- #start ⇒ Object
- #stderr ⇒ Object
- #stdout ⇒ Object
- #text ⇒ Object
Constructor Details
#initialize(feature, format, out, extra_args = []) ⇒ Worker
Returns a new instance of Worker.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/cukeforker/worker.rb', line 12 def initialize(feature, format, out, extra_args = []) @feature = feature @format = format @extra_args = extra_args @out = out @status = nil @data = OpenStruct.new @id = self.class.id += 1 end |
Class Attribute Details
.id ⇒ Object
7 |
# File 'lib/cukeforker/worker.rb', line 7 def id; @id ||= -1; end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
10 11 12 |
# File 'lib/cukeforker/worker.rb', line 10 def data @data end |
#feature ⇒ Object (readonly)
Returns the value of attribute feature.
10 11 12 |
# File 'lib/cukeforker/worker.rb', line 10 def feature @feature end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
10 11 12 |
# File 'lib/cukeforker/worker.rb', line 10 def format @format end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/cukeforker/worker.rb', line 10 def id @id end |
#out ⇒ Object (readonly)
Returns the value of attribute out.
10 11 12 |
# File 'lib/cukeforker/worker.rb', line 10 def out @out end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
10 11 12 |
# File 'lib/cukeforker/worker.rb', line 10 def pid @pid end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
10 11 12 |
# File 'lib/cukeforker/worker.rb', line 10 def status @status end |
Instance Method Details
#args ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/cukeforker/worker.rb', line 42 def args args = %W[--format #{format} --out #{output}] args += @extra_args args << feature args end |
#basename ⇒ Object
72 73 74 |
# File 'lib/cukeforker/worker.rb', line 72 def basename @basename ||= feature.gsub(/\W/, '_') end |
#failed? ⇒ Boolean
30 31 32 |
# File 'lib/cukeforker/worker.rb', line 30 def failed? status.nil? || status.exitstatus != 0 end |
#finished? ⇒ Boolean
23 24 25 26 27 28 |
# File 'lib/cukeforker/worker.rb', line 23 def finished? wait_pid, @status = Process.waitpid2(pid, Process::WNOHANG) !!wait_pid rescue Errno::ECHILD, Errno::ESRCH true end |
#output ⇒ Object
60 61 62 |
# File 'lib/cukeforker/worker.rb', line 60 def output File.join out, "#{basename}.#{format}" end |
#start ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/cukeforker/worker.rb', line 34 def start @pid = Process.fork { changed notify_observers :on_worker_forked, self execute_cucumber } end |
#stderr ⇒ Object
68 69 70 |
# File 'lib/cukeforker/worker.rb', line 68 def stderr File.join out, "#{basename}.stderr" end |
#stdout ⇒ Object
64 65 66 |
# File 'lib/cukeforker/worker.rb', line 64 def stdout File.join out, "#{basename}.stdout" end |
#text ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/cukeforker/worker.rb', line 50 def text "[ #{pid} #{feature} #{status.inspect} #{out} #{data} ]" end |