#RubyOnRails - 04 April 2018
Forward 1 day »
[06:50:22] Radar: dminuoso: https://github.com/dry-rb/dry-monads/blob/master/lib/dry/monads/either.rb#L7-L9
[06:51:32] Radar: https://github.com/dry-rb/dry-monads/commit/09066220e135b8efa1bc7e0ba9cef3fa30d64c2d No PR. No explanation. Probably lost in the sands of time ... oops I mean Gitter.im
[06:51:44] dminuoso: Radar: It's just a shame monad patterns tend to perform horribly with Ruby's execution model and complete lack of optimizations.
[06:52:15] Radar: TBH tho it is a better alternative to pervasive if/else typically found in service objects
[06:52:34] Radar: ANYWAY. I said I was leaving the office 5 mins ago but I am _still here_. Time to change that :wave:
[06:53:08] dminuoso: Radar: Id ask you to ponder about this for a moment. What exactly does Either/Result model?
[06:53:31] dminuoso: As in "once you emit a Left/Failure, skip all further computation until someone handles your left case"
[06:53:49] MasterAsia: Radar, I ended up solving it with a table-lock that still allows reads (lock table with exclusive)
[06:59:11] dminuoso: Radar: So what strength do you get from using `Either` over `raise`? What exactly is so dangerous or problematic for using exceptions to shortcircuit computation?
[07:00:49] dminuoso: It's mostly lack of enforced contract really, in that the consumer has to know that an exception can be produced. Java does it right by forcing you to acknowledge that fact.
[07:01:53] dminuoso: But in Ruby all bets are off anyway, because we have no type system to rule out cases where someone forgets to handle the left case, and we have no syntactic sugar or combinators to properly use monadic code
[07:03:31] dminuoso: We already happily live with the fact that you have to read the source code and documentation to know how to use a method. So some note that "this throws XYZ in case of failure" seems to fit into standard ruby practices.
[07:08:40] dminuoso: The more I stare at this result monad from dry-monads, the less Im convinced about it. It has too many options to promote escaping the either monad, which means programmers will be quick to simply pry the thing open because its too cumbersome to use the monadic interface.
[07:10:35] Radar: dminuoso: You're right. An exception would be just as suitable in this case. I like it solely because it isn't enforcing that rescuing from exceptions is a "good pattern"
[07:10:45] Radar: But essentially, the implementation is the same. "In this _exceptional_ case, go do this thing"
[07:11:59] dminuoso: Radar: Oh absolutely yeah. With the right set of combinators `Either` becomes more powerful because suddenly control flow lives in data types.
[07:12:58] dminuoso: Radar: I recently tried rolling a parser combinator library in Ruby. It was an absolute nightmare to write. :(
[07:16:06] dminuoso: Radar: Once the groundwork is laid, it's the most elegant way to write parsers.
[07:16:44] dminuoso: It's just difficult to write an efficient combinator library that can backtrack and has location reporting..
[13:01:50] dminuoso: Given the nesting [Foo::Bar], should a reference to `Foo::Quux` autoload and find some `::Foo::Quux`?
[14:14:30] yebyen: can I ask a question of anyone that is using fixtures in rails (with rspec? not sure if that part is important)
[14:15:26] yebyen: the question is, when you invoke "fixtures :whatevers" at the top of your file's first describe block
[14:16:03] yebyen: is that the end of the story or are you later going down and asking for particular fixtures within a given test like whatever(:certain_one)
[14:16:53] yebyen: and I'm trying to understand why... if it's because of something I've done, or what version I'm on
[15:04:44] yebyen: I adjusted my RSpec config to use database cleaner and truncate before each suite
[15:05:07] yebyen: I don't like it but it works, I can run rspec twice and it doesn't have surprise failures the second time
[15:19:03] drale2k_: WalterPeck: i would like to use this ui framework. It has a npm package, can i use that with webpacker? https://www.npmjs.com/package/tabler-ui
[15:22:22] WalterPeck: drale2k_: I am not really a front end guy, but it webpacker allows you to use npm ui packages
[15:25:14] WalterPeck: drale2k_: and then just make sure your rails app is set up to read assets from the ui package
[15:26:47] WalterPeck: drale2k_: but that looks like a jekyll template ui system, are you trying to utilize it for rails?
[15:28:47] GeorgesLeYeti: I want to do something like that: https://gist.github.com/GeorgesLeYeti/4bb8e6b245444e4361ba0747f556ef0e
[15:29:28] WalterPeck: drale2k_: but I have run into issues where rails wasnt using the package assets
[15:29:49] GeorgesLeYeti: But when is_joe = false then it returns any user with last_name = Doe and any first name
[15:32:12] GeorgesLeYeti: I know i can do something like I did in the comment but i wanna know if it s possible to do it like the 1st code
[17:58:01] fcser_: With a multi-step form - after visitors complete it, to prevent them from going back and editing the form. Is the standard best practice to just keep the record ID in the session and delete it at the end once the form is complete? Or is there a better way? There is no login involved for this record creation.
[18:18:59] dminuoso: fcser_: If possible I'd try to not enforce it server side unless I had a good reason to do so. If you can simply use `history.replaceState` to navigate, that avoids the issue.
[18:21:05] fcser_: and have a few steps then a payment and want to disallow any editing after payment / thank-you
[18:23:44] fcser_: Generally you define steps in a controller, first step it creates a model, next steps add more data to the model. Validation is setup to be conditional based on the current step, and then payment occurrs as a validation on last step.
[18:25:09] fcser_: Maybe I’m not explaining it well. It does save, there is also a ‘status’ attribute on the model
[18:25:12] dminuoso: fcser_: Well anyway. Id probably use `history.replaceState` to navigate between the steps.
[18:25:32] fcser_: ok thanks for the suggestion I was not aware of that option and will check it out.
[18:27:46] dminuoso: fcser_: An alternative option would be to generate some token on the initial request, store it in the model and add a unique constraint. That guarantees it server side.
[18:28:07] fcser_: ok I had started down that path too but was wondering if there was a better option
[18:28:22] fcser_: and that would allow access via a ‘secret url’ in the future to view the completed form
[18:29:41] dminuoso: fcser_: the point isnt as much the "secrecy", its the inability to replay that last request because of the unique constraint.
[18:30:21] dminuoso: if a user shoudn't be able to go back (or only at defined points), dont use the browser history
[18:31:26] dminuoso: fcser_: What you could do, which might not be so bad actually - is grab the `id` by fetching from the database sequence manually before.
[18:33:14] fcser_: interesting - ok I’ll have to think about that some - wonder if there is some example code for that scenario?
[18:36:59] fcser_: yebyen: I did a quick search but could not find any info on ‘pre_loaded_fixtures’
[18:38:48] devpolish: Hi guys, I'm doing an API using Faker gem. I'm serving random data without using a DB, for each request. It's a good pattern doing this?
[19:11:10] devpolish: https://bitbucket.org/bitconcept/rails-api/src/a35729084bd8f7de6c4e2764f2ef1b33399d5bd7/app/models/user_generator.rb?at=master&fileviewer=file-view-default
[19:11:23] devpolish: https://bitbucket.org/bitconcept/rails-api/src/a35729084bd8f7de6c4e2764f2ef1b33399d5bd7/app/controllers/users_controller.rb?at=master&fileviewer=file-view-default
[19:12:39] devpolish: https://bitbucket.org/bitconcept/rails-api/src/a35729084bd8f7de6c4e2764f2ef1b33399d5bd7/README.md?at=master&fileviewer=file-view-default
[19:19:25] yebyen: FLeiXiuS: put the 'pry' gem in there and drop a 'binding.pry' statement on the line before it blows up
[19:19:58] yebyen: and run `class` if you want and see what kind of object it really is at that point
[19:20:25] yebyen: pry is better imho, you can run "modules" and get a list of modules in the web console
[21:15:27] FrostCandy: Easy Question, I need to see if this date is older than a year old. This timestame looks like this 2018-04-04 18:45:31.079599
[21:15:59] FrostCandy: I think i want something like this but it doesnt work Date.today - 365 <= Date.parse(created_at, "%d-%m-%Y")
[22:01:04] conorao: hey all, does anyone have experience using recognize_path in the context of a routing constraint?
[22:03:41] FrostCandy: dionysus69: by the way turns out reading the date in from postgres through activerecords automaticalyl puts it into a date class so i was trying to to_date a date heh
[22:05:12] dionysus69: oh :D ye otherwise the pgsql date record would be super ugly for humans to read :)
[22:31:00] FrostCandy: conorao: yup it turned out i didn't have to mess with the returend date from the db. It was already a date type.