Skip to content

Instantly share code, notes, and snippets.

@nicholasf
Created November 27, 2009 00:22
Show Gist options
  • Select an option

  • Save nicholasf/243734 to your computer and use it in GitHub Desktop.

Select an option

Save nicholasf/243734 to your computer and use it in GitHub Desktop.
#*
How would you refactor this?
This code is workflow, which moves through a set of tasks: the config hash is a list of XML documents to convert into the database kept in YAML, before() does some setup work, download_xmls fetches hundreds of XML documents based on the config, the convert method does a lot of transformation work from xml into AR (and sometimes fetches further XML documents). Finally a report is generated and emailed to recipients to represent how the run went.
It began as a practical way to code an integration between an XML service and the app., now it's smelly. I obviously need a task based DSL, probably a state machine lib.. Any other ideas of a good DSL or library which could be adopted for it?
*#
def self.run
config = YAML.load_file(@@datasets_file)
before()
results = download_xmls(config[:urls])
results[:database_errors] = convert
report = generate_report(results)
email_report(report, config[:notify])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment