I have a ThermalAnalysis class which is NOT a subclass of ActiveRecord::Base. ThermalAnalysis has a dozen or so sub-classes. I want to know the best places to put the files, and how to automatically require all the subclass files. Currently, I have: app/models/ thermal_analysis.rb app/models/thermal_analyses/ subclass1.rb subclass2.rb ... First, is it stylistically okay to put thermal_analysis.rb in the models directory, considering that it''s not an ActiveRecord model? (It IS intimately tied to a few AR models.) If not in models, then where would you suggest? Second, what''s the best technique for requiring all the ThermalAnalysis subclasses? I could push a new value onto $LOAD_PATH from within thermal_analysis.rb, as in: $LOAD_PATH << File.expand_path("../thermal_analyses", __FILE__) ...but that will only get triggered when ThermalAnalysis is first referenced, which is usually too late. (FWIW, ThermalAnalysis is essentially an abstract class: only its subclasses get instantiated.) TIA. - ff -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 5, 12:59 am, Fearless Fool <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: subclass2.rb> ... > > First, is it stylistically okay to put thermal_analysis.rb in the models > directory, considering that it''s not an ActiveRecord model? (It IS > intimately tied to a few AR models.) If not in models, then where would > you suggest?/models is definitely not restricted to ActiveRecord subclasses, for example I''d 100% put mongodb models in there. You might be able to reasonably claim that this class does model data, the data itself is just a layer of abstraction away. If not, then lib is where I''d put things.> > Second, what''s the best technique for requiring all the ThermalAnalysis > subclasses? I could push a new value onto $LOAD_PATH from within > thermal_analysis.rb, as in: > > $LOAD_PATH << File.expand_path("../thermal_analyses", __FILE__) > > ...but that will only get triggered when ThermalAnalysis is first > referenced, which is usually too late. (FWIW, ThermalAnalysis is > essentially an abstract class: only its subclasses get instantiated.) >Rails maps sub directories to namespaces - it will automatically look for ThermalAnalysis::Foo in thermal_analysis/foo.rb. If you do add something to the load path (you probably want to add it to active support''s load path so that auto require, preloading etc. work) you could do it from an initializer ( a file in config/initializers) Fred> TIA. > > - ff > > -- > Posted viahttp://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote in post #972354:> /models is definitely not restricted to ActiveRecord subclasses... > ... > Rails maps sub directories to namespaces - it will automatically look > for ThermalAnalysis::Foo in thermal_analysis/foo.rb.Ah! Poifect! This works like a champ: # file: app/modules/thermal_analysis/base.rb module ThermalAnalysis class Base ... ; end end # file: app/modules/thermal_analysis/foo.rb module ThermalAnalysis class Foo < ThermalAnalysis::Base ... ; end end ... etc Thanks for the explanation and solution. - ff -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.