Class: Paperclip::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/paperclip/command_line.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(binary, params = "", options = {}) ⇒ CommandLine

Returns a new instance of CommandLine.



7
8
9
10
11
12
13
14
# File 'lib/paperclip/command_line.rb', line 7

def initialize(binary, params = "", options = {})
  @binary            = binary.dup
  @params            = params.dup
  @options           = options.dup
  @swallow_stderr    = @options.has_key?(:swallow_stderr) ? @options.delete(:swallow_stderr) : Paperclip.options[:swallow_stderr]
  @expected_outcodes = @options.delete(:expected_outcodes)
  @expected_outcodes ||= [0]
end

Class Attribute Details

.pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/paperclip/command_line.rb', line 4

def path
  @path
end

Instance Method Details

#commandObject



16
17
18
19
20
21
22
# File 'lib/paperclip/command_line.rb', line 16

def command
  cmd = []
  cmd << full_path(@binary)
  cmd << interpolate(@params, @options)
  cmd << bit_bucket if @swallow_stderr
  cmd.join(" ")
end

#runObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/paperclip/command_line.rb', line 24

def run
  Paperclip.log(command)
  begin
    output = self.class.send(:'`', command)
  rescue Errno::ENOENT
    raise Paperclip::CommandNotFoundError
  end
  if $?.exitstatus == 127
    raise Paperclip::CommandNotFoundError
  end
  unless @expected_outcodes.include?($?.exitstatus)
    raise Paperclip::PaperclipCommandLineError, "Command '#{command}' returned #{$?.exitstatus}. Expected #{@expected_outcodes.join(", ")}"
  end
  output
end