[@Max: our messages just crossed.  With all due respect, I think I like
my approach better!]

Okay.  I'm out of the weeds, but I'd like to know if I've done it the
right way.

My code references subclasses of MeteredService several transactions
after metered_service.rb gets loaded (e.g. the result of posting a
form), at which point the sub-classes had been flushed and there was
nothing that forced a reload of metered_service.rb.  Ergo, adding
require_dependency statements at the bottom of metered_service.rb didn't
help.

My next gambit was to overload MeteredService.descendants:

class MeteredService
  ...
  def self.descendants
    require_dependency 'metered_services/pge_business'
    require_dependency 'metered_services/pge_residential'
    require_dependency 'metered_services/sce_residential'
    require_dependency 'metered_services/sdge_residential'
    require_dependency 'metered_services/socalgas_residential'
    require_dependency 'metered_services/srp_residential'
    super
  end
end

... but that had the problem that it threw "TypeError (superclass
mismatch for class PGEBusiness)" when it got called.  Perhaps it's in
the wrong context when it calls require_dependency?  I don't know, and I
couldn't find any documentation that helped.

So now I overload MeteredService.descendants, calling 'require' instead
of 'require_dependency'.  This seems to work just fine:

class MeteredService
  ...
if Rails.env.development?
  def self.descendants
    require 'metered_services/pge_business'
    require 'metered_services/pge_residential'
    require 'metered_services/sce_residential'
    require 'metered_services/sdge_residential'
    require 'metered_services/socalgas_residential'
    require 'metered_services/srp_residential'
    super
  end
end
end

Yes, I will generalize this with a method that reads the contents of the
metered_services directory so I don't have to manually add each one.

Let me know if I'm missing anything important.

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to