Class: SiteFuel::Processor::AbstractExternalProgramProcessor

Inherits:
AbstractProcessor show all
Defined in:
lib/sitefuel/processors/AbstractExternalProgramProcessor.rb

Overview

Defines an abstract processor that offloads the work onto an external program. These are typically processors for handling binary files (eg. images)

These processors spend a bunch of time ensuring the external program exists and of the appropriate version; each filter then will typically setup more parameters to pass to the program.

Direct Known Subclasses

PNGProcessor

Instance Attribute Summary

Attributes inherited from AbstractProcessor

#execution_list, #original_size, #processed_size, #resource_name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractProcessor

#add_filter, #add_filterset, #clear_filters, #create_file, default_filterset, #drop_filter, #execute, file_pattern_match?, file_patterns, #filter?, filter?, filters, filters_in_filterset, filterset?, filterset_ignore, filtersets, find_processors, #finish_filters, processes_file?, processor_name, #run_filter, #run_filterset, #setup_filters

Methods included from ClassLogging

#debug, #error, #fatal, #info, #warn

Methods included from Configurable

#configuration_options, #configure, #ensure_configurable_option, #post_configuration, #pre_configuration, #set_configuration

Methods included from Logging

#debug, #error, #fatal, #info, #logger=, #warn

Constructor Details

#initializeAbstractExternalProgramProcessor

Returns a new instance of AbstractExternalProgramProcessor.



27
28
29
30
# File 'lib/sitefuel/processors/AbstractExternalProgramProcessor.rb', line 27

def initialize
  super
  @output_filename = nil
end

Class Method Details

.process_file(filename, config = {}) ⇒ Object

processes a file using a given configuration



41
42
43
44
45
46
47
48
# File 'lib/sitefuel/processors/AbstractExternalProgramProcessor.rb', line 41

def self.process_file(filename, config = {})
  info "#{self.class} opening for #{filename}"

  proc = self.new()
  proc.configure(config)
  proc.set_file(filename)
  proc.generate
end

.processor_typeObject



32
33
34
# File 'lib/sitefuel/processors/AbstractExternalProgramProcessor.rb', line 32

def self.processor_type
  'External'
end

Instance Method Details

#generateObject

generates the new document using external programs



79
80
81
82
83
84
85
86
# File 'lib/sitefuel/processors/AbstractExternalProgramProcessor.rb', line 79

def generate
  self.execute
  self.processed_size = File.size(output_filename)
  return self
rescue SiteFuel::External::ProgramExitedWithFailure => exception
  error "When processing #{resource_name}:"
  error exception.to_s
end

#output_filenameObject

gives the output filename for this processor; typically this will be a temporary file.



70
71
72
73
74
75
76
# File 'lib/sitefuel/processors/AbstractExternalProgramProcessor.rb', line 70

def output_filename
  if @output_filename == nil
    @output_filename = Tempfile.new(File.basename(resource_name)).path
  end

  @output_filename
end

#processor_symbolObject



36
37
38
# File 'lib/sitefuel/processors/AbstractExternalProgramProcessor.rb', line 36

def processor_symbol
  'E'
end

#save(base_file_tree) ⇒ Object



88
89
90
91
92
# File 'lib/sitefuel/processors/AbstractExternalProgramProcessor.rb', line 88

def save(base_file_tree)
  final_filename = base_file_tree.get_file(resource_name)
  File.rename(output_filename, final_filename)
  info "Moved #{output_filename} to #{final_filename}"
end

#set_file(filename, resource_name = nil) ⇒ Object

sets the file used by this processor



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/sitefuel/processors/AbstractExternalProgramProcessor.rb', line 51

def set_file(filename, resource_name=nil)
  case
    when (resource_name == nil and @resource_name == nil)
      @resource_name = filename

    when @resource_name != nil
      # just leave @resource_name be

    else
      @resource_name = resource_name
  end
  
  self.original_size = File.size(filename)

  return self
end