jeudi 20 juillet 2017

Should this be a lone Model, a Model and Controller, or some other Ruby class entirely?

Currently in my app a QuoteRequest has_one Quote which belongs_to a QuoteRequest. QuoteRequest has full MVC, ie QuoteRequest#new view enables user to create and persist the object and its data to a QuoteRequest table in the db.

I'm now working out how to design the next stage, which is;

  • when a QuoteRequest is created it should kick off the application crawling to an external site
  • gathering the actual quote using the QuoteRequest data, scraping the result, persisting that result to the app’s data
  • then rendering a view of that quote data.

As a newbie I’m struggling to decise how best to design and write this. I think I get that general MVC standard, of a C serving the user a V, that V capturing something from the user and the C then taking that something from the V and sending it to the M for the M to persist in the db. But I;m not sure how plain old Ruby classes with initialize methods fit within the Rails environment.

In my next stage after QuoteRequest is created there’s a part of the process that doesn’t need a view, ie once the QuoteRequest data is persisted to the db it needs to kick off something in the app, currently Quote though no functionality written in Quote yet, that goes our and crawls and scrapes and saves this scrape, then we’re back to needing a view for the scrape to be rendered.

So I’m wondering whether this ‘non view requiring’ stage of the process ought to be neither a model or a controller, rather some type of standard Ruby class, e.g. flow as below(pls excuse strange 'pseudo code'!):

  • On successful QuoteRequest.save >> OtherClass.start_crawl >> on OtherClass.crawl_success >> save as a Quote.create (no view) >> Quote.show(OtherClass.crawl_sucess_result) view >> Done.

Can anyone help me out with making decisions about how to design this I guess pretty simple pattern. Thanks

Aucun commentaire:

Enregistrer un commentaire