addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupsimageimagesinstagramlinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1outlookpersonJoin Group on CardStartprice-ribbonImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruseryahoo

Re: [ruby-46] newbie RoR design question

From: Chris R.
Sent on: Thursday, February 13, 2014 8:48 AM
Adam,

You could use an interactor to capture this behavior. Collective Idea uses interactors (https://github.com/collectiveidea/interactor) to move complicated logic out of controllers. Thus, keeping your controllers  SRP compliant (controllers handle requests, and that's it).

Think of an interactor as a step in a sequence. It has data that gets fed to the step (a context), a method that executes the step (.perform method). And the step can either succeed, or fail (with a message).

You can use the status of the executed interactor to control the flow of your app from your controller. Or if you want to, incorporate it into a background job if parsing the feed is something that takes longer than a handleable request.

/Chris Rittersdorf


On Wed, Feb 12, 2014 at 10:40 AM, Adam Kolkman <[address removed]> wrote:
Hey guys,

Right now I'm working on an app that takes an inventory file (csv), parses it, and persists it to a database. At first I was going to create an Inventory class that would parse the csv and also do business logic on the constructed Inventory database. But now it seems like I should be separating those concerns. The file will update daily, so csv parsing is an important part of the app. 

So I'm now creating a class Feed to handle the inventory feed (.csv), parse it, check for errors, and maybe even act as a json endpoint. The only thing is, there is no need for this class to persist its data, the Inventory class will do that. So if this whole Feed class is a good idea, how would I include it in a Rails project? As a controller without a model? As a .rb file in /lib ? Should I be using rake tasks for this? Other options?

-Adam Kolkman




--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Adam Kolkman ([address removed]) from West Michigan Ruby Users Group.
To learn more about Adam Kolkman, visit his/her member profile
To report this message or block the sender, please click here
Set my mailing list to email me As they are sent | In one daily email | Don't send me mailing list messages

Meetup, POB 4668 #37895 NY NY USA 10163 | [address removed]

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy