jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
<FromGitter> <mtsmmp_gitlab> hey guys
<FromGitter> <mtsmmp_gitlab> i have a class Config that has only this property -> @data = YAML.parse(File.read("config.yml"))
<FromGitter> <mtsmmp_gitlab> is there a way to make Config itself be @data? for example -> puts Config.name instead of puts Config.data.name
<FromGitter> <mtsmmp_gitlab> i tried declaring self = data but doesnt work
<FromGitter> <mixflame> What would make a shard dependency not run it's post-install script?
<FromGitter> <Blacksmoke16> ```def name ⏎ @config.name ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5f3f23fe85c0f2132fe09076]
<FromGitter> <mtsmmp_gitlab> @Blacksmoke16 do i need to create method for each YAML property?
<FromGitter> <mtsmmp_gitlab> cause with @data i just do puts Config.data.name, name doesnt not appear anywhere in the code
<FromGitter> <Blacksmoke16> can you share teh full example?
<FromGitter> <mtsmmp_gitlab> i wanted the same behavior with Config.name
<FromGitter> <mtsmmp_gitlab> sure
<FromGitter> <mwlang> isn't there a delegate_missing macro that would solve this?
<FromGitter> <mwlang> Ah, I misremembered, but this is it: https://crystal-lang.org/api/0.20.0/Class.html#forward_missing_to%28delegate%29-macro
<FromGitter> <mtsmmp_gitlab> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f3f29325d0f8f2440847383]
<FromGitter> <mwlang> @mtsmmp_gitlab try this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f3f2a41750a274130327e71]
<FromGitter> <mwlang> `puts config["name"]` worked for me with that forward_missing_to in there.
<FromGitter> <mtsmmp_gitlab> yep
<FromGitter> <mtsmmp_gitlab> thanks!! it works
<FromGitter> <mwlang> that does forward every missing method call to @data, if you want to constrain it, then do this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f3f2ac93dac5343401e7ef9]
<FromGitter> <mwlang> which is actually what I think I would do myself.
<FromGitter> <mtsmmp_gitlab> is there a way:
<FromGitter> <mtsmmp_gitlab> 1) to escape having to call Config.new (like Config was already initilized on require)
deavmi has quit [Ping timeout: 256 seconds]
<FromGitter> <mtsmmp_gitlab> 1) to get the properties like this -> config.name instead of config["name"]
deavmi has joined #crystal-lang
<FromGitter> <mtsmmp_gitlab> @mwlang can you show me an example of what this constrain method does
<FromGitter> <mtsmmp_gitlab> @mwlang yo? :D
<FromGitter> <dscottboggs_gitlab> > to get the properties like this -> config.name instead of config["name"] ⏎ ⏎ it depends on whether you know the string `name` at compile- or run-time
<FromGitter> <mtsmmp_gitlab> @dscottboggs_gitlab got it
<FromGitter> <dscottboggs_gitlab> wow, cool, I expected to have to explain what I meant by that lol
<FromGitter> <mtsmmp_gitlab> =(
<FromGitter> <dscottboggs_gitlab> not because of you in particular!
<FromGitter> <dscottboggs_gitlab> I just don't expect people to necessarily know what compile-time or runtime are in a forum for a language targeted at rubyists lol
<FromGitter> <dscottboggs_gitlab> > is there a way to escape having to call Config.new (like Config was already initilized on require) ⏎ ⏎ so, I recently was confronted with this exact problem, and....I'm not exactly proud of this or sure it's the best way to do things, but this is how I handled it... ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f3f41f2a8c17801766199c3]
iwq has quit [Ping timeout: 260 seconds]
<FromGitter> <mtsmmp_gitlab> the difficulty for me is that i come from a nodejs background and everything is new yet. i have 0 ruby experience too
iwq has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> that's alright. TBH I don't think ruby experience is a huge advantage for Crystal. I feel like it's more like a better Go or runtime-GC'd rust than ruby-like
<FromGitter> <mixflame> Ok in the last few days in my backend I have built bad word filtering, bad link filtering, serverless server and global user ban, almost done with these apple requirements lol
<FromGitter> <dscottboggs_gitlab> > is there a way to escape having to call Config.new (like Config was already initilized on require) ⏎ ⏎ so, I recently was confronted with this exact problem, and....I'm not exactly proud of this or sure it's the best way to do things, but this is how I handled it... ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f3f43b6a05e464346db15f5]
<FromGitter> <dscottboggs_gitlab> > apple requirements ⏎ ⏎ ugh that sucks. Thanks for your work in making Crystal Apps work on iOS but I don't envy you
<FromGitter> <mixflame> lol np
<FromGitter> <mixflame> it's actually a crystal server paired with a swift OS X app
<FromGitter> <dscottboggs_gitlab> > swift OS X app ⏎ ⏎ oh, I see. Still, I don't envy you 😆
<FromGitter> <mtsmmp_gitlab> > that's alright. TBH I don't think ruby experience is a huge advantage for Crystal. I feel like it's more like a better Go or runtime-GC'd rust than ruby-like ⏎ ⏎ i thought it was a major advantage
<FromGitter> <mtsmmp_gitlab> > > is there a way to escape having to call Config.new (like Config was already initilized on require) ⏎ > ⏎ > so, I recently was confronted with this exact problem, and....I'm not exactly proud of this or sure it's the best way to do things, but this is how I handled it... ⏎ > ⏎ > ``` ... [https://gitter.im/crystal-lang/crystal?at=5f3f4542a8c178017661a198]
<FromGitter> <dscottboggs_gitlab> > i thought it was a major advantage ⏎ ⏎ on it's face, you'd think so. The syntax is so close that some Crystal programs wiill run in the ruby interpreter. But the type system in Crystal is so much like C/C++/Rust/Go that it's not even close to ruby when you really get into writing Crystal on a day-to-day basis.
<FromGitter> <dscottboggs_gitlab> > crazy ⏎ ⏎ what's crazy?
<FromGitter> <mtsmmp_gitlab> sorry, nothing
<FromGitter> <mtsmmp_gitlab> i was trying to understand the code
<FromGitter> <dscottboggs_gitlab> as long as you get it, 👍
<FromGitter> <mtsmmp_gitlab> got it
<FromGitter> <mtsmmp_gitlab> thanks
_whitelogger has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> awesome
<FromGitter> <mtsmmp_gitlab> @dscottboggs_gitlab any lib or tool to prettify/uglify html?
<FromGitter> <Daniel-Worrall> Prettify: https://github.com/Daniel-Worrall/beautify
<FromGitter> <mwlang> For me, Ruby doesn't help all that much with the static type stuff (as you can tell by my various questions here), but it's been a huge advantage to me quickly taking up Crystal. I'm especially able to find the rough equivalents for Crystal based on my StdLib of Ruby and all that meta-programming definitely helped me figure out how to write macros in Crystal and actually think of them like I might think of
<FromGitter> ... meta-programming in Ruby.
<FromGitter> <Daniel-Worrall> Minify: https://github.com/sam0x17/html-minifier
<FromGitter> <mwlang> I love that I can think structurally and conceptually like Ruby and approach problems with more or less the same approach I would in Ruby from design perspective.
<FromGitter> <mtsmmp_gitlab> @Daniel-Worrall thanks buddy
<FromGitter> <mwlang> sorry, @mtsmmp_gitlab -- wasn't ignoring ya earlier, just had my head down in code and all notifications off.
<FromGitter> <mtsmmp_gitlab> no problem mate
<FromGitter> <mwlang> I only have a few weeks of Crystal under my belt, so by no means an expert here.
<FromGitter> <mtsmmp_gitlab> i just started days ago
<FromGitter> <mwlang> entirely different beast from NodeJS, so I'd say you're doing quite well already.
<FromGitter> <mtsmmp_gitlab> i can say without a doubt that today i worked like 8 or 10 hours on this crystal project
<FromGitter> <mtsmmp_gitlab> long time since that happens man
<FromGitter> <mwlang> its the excitement of seeing and doing something new and seeing how ridiculously fast the programs run.
<FromGitter> <mwlang> I've got algos that take 20 minutes in Ruby running in just under a couple minutes in Crystal.
<FromGitter> <mwlang> I still can't get over that huge speed boost.
<FromGitter> <mtsmmp_gitlab> yep... im creating a simple blog generator because on nodejs i use hexo and i have some spam blogs with thousands of pages
<FromGitter> <mtsmmp_gitlab> what is happening is that hexo is slowing down a lot on the generation
<FromGitter> <mtsmmp_gitlab> and it takes up like 4gb of my memory, like what the fuck
<FromGitter> <mtsmmp_gitlab> (on the generation)
<FromGitter> <mwlang> sounds crazy
<FromGitter> <mtsmmp_gitlab> i thought about switching to huGO
<FromGitter> <mwlang> well, I'm off to bed. have fun!
<FromGitter> <mtsmmp_gitlab> but out of nowhere decided to code everything myself on crystal
<FromGitter> <mtsmmp_gitlab> cool, have a good night
dostoyevsky has quit [*.net *.split]
duane has quit [*.net *.split]
DTZUZU has quit [*.net *.split]
Elouin has quit [*.net *.split]
deimos_ has quit [*.net *.split]
sorcus has quit [Ping timeout: 240 seconds]
duane has joined #crystal-lang
Elouin has joined #crystal-lang
deimos_ has joined #crystal-lang
DTZUZU has joined #crystal-lang
dostoyevsky has joined #crystal-lang
dostoyevsky has quit [Max SendQ exceeded]
dostoyevsky has joined #crystal-lang
<FromGitter> <mattrberry> Can someone explain this error to me please? This doesn't make sense to me.. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f3f6d8edfaaed4ef5fcbe17]
woodruffw has quit [Ping timeout: 246 seconds]
<FromGitter> <mattrberry> And why does it fail on `bus` but not `cartridge`?
dostoyevsky has quit [Client Quit]
dostoyevsky has joined #crystal-lang
woodruffw has joined #crystal-lang
<FromGitter> <naqvis> @mattrberry you are passing instance of uninitialized object
<FromGitter> <naqvis> during constructor phase `self` shouldn't be valid and shouldn't be available
<FromGitter> <naqvis> object is not yet instantiated/constructed
sorcus has joined #crystal-lang
<FromGitter> <mattrberry> Is there a way to achieve a similar effect of objects with references to each other from the initialize method so that I dont have to do it independently at a later point?
<FromGitter> <naqvis> yeah, do lazy initialization like ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f3f746a89cf2d584b674c56]
<FromGitter> <naqvis> and in your code, you should use getter method instead of directly using the variables
<FromGitter> <naqvis> modified code above to use `cpu` instead of `@cpu`
<FromGitter> <mattrberry> Wouldn’t I need cpu.not_nil!.tick then? :/
<FromGitter> <naqvis> no, you don't
<FromGitter> <naqvis> because you are accessing the property
<FromGitter> <mattrberry> Ah, gotcha
<FromGitter> <naqvis> 👍
<FromGitter> <mattrberry> Iirc the getter macro can also take a block, so I could just put the ||= in there
<FromGitter> <mattrberry> Okay, that’s not the worst
<FromGitter> <naqvis> yeah sure
<FromGitter> <mattrberry> Ty for the suggestion
<FromGitter> <naqvis> 👍 u
<FromGitter> <naqvis> @mattrberry if you use block with getter, you don't need to use `||=` operator
<FromGitter> <naqvis> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f3f78b29bad075eacc8d787]
<FromGitter> <naqvis> If a block is given to the macro, a getter is generated with a variable that is lazily initialized with the block's contents
<FromGitter> <naqvis> this code is similar to what was given previously
<FromGitter> <mattrberry> Awesome, thank you!
dostoyevsky has quit [*.net *.split]
iwq has quit [*.net *.split]
deavmi has quit [*.net *.split]
<FromGitter> <naqvis> 👍
iwq has joined #crystal-lang
deavmi has joined #crystal-lang
dostoyevsky has joined #crystal-lang
dostoyevsky has quit [Max SendQ exceeded]
dostoyevsky has joined #crystal-lang
zorp_ has joined #crystal-lang
r0bby has quit [Read error: Connection reset by peer]
r0bby has joined #crystal-lang
zorp_ has quit [Remote host closed the connection]
zorp_ has joined #crystal-lang
<oprypin> @naqvis: @mattrberry ftr that macro with the block does exactly the ||= thing
alexherbo2 has joined #crystal-lang
<FromGitter> <naqvis> yeah oprypin, so I said "this code is similar to what was given previously"
alexherbo24 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 265 seconds]
alexherbo24 is now known as alexherbo2
Elouin has quit [Quit: So long and thanks for all the fish!]
Elouin has joined #crystal-lang
deavmi has quit [Quit: No Ping reply in 180 seconds.]
deavmi has joined #crystal-lang
<FromGitter> <grkek> tf is this?
<FromGitter> <grkek> and why does it redirect to shards.io?
<FromGitter> <grkek> shards.info*
<FromGitter> <Blacksmoke16> the real question is how did you find that :S
<FromGitter> <wyhaines> @grkek It's not redirecting to shards.io. ⏎ ⏎ The DNS for it points to the same IP address as shards.io. ⏎ ⏎ It was registered in 201, and it was still operating until sometime last year. ... [https://gitter.im/crystal-lang/crystal?at=5f3fd9b459ac794e02b88d77]
Seich has quit [Ping timeout: 272 seconds]
Seich has joined #crystal-lang
zorp_ has quit [Ping timeout: 272 seconds]
zorp_ has joined #crystal-lang
<FromGitter> <j8r> @Blacksmoke16 haha lol
<FromGitter> <grkek> @Blacksmoke16 I was searching for shards
<FromGitter> <grkek> and it popped up
<FromGitter> <j8r> @grkek maybe it was the first domain name
Elouin7 has joined #crystal-lang
<FromGitter> <grkek> Maybe they just decided to rename shards.info to that
<FromGitter> <grkek> I released Grip 1.0.0
<FromGitter> <grkek> v
<FromGitter> <j8r> it popped having installed some random things a site asked?
<FromGitter> <Blacksmoke16> 1) 0.0 already? :0
<FromGitter> <grkek> Yes, as the Crystal 1.0.0 is coming I decided to jump versions
Elouin has quit [Ping timeout: 240 seconds]
Elouin7 is now known as Elouin
<FromGitter> <grkek> I added tests
<FromGitter> <grkek> fixed the websocket issues
<FromGitter> <Blacksmoke16> fair enough
<FromGitter> <grkek> Yes
<FromGitter> <grkek> I am very bad with git
<FromGitter> <grkek> don't mind it :p
<FromGitter> <grkek> Idk why but I am using actions as well with the circle ci
<FromGitter> <grkek> travis*
<FromGitter> <grkek> So what do you people think, is it horrific?
<FromGitter> <Blacksmoke16> deff makes the commit history gross
<FromGitter> <Blacksmoke16> but :shrug:
<FromGitter> <dscottboggs_gitlab> to merge master into master? Yeah I did that once when I was working with @j8r and he got hella mad lol
<FromGitter> <dscottboggs_gitlab> it creates duplicate commits or a circular point in your history or something
<FromGitter> <grkek> Not the merge, the release and the framework itself
<FromGitter> <dscottboggs_gitlab> ohh
<FromGitter> <grkek> I am kinda proud of it
<FromGitter> <dscottboggs_gitlab> we haven't gotten any 1.0rc's yet have we?
<FromGitter> <Blacksmoke16> nope, prob kinda early
* FromGitter * j8r is however proud of merging master into master
<FromGitter> <grkek> Nope, I think I am one who just jumped it up
<FromGitter> <grkek> @Blacksmoke16 lmao
<FromGitter> <j8r> ... hum that's me that said that, not @Blacksmoke16
<FromGitter> <j8r> that's the infamous `/me`
<FromGitter> <dscottboggs_gitlab> yes the /me display is kinda confusing in gitter
<FromGitter> <dscottboggs_gitlab> I knew what was going on.
<FromGitter> <grkek> I have a cool exploit for gitter
<FromGitter> <grkek> which is kinda annoying
<FromGitter> <grkek> > >>>>>>>>>>>>>>>>>>>>>>>>>>>
<FromGitter> <grkek> > >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>hahafunny
<FromGitter> <grkek> there we go
<FromGitter> <j8r> that's a special character?
<FromGitter> <grkek> Use the more than sign multiple times
<FromGitter> <dscottboggs_gitlab> I don't see how that's an "exploit"
<FromGitter> <grkek> I wonder what happens if you type /me multiple times
<FromGitter> <dscottboggs_gitlab> @grkek is there anything significant for the release other than adding some tests and `crystal: 1.0.0` ?
* FromGitter * grkek /me /me /me /me /me
<FromGitter> <grkek> Updated the websocket handler
<FromGitter> <grkek> renamed couple of classes idk
<FromGitter> <grkek> not much to be honest
<FromGitter> <dscottboggs_gitlab> I like the websocket API of inheriting from a controller and overloading `#on_ping` etc
<FromGitter> <dscottboggs_gitlab> @Blacksmoke16 does Athena have decent websocket support?
<FromGitter> <Blacksmoke16> 😬
<FromGitter> <Blacksmoke16> no
<FromGitter> <grkek> It doesn't even have
<FromGitter> <grkek> websocket support
<FromGitter> <grkek> I think
<FromGitter> <dscottboggs_gitlab> oooof
<FromGitter> <Blacksmoke16> it doesnt, idk anything about them soooo yea...
<FromGitter> <Blacksmoke16> its a TODO :P
<FromGitter> <grkek> I can help? but I don't know the weird annotation magic
<FromGitter> <grkek> @dscottboggs_gitlab thank you mate ;)
<FromGitter> <grkek> Did you like the way the exceptions are handled?
<FromGitter> <dscottboggs_gitlab> yeah I was just about to say I might be able to work up a PR for that, from what I remember of looking at the Kemal source code it was pretty simple to do
<FromGitter> <grkek> Yeah it is really simple
<FromGitter> <Blacksmoke16> main problem would be those implementations are based on `HTTP::Handler` which athena doesnt use
<FromGitter> <grkek> > .> sorry that is what kemal uses
<FromGitter> <dscottboggs_gitlab> why does that smell bad @j8r ?
<FromGitter> <j8r> this means two grip can't be on a same app
<FromGitter> <dscottboggs_gitlab> oh
<FromGitter> <grkek> Why would one want to do that?
<FromGitter> <j8r> same as kemal
<FromGitter> <grkek> Why would you want to have 2 apps in the same project?
<FromGitter> <j8r> a reverse proxy for instance
<FromGitter> <dscottboggs_gitlab> IMO it doesn't matter why. Someone will want to do something weird with your code someday so designing for flexibility is better
<FromGitter> <Blacksmoke16> fwiw, can any framework do that atm?
<FromGitter> <dscottboggs_gitlab> couldn't you just put instance in a module class method and then include the module in each "app" running in your app?
<FromGitter> <j8r> @dscottboggs_gitlab is quite right, that's also not a good practise overall
<FromGitter> <Blacksmoke16> separate apps meaning separate routes as well i assume?
<FromGitter> <j8r> @Blacksmoke16 do what?
<FromGitter> <grkek> Multiple apps @j8r
<FromGitter> <j8r> Examples 😀 https://github.com/grip-framework/gripen
<FromGitter> <j8r> haha
<FromGitter> <j8r> I suspect Lucky and Amber too?
<FromGitter> <Blacksmoke16> i mean are we talking about having two apps with separate routes running on the diff ports, or the same app running on separate ports?
<FromGitter> <dscottboggs_gitlab> different routes
<FromGitter> <grkek> The second one is possible
<FromGitter> <grkek> @Blacksmoke16
<FromGitter> <grkek> the first one is not possible in Grip ATM
<FromGitter> <j8r> yes two different apps, in the same binary, which can be an advantage
<FromGitter> <Blacksmoke16> same for athena. I think it would be doable as i have some abstractions that could allow for it but atm :shrug: is prob low priority compared to other stuff that could be done
<FromGitter> <grkek> @dscottboggs_gitlab The exception handling gives is done by matching over the exceptions and rendering different views for each and every error code, so basically you get more control over them.
<FromGitter> <grkek> @j8r I still see it as an optional improvement
<FromGitter> <dscottboggs_gitlab> oh ok. that's a good way to do it.
<FromGitter> <j8r> that's sure not very common
<FromGitter> <grkek> Ill show an example and youll understand what I mean
<FromGitter> <grkek> the raise function is overloaded
<FromGitter> <Blacksmoke16> oof
<FromGitter> <dscottboggs_gitlab> meh
<FromGitter> <naqvis> @j8r what's the reason behind using both inheritance and mixin in gripen? that seems confusing to me :P
<FromGitter> <j8r> @naqvis for example?
<FromGitter> <Blacksmoke16> what happens if you dont do that? just defaults to 500 or something?
<FromGitter> <grkek> here it catches the exception and renders it
<FromGitter> <grkek> @Blacksmoke16 yeah it defaults to 500
<FromGitter> <naqvis> ```struct Controller < Gripen::Controller ⏎ include Gripen::Controller::HTTP ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5f3ffadb5580fa092b14d02d]
<FromGitter> <dscottboggs_gitlab> wait I thought you couldn't inherit structs
<FromGitter> <j8r> ha that, because typically, you can include multiple controllers
<FromGitter> <Blacksmoke16> parent just has to be abstract
<FromGitter> <dscottboggs_gitlab> oh ok
<FromGitter> <grkek> @Blacksmoke16 why oof?
<FromGitter> <grkek> I don't understand am I doing something wrong here? :D
<FromGitter> <j8r> @naqvis the `include` are Controller features to add (HTTP, WebSocket, StaticFile and more), but the object is a Controller
<FromGitter> <Blacksmoke16> seems quite verbose, like almost half of the controller logic is that resuce/case
<FromGitter> <grkek> I mean you can ignore it and just raise everything that occurs, it is optional
<FromGitter> <naqvis> yeah, but I still can't get my head around first doing the inheritance then I still need to include sth
<FromGitter> <grkek> it will just give more details about exceptions
<FromGitter> <naqvis> what's stopping the parent class in having this functionality?
<FromGitter> <Blacksmoke16> yea but wouldnt it make more sense map the error codes to exception types?
<FromGitter> <Blacksmoke16> then you could handle it higher up
<FromGitter> <naqvis> might be i'm thinking in different context here :P
<FromGitter> <grkek> I already have that @Blacksmoke16
<FromGitter> <j8r> @naqvis `Gripen::Controller` having everything, websocket, staticfile and all?
<FromGitter> <grkek> This just gives more detail to the exception
<FromGitter> <Blacksmoke16> right, but i mean making the framework handle ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ for you [https://gitter.im/crystal-lang/crystal?at=5f3ffbe99bad075eacca445b]
<FromGitter> <Blacksmoke16> or am i not understanding something correctly?
<FromGitter> <grkek> The incorrect password is a custom exception which inherits exception
<FromGitter> <grkek> it is defined not by the framework but by the project
<FromGitter> <naqvis> @j8r not asking to bloat the parent class, but can have different parent classes for different purposes
<FromGitter> <grkek> which uses grip
<FromGitter> <grkek> so basically you cant raise a context exception without the context
<FromGitter> <Blacksmoke16> right, but if you did something like https://athena-framework.github.io/athena/Athena/Routing/Exceptions/HTTPException.html, you could look for instances of `HTTPException`, and handle it that way
<FromGitter> <grkek> and when you raise a non context error from a db component or something u do not have context there
<FromGitter> <j8r> @naqvis yeah, but how can you compose them then? One may need HTTP + WS, an other only HTTP, an other just StaticFile etc
<FromGitter> <Blacksmoke16> versus needing to catch the custom ex and map it to a response manually
<FromGitter> <grkek> I have that already
<FromGitter> <naqvis> agree, then why not just with mixins?
<FromGitter> <naqvis> i mean mixing both seems confusing to me
<FromGitter> <naqvis> just having some open discussion here :P
<FromGitter> <Blacksmoke16> you do, but the user has to define those mapping manually
<FromGitter> <grkek> they don't have to
<FromGitter> <grkek> they are optional
<FromGitter> <grkek> if they want to they will
<FromGitter> <j8r> @naqvis So having ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f3ffca8d4f0f55ebbd06acc]
<FromGitter> <grkek> since this will give more details to the error
<FromGitter> <grkek> for example generic 401 will just go and render 401
<FromGitter> <Blacksmoke16> ok, so what would happen if you did `raise IncorrectPassword.new "Invalid Password"` and didnt have a `when Bakuriani::Exceptions::Users::IncorrectPassword`?
<FromGitter> <dscottboggs_gitlab> I agree this example is good @j8r
<FromGitter> <grkek> it will render
<FromGitter> <grkek> 500 with the invalid password
<FromGitter> <grkek> text
<FromGitter> <dscottboggs_gitlab> I feel like this is a problem with Crystal though, having both inheritance and mixins, and doesn't that come from ruby?
<FromGitter> <grkek> since that exception doesn't belong to the library it needs to be mapped
<FromGitter> <grkek> you can just return 401 and raise the error
<FromGitter> <grkek> would do the same
<FromGitter> <j8r> That was a question @dscottboggs_gitlab , because I did with both inheritance and composition 😅
<FromGitter> <grkek> but you would need the context
<FromGitter> <grkek> if you returned a response with an 401
<FromGitter> <grkek> or raised an error
<FromGitter> <grkek> or whatever else
<FromGitter> <grkek> it would go to the 401 handler
<FromGitter> <j8r> Actually there is ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ I prefer the first because It is obvious the includes are controller features [https://gitter.im/crystal-lang/crystal?at=5f3ffd4249148b41c96323e4]
<FromGitter> <grkek> The basic idea here is that you map out what errors do what
<FromGitter> <grkek> since you dont get to have the context object with you in the other components of the app
<FromGitter> <grkek> otherwise you would need to pass context down to the exceptions
<FromGitter> <naqvis> @j8r yeah, and shouldn't `include Gripen::Controller::HTTP` be `Controller` in itself?
<FromGitter> <naqvis> sorry, haven't gone through gripen codebase, so don't know things in details
<FromGitter> <grkek> @Blacksmoke16 do you understand now?
<FromGitter> <naqvis> I was just looking at examples, so thought of asking the design decisions
<FromGitter> <j8r> @naqvis sure, that's good questions!
<FromGitter> <j8r> Can't be, because as said above, we can need a Controller which has WebSocket and StaticFile support for instance
<FromGitter> <j8r> or HTTP + WS, etc
<FromGitter> <naqvis> yeah, but why not `HTTP` , `WebSocket` inherit `Controller`?
<FromGitter> <Blacksmoke16> @grkek I do, but is that the best approach? The athena equivalent would be like, which IMO is a much cleaner approach...
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f3ffe40ec534f584fb1ceb4]
<FromGitter> <naqvis> because from examples its obvious that for one to write `Controller`, they need to inherit from `Controller` and then use mixin for specific http or ws functionality
<FromGitter> <j8r> @naqvis but, how can you then include them if they are classes/structs?
<FromGitter> <Blacksmoke16> then could add whatever context you wanted to this type
<FromGitter> <Blacksmoke16> the framework should ideally handle all that boilerplate
<FromGitter> <naqvis> if going with mixin approach, then replace inheritance with inclusion in my above sentence
<FromGitter> <grkek> @Blacksmoke16 If you look at the structure you can see that my database layer is in a different module
<FromGitter> <j8r> @naqvis not sure to see the advantage though?
<FromGitter> <grkek> @Blacksmoke16 I want to handle raised exceptions from the database layer
<FromGitter> <j8r> using inheritance differentiate controllers features vs base object, it should be clearer?
<FromGitter> <grkek> how would you do that?
<FromGitter> <naqvis> only advantage i see is consistency from user perspective
<FromGitter> <Blacksmoke16> have a parent exception type that your custom types inherit from, then do something like https://github.com/athena-framework/athena/blob/master/src/error_renderer.cr#L8-L14
<FromGitter> <Blacksmoke16> like around the `call_next` in the handler?
<FromGitter> <grkek> I don't use call_next
<FromGitter> <grkek> the endpoint is the deadend to the request
<FromGitter> <grkek> for the http controllers
alexherbo2 has quit [Remote host closed the connection]
<FromGitter> <Blacksmoke16> so theres nothing in between the request coming into the application and the controller action?
<FromGitter> <Blacksmoke16> something has to handle calling the right thing
<FromGitter> <grkek> It is
<FromGitter> <grkek> the router
<FromGitter> <grkek> basically its kemal
<FromGitter> <grkek> but object oriented
<FromGitter> <grkek> with a slapped on routing sugar
<FromGitter> <Blacksmoke16> fair enough
<FromGitter> <grkek> the exceptions are handled when they are default defined by the library
<FromGitter> <grkek> if they are not defined they go to the 500 handler
<FromGitter> <grkek> if you define an exception in your app and register it you need to route it as well so it doesnt go to 500 again
<FromGitter> <grkek> and it goes to the appropriate error code
<FromGitter> <grkek> that is why the raise function is overloaded so you can specify the error and the response code at the same time
<FromGitter> <grkek> and since you do not have the context with which you can specify the error code you need to match over the errors so you can define the proper error code for the proper exception
<FromGitter> <Blacksmoke16> i think we just have diff views on how it should work. All im saying is why shouldnt the error class be tied to the code?
<FromGitter> <grkek> it sounds verbose, looks verbose but provides cleaner and better structure
<FromGitter> <grkek> It is tied to the code
<FromGitter> <grkek> the grip code
<FromGitter> <grkek> everything else you define other than grip code
<FromGitter> <Blacksmoke16> but its not if you have to manually give the code
<FromGitter> <grkek> is loose code
<FromGitter> <grkek> you mean the response code
<FromGitter> <grkek> hm
<FromGitter> <Blacksmoke16> `raise context, exception, 401`
<FromGitter> <Blacksmoke16> `raise context, exception` where `exception` knows its a 401
<FromGitter> <grkek> shit youre right
<FromGitter> <grkek> if the exception itself has a property of status_code
<FromGitter> <grkek> you can just do automatic raise for the status code
<FromGitter> <grkek> god damn youre a genius
<FromGitter> <Blacksmoke16> yes, then you can introduce inheritance to tell the framework "this exception maps to an HTTP error code"
<FromGitter> <Blacksmoke16> and handle those at a higher level
<FromGitter> <Blacksmoke16> like i linked earlier
<FromGitter> <grkek> So
<FromGitter> <grkek> you define an exception and define the status code it belongs to
<FromGitter> <grkek> and when raised
<FromGitter> <grkek> you get the status code for it and raise it for the status code it raised in the first place
<FromGitter> <grkek> basically i need to create a base class for exceptions and inherit them
<FromGitter> <Blacksmoke16> and the related types in that directory
<FromGitter> <grkek> Mega-based thats nice
<FromGitter> <grkek> I like that code, thank you yet again ;)
<FromGitter> <Blacksmoke16> time for `2.0.0` 😉
<FromGitter> <grkek> ah the jokes
<FromGitter> <grkek> not really
<FromGitter> <grkek> time for a 1.0.1
<FromGitter> <Blacksmoke16> its a breaking change, has to be a major now
<FromGitter> <grkek> this is my first time doing this so please dont insult me too much
<FromGitter> <grkek> Ill just re-release the 1.0.0
<FromGitter> <grkek> no one is using it right now
<FromGitter> <grkek> no one can use it
<FromGitter> <grkek> since I am using crystal 1.0.0 already
<FromGitter> <grkek> for that
<FromGitter> <grkek> which cant be installed
<FromGitter> <grkek> so basically you get 0.29.0 anyway
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <grkek> I know sounds stupid:D
<FromGitter> <grkek> thank you mate
<FromGitter> <j8r> @naqvis But what stops someone to include everything in a single object?
<FromGitter> <j8r> One can include Controller into a Parameter, Server, Handler object, or whatever
<FromGitter> <jwoertink> Is there a shorter way to write this? `thing.run { |x| x }`
<FromGitter> <j8r> `thing.run { }`?
<FromGitter> <grkek> without the args
<FromGitter> <Blacksmoke16> `thing.run &.itself`
<FromGitter> <Blacksmoke16> i think
<FromGitter> <jwoertink> the block has to return the arg.
<FromGitter> <jwoertink> ah, I'll try that
<FromGitter> <jwoertink> sweet! Thanks @Blacksmoke16 that works.
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <naqvis> @j8r sure thing. Please don't take my comments as criticism, it was just some random thoughts :P
<FromGitter> <j8r> no problem, also I don't mind crititics
<FromGitter> <naqvis> 👍
<FromGitter> <j8r> I think it makes sense on my case, to force an object to be only 1 thing.
<FromGitter> <j8r> module should act as components, right?
HumanG33k has joined #crystal-lang
<FromGitter> <grkek> @Blacksmoke16 Literally removed the entire rescue block
<FromGitter> <grkek> and migrated the heavy lifting towards the framework
<FromGitter> <grkek> works perfectly
<FromGitter> <Blacksmoke16> 👍 well done
<FromGitter> <grkek> thank you for such a tip ;)
<FromGitter> <Blacksmoke16> np
_whitelogger has quit [Ping timeout: 240 seconds]