Class: Skeptick::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/skeptick/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shellwords) ⇒ Command

Returns a new instance of Command.



9
10
11
# File 'lib/skeptick/command.rb', line 9

def initialize(shellwords)
  @shellwords = shellwords
end

Instance Attribute Details

#shellwordsObject (readonly)

Returns the value of attribute shellwords.



7
8
9
# File 'lib/skeptick/command.rb', line 7

def shellwords
  @shellwords
end

Instance Method Details

#run(spawn_options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/skeptick/command.rb', line 17

def run(spawn_options = {})
  opts = {}
  opts[:chdir]   = Skeptick.cd_path.to_s if Skeptick.cd_path
  opts[:timeout] = Skeptick.timeout if Skeptick.timeout
  opts.merge(spawn_options)

  if Skeptick.debug_mode?
    Skeptick.log("Skeptick Command: #{to_s}")
  end

  im_process = POSIX::Spawn::Child.new(*shellwords, opts)

  if !im_process.success?
    raise ImageMagickError,
      "ImageMagick error\nCommand: #{to_s}\nSTDERR:\n#{im_process.err}"
  end

  im_process.status
end

#to_sObject



13
14
15
# File 'lib/skeptick/command.rb', line 13

def to_s
  shellwords.join(' ')
end