lib/unbreakable/processors/transform.rb in unbreakable-0.0.1 vs lib/unbreakable/processors/transform.rb in unbreakable-0.0.2

- old
+ new

@@ -3,16 +3,16 @@ # You may implement a transform process by subclassing this class: # # require 'nokogiri' # class MyProcessor < Unbreakable::Processors::Transform # # Extracts the page title from an HTML page. - # def perform(temp_object) + # def perform # Nokogiri::HTML(temp_object.data).at_css('title') # end # # # Saves the page title to an external database. - # def persist(temp_object, arg) + # def persist(arg) # MyModel.create(:title => arg) # end # end # MyScraper.processor.register MyProcessor # @@ -25,35 +25,37 @@ # the default implementation, but you probably won't have to. class Transform include Dragonfly::Configurable include Dragonfly::Loggable + attr_reader :temp_object, :opts + # +#transform+ must be defined on the subclass for Dragonfly to see it. # @param [Class] subclass a subclass def self.inherited(subclass) subclass.class_eval do # @param [Dragonfly::TempObject] temp_object + # @param [Hash] opts # @return [Dragonfly::TempObject] the same object - def transform(temp_object) - persist temp_object, perform(temp_object) + def transform(temp_object, opts = {}) + @temp_object, @opts = temp_object, opts + persist perform temp_object end end end private # Transforms a record. - # @param [Dragonfly::TempObject] temp_object # @return [Hash] the transformed record - def perform(temp_object) + def perform raise NotImplementedError end # Persists a transformed record. - # @param [Dragonfly::TempObject] temp_object # @param arg a transformed record - def persist(temp_object, arg) + def persist(arg) raise NotImplementedError end end end end