Class: SiteFuel::Processor::AbstractProcessor
- Inherits:
-
Object
- Object
- SiteFuel::Processor::AbstractProcessor
- Extended by:
- ClassLogging
- Includes:
- Logging, Configurable
- Defined in:
- lib/sitefuel/processors/AbstractProcessor.rb
Overview
defines the base functions every processor must implement to interface with the sitefuel architecture
Direct Known Subclasses
AbstractExternalProgramProcessor, AbstractStringBasedProcessor
Instance Attribute Summary (collapse)
-
- (Object) execution_list
readonly
array of filters to run.
-
- (Object) original_size
readonly
gives the original size of a resource before being processed.
-
- (Object) processed_size
readonly
gives the size of the resouce now that it's been processed.
-
- (Object) resource_name
readonly
gives the canonical name of the resource.
Class Method Summary (collapse)
-
+ (Object) default_filterset
gives the default filterset used.
-
+ (Boolean) file_pattern_match?(filename)
gives true if filename matches one of #file_patterns.
-
+ (Object) file_patterns
gives the file patterns that trigger the processor by default; this behavior can be over-ridden by configuration files.
-
+ (Boolean) filter?(name)
gives true if the given filter is known for this processor class.
-
+ (Object) filters
lists all the filters implemented by a processor.
-
+ (Object) filters_in_filterset(name)
returns the filters in the given filter set, [] if no such filters exist.
-
+ (Boolean) filterset?(name)
gives true if the given name is of a filter set for this processor.
-
+ (Object) filterset_ignore
the ignore filter set is used when configuring sitefuel to not process certain kinds of files.
-
+ (Object) filtersets
lists all filtersets for this processor.
-
+ (Object) find_processors
gives a list of processors that implement AbstractProcessor.
-
+ (Boolean) processes_file?(filename)
uses #file_pattern_match? to decide if the file can be processed eventually this may use other metrics (like mime types).
-
+ (Object) processor_name
gives the display name for the processor.
-
+ (Object) processor_type
gives the type of the processor, usually implemented by the more specific abstract processors.
Instance Method Summary (collapse)
-
- (Object) add_filter(filter)
adds a filter or array of filters to the execution list.
-
- (Object) add_filterset(filterset)
adds the filters in a filterset to the execution list.
-
- (Object) clear_filters
clears all filters from the execution list.
-
- (Object) create_file(base_file_tree)
creates a file with the given name.
-
- (Object) drop_filter(filter)
drops a filter from the execution list.
-
- (Object) execute
runs all filters in the execution list.
-
- (Boolean) filter?(filter)
gives true if the given filter is known for this processor instance.
-
- (Object) finish_filters
called in #execute after running the execution list of filters.
-
- (AbstractProcessor) initialize
constructor
setup an AbstractProcessor.
-
- (Object) processor_symbol
gives the symbol of the processor; used when showing deployment progress.
-
- (Object) run_filter(name)
runs a particular filter.
-
- (Object) run_filterset(name)
evaluate a filterset.
-
- (Object) save(base_file_tree)
default save method.
-
- (Object) setup_filters
called in #execute before running the execution list of filters; note that #setup_filters is only called once before all of the filters are batch executed.
Methods included from ClassLogging
debug, error, fatal, info, warn
Methods included from Configurable
#configuration_options, #configure, #ensure_configurable_option, #set_configuration
Methods included from Logging
#debug, #error, #fatal, #info, #logger=, #warn
Constructor Details
- (AbstractProcessor) initialize
setup an AbstractProcessor
83 84 85 86 87 88 89 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 83 def initialize self.logger = SiteFuelLogger.instance @execution_list = [] @filters = [] @resource_name = nil end |
Instance Attribute Details
- (Object) execution_list (readonly)
array of filters to run
266 267 268 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 266 def execution_list @execution_list end |
- (Object) original_size
gives the original size of a resource before being processed
122 123 124 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 122 def original_size @original_size end |
- (Object) processed_size
gives the size of the resouce now that it's been processed
125 126 127 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 125 def processed_size @processed_size end |
- (Object) resource_name
gives the canonical name of the resource
119 120 121 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 119 def resource_name @resource_name end |
Class Method Details
+ (Object) default_filterset
gives the default filterset used
180 181 182 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 180 def self.default_filterset nil end |
+ (Boolean) file_pattern_match?(filename)
gives true if filename matches one of #file_patterns.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 150 def self.file_pattern_match?(filename) file_patterns.map { |patt| case patt when String regex = Regexp.new("^.*"+Regexp.escape(patt)+"$", Regexp::IGNORECASE) return true if filename.match(regex) != nil when Regexp return true if filename.match(patt) != nil end } # if we got this far nothing matched return false end |
+ (Object) file_patterns
gives the file patterns that trigger the processor by default; this behavior can be over-ridden by configuration files.
-
strings are assumed to be extensions and are tested for a literal match
-
regexes are tested against the entire file name
145 146 147 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 145 def self.file_patterns [] end |
+ (Boolean) filter?(name)
gives true if the given filter is known for this processor class
256 257 258 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 256 def self.filter?(name) filters.include?(name.to_sym) end |
+ (Object) filters
lists all the filters implemented by a processor
247 248 249 250 251 252 253 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 247 def self.filters names = instance_methods names = names.delete_if{ |method| not method =~ /^filter_.*$/ } names.sort! names.map { |filter_name| filter_name.sub(/^filter_(.*)$/, '\1').to_sym } end |
+ (Object) filters_in_filterset(name)
returns the filters in the given filter set, [] if no such filters exist
206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 206 def self.filters_in_filterset(name) return [] unless self.filterset?(name) filter_list = self.send("filterset_" + name.to_s) if filter_list == nil return [] else return filter_list end end |
+ (Boolean) filterset?(name)
gives true if the given name is of a filter set for this processor
194 195 196 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 194 def self.filterset?(name) respond_to?("filterset_" + name.to_s) end |
+ (Object) filterset_ignore
the ignore filter set is used when configuring sitefuel to not process certain kinds of files.
200 201 202 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 200 def self.filterset_ignore [] end |
+ (Object) filtersets
lists all filtersets for this processor
185 186 187 188 189 190 191 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 185 def self.filtersets names = methods names = names.delete_if{|method| not method =~ /^filterset_.*$/ } names.sort! names.map { |filterset| filterset.sub(/^filterset_(.*)$/, '\1').to_sym } end |
+ (Object) find_processors
gives a list of processors that implement AbstractProcessor
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 93 def self.find_processors procs = [] ObjectSpace.each_object(Class) do |cls| if cls.ancestors.include?(self) and cls.to_s =~ /^.*Processor$/ and not cls.to_s =~ /^.*Abstract.*Processor$/ then procs << cls end end procs end |
+ (Boolean) processes_file?(filename)
uses #file_pattern_match? to decide if the file can be processed eventually this may use other metrics (like mime types)
168 169 170 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 168 def self.processes_file?(filename) file_pattern_match? filename end |
+ (Object) processor_name
gives the display name for the processor
128 129 130 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 128 def self.processor_name self.to_s.sub(/.*\b(.*)Processor/, '\1') end |
+ (Object) processor_type
gives the type of the processor, usually implemented by the more specific abstract processors.
109 110 111 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 109 def self.processor_type '' end |
Instance Method Details
- (Object) add_filter(filter)
adds a filter or array of filters to the execution list
add_filter(:minify)
add_filter([:beautifytext, :minify])
272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 272 def add_filter(filter) case filter when Array filter.each do |f| add_filter f end when Symbol, String if filter?(filter) @execution_list << filter else raise UnknownFilter.new(self, filter) end end end |
- (Object) add_filterset(filterset)
adds the filters in a filterset to the execution list
219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 219 def add_filterset(filterset) if self.class.filterset?(filterset) # extract the filters in the filterset and add them to the list filter_list = self.class.filters_in_filterset(filterset) filter_list.each do |filter| add_filter(filter) end @execution_list else raise UnknownFilterset.new(self, filterset) end end |
- (Object) clear_filters
clears all filters from the execution list
288 289 290 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 288 def clear_filters @execution_list = [] end |
- (Object) create_file(base_file_tree)
creates a file with the given name
333 334 335 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 333 def create_file(base_file_tree) base_file_tree.get_file(resource_name) end |
- (Object) drop_filter(filter)
drops a filter from the execution list
293 294 295 296 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 293 def drop_filter(filter) @execution_list.delete(filter) @execution_list end |
- (Object) execute
runs all filters in the execution list
319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 319 def execute setup_filters @execution_list.uniq.each do |filter| info "\t\tRunning filter: #{filter}" run_filter(filter) end finish_filters rescue => exception error 'from %s:%s: %s: %s' % [self.class, resource_name, exception.class, exception] error "Stack trace:\n#{exception.backtrace.join("\n")}" end |
- (Boolean) filter?(filter)
gives true if the given filter is known for this processor instance
261 262 263 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 261 def filter?(filter) respond_to?("filter_" + filter.to_s) end |
- (Object) finish_filters
called in #execute after running the execution list of filters
315 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 315 def finish_filters; end |
- (Object) processor_symbol
gives the symbol of the processor; used when showing deployment progress
134 135 136 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 134 def processor_symbol 'A' end |
- (Object) run_filter(name)
runs a particular filter
299 300 301 302 303 304 305 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 299 def run_filter(name) if respond_to?("filter_" + name.to_s) self.send("filter_"+name.to_s) else raise UnknownFilter.new(self, name) end end |
- (Object) run_filterset(name)
evaluate a filterset
233 234 235 236 237 238 239 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 233 def run_filterset(name) if self.class.filter_set?("filterset_" + name.to_s) self.send("filterset_" + name.to_s) else raise UnknownFilterset(self, name) end end |
- (Object) save(base_file_tree)
default save method. This will only create a file, the more specific abstractions need to implement the actual method
340 341 342 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 340 def save(base_file_tree) create_file(base_file_tree) end |
- (Object) setup_filters
called in #execute before running the execution list of filters; note that #setup_filters is only called once before all of the filters are batch executed. It is not called before every filter executes.
311 |
# File 'lib/sitefuel/processors/AbstractProcessor.rb', line 311 def setup_filters; end |