Skip to content

Instantly share code, notes, and snippets.

@imajes
Created July 15, 2010 15:25
Show Gist options
  • Save imajes/477105 to your computer and use it in GitHub Desktop.
Save imajes/477105 to your computer and use it in GitHub Desktop.
class Converter
require 'logger'
# abstract class for converting from our sources into the main db...
attr_accessor :sources
def initialize(*sources)
self.sources = sources
@logger = Logger.new("log/#{self.class.to_s}.log")
@logger.formatter = Logger::Formatter.new
end
def process!
# iterate over each source to process
sources.each do |s|
begin
source = Rails.const_get(s.to_s.classify)
rescue
@logger.warn "Invalid attempt to call the source #{s.to_s.classify} - skipping"
next ## invalid object, so punting
end
source.find(:all).each do |item|
process_one(item, s)
end
end
end
def process_one(item, source)
## abstract for subclass....
end
def mark_as(state, item)
begin
sm.state = :state.to_s
sm.save!
rescue
@logger.warn "Invalid State change attempt for #{item.class.to_s}"
end
sm.reload
sm
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment