Reputation: 9332
This is a complicated question with many possible answers, so I'll break down my situation into simple bullet points to help narrow down the solution:
My Rails App Has the Following 'Objects'
The Objects are Related Like So:
Example Setup:
My problem and My Questions:
Problem:
I need to parse the above-mentioned feed and store each tweet in the updates
table. To parse the feed, I was thinking of writing a custom Feed
class which would get inherited by TwitterFeed
, FacebookFeed
, TumblrFeed
, etc.
However, I'm not sure if this is the 'Best Practice' for solving this kind of problem.
Questions:
Upvotes: 2
Views: 761
Reputation: 6408
Don't shy away from using a custom class if it's appropriate. If you need another a class, then add one, the fact you are using rails is not relevant to that decision.
Upvotes: 1
Reputation: 12242
You are probably going to have a background task invoked from time-to-time to check all the feeds, fetch new updates and store those in database. This task is completely separate from controllers and it should be possible to invoke it without any controller logic.
Your abstraction looks fine. You can further have something like XmlFeed < Feed
if several feeds share a common XML structure.
1) Controllers should talk to database/models and pass relevant data to the view to render. Everything else should be either in a model, helper or library.
2) Are you asking where the parsing logic belongs to? In MVC, I think this would belong under the Model and/or a helper class, but definitely not the controller.. it's not its responsibility.
3) Classes holding data go into app/models. Classes that have nothing to do with holding data, go into the lib directory.
Upvotes: 1