<mayhew>
problem solved :) idling nicely now, my CPU is very happy
<adam12>
nakilon: I don’t like the ‘Fake’ prefix for User or Items. I’d probably have a Store struct that had `items`, and then just pass in the Array of created Items. I don’t like the use of #map over an Array when they could of just been instances of Item directly.
<adam12>
nakilon: For Roda, I’d create custom exception classes and raise them, then handle that in one place with the errors plugin (or whatever the name of it is, I’d have to look it up).
<adam12>
Store could have it’s own lookup method for items, so you wouldn’t have to poke into the items Array repeatedly to do a comparison. Store.find_item(id). Seems like a leaky abstraction.
goldfish has quit [Remote host closed the connection]
<adam12>
nakilon: I’d probably have something that represented the Cart too, even if it was a dummy object that just contained logic. Cart.add_item; Cart.items, etc.
<nakilon>
there is no cart in the task, the item should be subtracted from balance immediately
<adam12>
Ah
<adam12>
If you wanted to get fancy, you could stick this in pstore too.
<adam12>
Assigning a lambda to a variable inside the routing tree every time seems wasteful. I’d assign it to a constant.
<adam12>
Even better, it could just be a method on App.
<nakilon>
doesn't it run once?
<adam12>
No.
<nakilon>
that lambda is about json api, that is only a part of App
<adam12>
It’s a new object for every request into that part of the routing tree.
<nakilon>
ouch
<adam12>
tree: if you were called shrub I’d highlight you less :P
<adam12>
nakilon: Using the roda JSON plugin could have just plain Hashes as return values too.
<adam12>
I don’t see any content-type header’s being set. Not sure if that’s important.
<nakilon>
the company uses Roda without JSON plugin
<adam12>
nakilon: I don’t think this is bad code. But I write Roda all day, every day, for like 6 years now, so I’ve seen some things :P
<nakilon>
declaring a special error class would make sense if there was any scenario of catching it specifically but it's out of task user scenarios
<nakilon>
I agree on defining the items.find method
<nakilon>
yeah you've provided good points on something that is planned to evolve into something bigger
aeris- has quit [Ping timeout: 252 seconds]
<nakilon>
but the task specifically said: "code should be simple, not complicated, no excessive things..."
<nakilon>
thanks for your feedback
<adam12>
That’s true. I’m not sure what counts as excessive.
<adam12>
Was it asked to be done in Roda?
<nakilon>
it was asked to be done in anything
<adam12>
Do the responses always have to be in json-api format?
<adam12>
I notice the error has those fields, but the happy path doesn’t. Just `data` and `included`.
<tree>
adam12: I’m coming to terms with my burden :(
<adam12>
tree: lol
<nakilon>
what else do you mean? it's specfiically told that "you don't do frontend"
<nakilon>
ah, you mean that standard
<adam12>
nakilon: I just thought it odd that the sad path has `jsonapi: { version: “1.0”}`, but the happy path does not.
<adam12>
Yeah.
<nakilon>
the eaxmple on json api website doesn't have version on happy path
<adam12>
I just did a json-rpc client that requires something similar on _EVERY_ response. So I thought it was odd.
<adam12>
No worries.
ur5us has quit [Ping timeout: 240 seconds]
<mayhew>
one question about Roda / Ruby: is it possible to call a module function and keep the same context you'd have inside the `routes do |r|` method to keep the main routing block clean of logic?
<adam12>
mayhew: Yes, kinda? I use something like this: instance_exec(r, some_proc)
aeris- has joined #ruby
<adam12>
mayhew: I was going to give this example but looking at it now, it looks wrong. It works tho and I use something identical in production. Foo = ->(r) { # yay routing tree }; instance_exec(r, &Foo). I feel like it might be making an unnecessary proc but I’d have to look closer.
<adam12>
s/identical/similar
<mayhew>
ah cool, I'll have to try playing around with that. I was just passing all of the stuff I needed explicitly and it was getting a bit ugly. Needed to pass request, response, view, any captured route params, etc.
<mayhew>
instance_exec(&DASHBOARD_HANDLER) worked (where that's a Proc.new), kinda wish I could put it in a `module Dashboard; self.handler` function though. Is that doable?
aeris- has quit [Remote host closed the connection]
aeris- has joined #ruby
aeris- has quit [Remote host closed the connection]
aeris22 has joined #ruby
aeris22 has quit [Remote host closed the connection]
_aeris_ has joined #ruby
_aeris_ is now known as aeris
ur5us has quit [Ping timeout: 244 seconds]
<mayhew>
in Rails, if I execute two separate activerecord operations; how does that work in terms of connection pooling? Does it individually check in and check out a connection for each operation, or is it smart somehow and use the same connection for both operations without putting it back in the pool?
roadie has quit [Ping timeout: 244 seconds]
roadie has joined #ruby
roadie has quit [Ping timeout: 272 seconds]
roadie has joined #ruby
Bish_ has quit [Quit: leaving]
<adam12>
mayhew: Maybe you could use `&Dashboard.method(:handler)`. Or if you named the method #call, maybe even just `&Dashboard`. I didn't test either of these tho.
<adam12>
mayhew: I'm pretty sure the connection is checked out of the pool in Rack middleware, so it's the same one for the entire request.
<adam12>
Actually, that might be the old way.
gr33n7007h has quit [Read error: Connection reset by peer]
gr33n7007h has joined #ruby
<mayhew>
adam12: instance_exec(&Dashboard.method(:handler)) does call Dashboard's self.handler, but it can't access request/response like the Proc could
gearnode has quit [Ping timeout: 244 seconds]
gearnode has joined #ruby
sdfuiojklqaz has joined #ruby
sdfuiojklqaz has quit [Ping timeout: 268 seconds]
sdfuiojklqaz has joined #ruby
billyruffian has joined #ruby
<adam12>
mayhew: It probably needs to be bound somehow. maybe add .bind(self) to the end.
billyruffian has quit [Remote host closed the connection]
TomyWork is now known as TomyLobo
TomyLobo has quit [Remote host closed the connection]