Module: Dragonfly::Shell
- Includes:
- Configurable
- Included in:
- Analysis::FileCommandAnalyser, ImageMagick::Utils
- Defined in:
- lib/dragonfly/shell.rb
Defined Under Namespace
Classes: CommandFailed
Configuration Summary
Configurable attributes
Configurable attributes for an object in general
object
can be configured either by using something like
object.configure do |c|
c.some_configurable_attribute = "some value"
c.some_other_configurable_attribute = 42
...
end
or
object.some_configurable_attribute = "some value"
Configurable attributes for instances of Dragonfly::Shell
-
log_commands
- default false
Instance Method Summary
(collapse)
included
Instance Method Details
- (Object) escape_args(args)
32
33
34
35
36
|
# File 'lib/dragonfly/shell.rb', line 32
def escape_args(args)
args.shellsplit.map do |arg|
quote arg.gsub(/\\?'/, %q('\\\\''))
end.join(' ')
end
|
- (Object) quote(string)
38
39
40
41
|
# File 'lib/dragonfly/shell.rb', line 38
def quote(string)
q = Dragonfly.running_on_windows? ? '"' : "'"
q + string + q
end
|
- (Object) raise_shell_command_failed(command)
28
29
30
|
# File 'lib/dragonfly/shell.rb', line 28
def raise_shell_command_failed(command)
raise CommandFailed, "Command failed (#{command}) with exit status #{$?.exitstatus}"
end
|
- (Object) run(command, args = "")
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/dragonfly/shell.rb', line 12
def run(command, args="")
full_command = "#{command} #{escape_args(args)}"
log.debug("Running command: #{full_command}") if log_commands
begin
result = `#{full_command}`
rescue Errno::ENOENT
raise_shell_command_failed(full_command)
end
if $?.exitstatus == 1
throw :unable_to_handle
elsif !$?.success?
raise_shell_command_failed(full_command)
end
result
end
|