Class: FriendlyGhost::Runner

Inherits:
Object
  • Object
show all
Includes:
POSIX::Spawn
Defined in:
lib/friendly_ghost/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



11
12
13
# File 'lib/friendly_ghost/runner.rb', line 11

def initialize
  @casper_path = `which casperjs`.strip
end

Instance Attribute Details

#casper_pathObject

Returns the value of attribute casper_path.



8
9
10
# File 'lib/friendly_ghost/runner.rb', line 8

def casper_path
  @casper_path
end

#processObject (readonly)

Returns the value of attribute process.



9
10
11
# File 'lib/friendly_ghost/runner.rb', line 9

def process
  @process
end

#resultObject (readonly)

Returns the value of attribute result.



9
10
11
# File 'lib/friendly_ghost/runner.rb', line 9

def result
  @result
end

Instance Method Details

#command(args) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/friendly_ghost/runner.rb', line 15

def command(args)
  @process = Child.new("#{@casper_path} #{args}")

  @result = parse_result
  @result['status'] = @process.success?

  @result
end

#parse_resultObject



28
29
30
31
32
# File 'lib/friendly_ghost/runner.rb', line 28

def parse_result
  json_line = @process.out.split(/\n/).select { |line| line =~ /\{/ }
  output = json_line.first.strip
  MultiJson.load(output)
end

#raw_outputObject



24
25
26
# File 'lib/friendly_ghost/runner.rb', line 24

def raw_output
  @process.out
end