I have a set of parsers that differ significantly in logic, but have exact methods and results.
I have developed several Rake
masters, and I'm curious that what I came up with can lead to unexpected or strange behavior.
Essentially my parse.rake
looks something like this:
require 'app/models/provider' require 'config/environment.rb' Provider.all.each do |provider| require "lib/tasks/#{provider.name}.rb" Kernel.const_get(provider.name).provider = provider namespace provider.name do task :provider_task do
Since classes are constants in ruby, Kernel.const_get
is what I used to access class methods from varname. My classes look like ( ABC.rb
):
Class ABC cattr_accessor :provider def self.provider_task()
With this setting, I can easily call rake ABC:provider_task
to run a specific parser. Also cattr_accessor
allows me to easily reference the actual provider model. Thoughts?
Mike a
source share