Class: Proselytism::Converters::Base
- Inherits:
-
Object
- Object
- Proselytism::Converters::Base
- Includes:
- Singleton
- Defined in:
- lib/proselytism/converter.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
-
#convert(file_path, options = {}) ⇒ Object
call perform logging duration and potential errors.
- #destination_file_path(origin, options = {}) ⇒ Object
-
#execute(command) ⇒ Object
execute a command and raise error with the command output if it fails.
Instance Method Details
#convert(file_path, options = {}) ⇒ Object
call perform logging duration and potential errors
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/proselytism/converter.rb', line 26 def convert(file_path, ={}) log :debug, "#{self.class.name} converted #{file_path} to :#{[:to]}" do begin perform(file_path, ) rescue Error => e log :error, "#{e.class.name} #{e.}\n#{e.backtrace}\n" raise e end end end |
#destination_file_path(origin, options = {}) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/proselytism/converter.rb', line 17 def destination_file_path(origin, ={}) if [:dest] [:dest] else File.join [:dir], File.basename(origin).gsub(/\..*$/, [:folder] ? '' : ".#{[:to]}") end end |
#execute(command) ⇒ Object
execute a command and raise error with the command output if it fails
38 39 40 41 42 43 44 |
# File 'lib/proselytism/converter.rb', line 38 def execute(command) output = `#{command}` if $?.exitstatus != 0 raise self.class::Error, ["#{self.class.name} unable to exec command: #{command}",'--', output,'--'].join("\n") end $?.exitstatus == 0 end |