RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.1 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
<fullforce> wow this question is gonna sound dumb but bear with me
<fullforce> I want to return an object with values, whats the best way to do this?
<fullforce> just create a class and assign all the vars in #initialize?
<FromGitter> <Blacksmoke16> that would be one way
<FromGitter> <Blacksmoke16> are the values static? where do the values come from? will this object be edited elsewhere or is it immutable?
<fullforce> dynamic
<fullforce> they will not be edited
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/0.27.2/toplevel.html#record(name,*properties)-macro
<FromGitter> <Blacksmoke16> might be the way to go then
<FromGitter> <dscottboggs_gitlab> could you provide a JSON example of the object? or does it have inconsistent keys
<fullforce> awesome
<fullforce> dscottboggs: yeah sure
<fullforce> {"nick": "blah", "ident": "test", "host": "test.host"}
<fullforce> i like blacksmokes solution
<FromGitter> <Blacksmoke16> is your object coming from a json string?
<FromGitter> <Blacksmoke16> er the data
<FromGitter> <dscottboggs_gitlab> yup `record` works
<FromGitter> <dscottboggs_gitlab> I was just going to suggest defining a struct but record does that so ¯\_(ツ)_/¯
<FromGitter> <Blacksmoke16> :P
<FromGitter> <Blacksmoke16> if his data is coming from json it would be even easier for him
<FromGitter> <dscottboggs_gitlab> why's that?
<FromGitter> <Blacksmoke16> `.from_json` vs having to call `.new xxx`
<FromGitter> <dscottboggs_gitlab> hm?
<FromGitter> <Blacksmoke16> would be able to call `from_json` on his string which would set the values automatically vs having to do like `obj = Obj.new "blah", "test", "test.host"` etc
<FromGitter> <dscottboggs_gitlab> Oh I see
<FromGitter> <Blacksmoke16> but sounds like its not so oh well
<FromGitter> <Blacksmoke16> found a work around for that module validation bug i found
<FromGitter> <Blacksmoke16> bit less clean but it works so meh
<FromGitter> <dscottboggs_gitlab> talkin to me?
<FromGitter> <Blacksmoke16> yea :P
<FromGitter> <dscottboggs_gitlab> I haven't been around too much...busy.... ⏎ ⏎ mind referencing the bug? :p
<FromGitter> <Blacksmoke16> i noticed, i miss you :P
<FromGitter> <dscottboggs_gitlab> sorry, got a job haha
<FromGitter> <Blacksmoke16> writing crystal at least?
<FromGitter> <dscottboggs_gitlab> well...one of them... but that's not the one that pays the bills. Things have been going well, I just wish the safety Crystal offered was more common haha. People at my new job write mainly python and I've already found at least one bug caused by null references...
<FromGitter> <Blacksmoke16> 😬
<FromGitter> <Blacksmoke16> gotta show them the light
<FromGitter> <dscottboggs_gitlab> yeah...I'm just glad to not be working retail anymore haha
<FromGitter> <Blacksmoke16> we recently upgraded to PHP 7.1 at work, gives *some* type safety as you can specify return/argument types now, but still only happens at runtime afaik
<FromGitter> <Blacksmoke16> or at build time, since there isnt really compile time
<FromGitter> <Blacksmoke16> ah jezz, anythings better than that ha
<FromGitter> <dscottboggs_gitlab> "ha"?
<FromGitter> <Blacksmoke16> ha?
<FromGitter> <dscottboggs_gitlab> oh I see
<FromGitter> <Blacksmoke16> mhm
<FromGitter> <dscottboggs_gitlab> but @j8r hired me to build the API for his (really cool) DPPM (https://github.com/dfabric/dppm) project, so I've been doing that every free minute I have basically haha
<FromGitter> <Blacksmoke16> ah nice, hows that going?
<FromGitter> <Blacksmoke16> hehe should have used athena 😏
<FromGitter> <dscottboggs_gitlab> flix is working as long as you *preformat* the video, so to really be useful it will need to be integrated with `libav.cr` with a standard, well-tested format sent from the server to the client
<FromGitter> <Blacksmoke16> wait what, whats his thing have to do with videos?
<FromGitter> <dscottboggs_gitlab> nothign I just was talking about another thing before you replied to my first message
<FromGitter> <Blacksmoke16> ohh right
<FromGitter> <Blacksmoke16> gotcha
<FromGitter> <dscottboggs_gitlab> I actually thought about it because we're using RBAC which seemed like it would integrate well with Athena's routing system, but I was more familiar with Kemal and you were refactoring Athena at the time. So maybe next time :p
<FromGitter> <dscottboggs_gitlab> RBAC is not easy lol
<FromGitter> <Blacksmoke16> all good
<FromGitter> <Blacksmoke16> you see the changes i did to it?
<FromGitter> <Blacksmoke16> for CORS/custom handlers?
<FromGitter> <dscottboggs_gitlab> not yet, how's it going?
<FromGitter> <Blacksmoke16> https://github.com/Blacksmoke16/athena/blob/master/docs/routing.md#cors custom handler stuff is below cors
<FromGitter> <Blacksmoke16> turned out pretty good id say, super flexible
<FromGitter> <Blacksmoke16> easy to setup for global cors, or can define groups to use on a per controller/action basis
<FromGitter> <Blacksmoke16> then i overloaded the HTTP::Handler to give middleware access to like matched route and the config obj
<FromGitter> <Blacksmoke16> pretty slick
<FromGitter> <Blacksmoke16> next thing id like to do is try and auto generate swagger docs from the route defs. should be able to do most of it automatically. Also could like annotate your models and generate schemas for those too. See how it goes
<FromGitter> <dscottboggs_gitlab> wow that looks really solid
<FromGitter> <dscottboggs_gitlab> swagger docs?
* FromGitter * dscottboggs_gitlab must hit the hay ✌️
<FromGitter> <Blacksmoke16> o/
lucasb has quit [Quit: Connection closed for inactivity]
boughtly has joined #crystal-lang
<boughtly> i have a piece of code that throws an exception, except I can't seem to catch it with begin/rescue/end
<boughtly> I get an unhandled exception stacktrace
<boughtly> what could I be doing wrong
<boughtly> (I tried both rescue with the exception type exactly and with Exception)
DmitryBochkarev has joined #crystal-lang
DmitryBochkarev has quit [Max SendQ exceeded]
DmitryBochkarev has joined #crystal-lang
<boughtly> Ha. I found the issue. I am trying to throw an exception when divising a float64 by 0, so naturally I've opened the struct and overrode the division operator. However, this causes the program to fail to load because Float64::NAN tries to divide by zero for initialization
DmitryBochkarev has quit [Ping timeout: 246 seconds]
rohitpaulk has joined #crystal-lang
boughtly has quit [Ping timeout: 256 seconds]
rohitpaulk has quit [Remote host closed the connection]
DmitryBochkarev has joined #crystal-lang
fanta7531 has joined #crystal-lang
fifr has quit [Quit: ZNC 1.6.5 - http://znc.in]
fifr has joined #crystal-lang
marmotini_ has joined #crystal-lang
fifr has quit [Quit: ZNC 1.6.5 - http://znc.in]
fifr has joined #crystal-lang
Raimondi has quit [Quit: WeeChat 2.3: ¡Chau!]
marmotini has joined #crystal-lang
marmotini_ has quit [Ping timeout: 245 seconds]
DmitryBochkarev has quit [Remote host closed the connection]
DmitryBochkarev has joined #crystal-lang
ashirase has quit [Ping timeout: 244 seconds]
ashirase has joined #crystal-lang
<jokke> nice find :D
marmotini_ has joined #crystal-lang
marmotini has quit [Ping timeout: 245 seconds]
marmotini has joined #crystal-lang
marmotini_ has quit [Ping timeout: 246 seconds]
<FromGitter> <j8r> @Blacksmoke16 do the routes on Athena can be changed at runtime?
<FromGitter> <Blacksmoke16> no why?
<FromGitter> <Blacksmoke16> routes are added to the router at compile time upon initialization of the RouteHandler handler
<FromGitter> <j8r> For example `/api/this_will_change/config`
<FromGitter> <Blacksmoke16> could use a blob to match anything htere
<FromGitter> <Blacksmoke16> like `/api/*/config` i think would work?
<FromGitter> <j8r> I'm afraid it will also match `/api/what/ever/path/config`?
<FromGitter> <Blacksmoke16> how would `this_will_change` actually change then?
<FromGitter> <Blacksmoke16> just the name of it or?
<FromGitter> <Blacksmoke16> i mean in theory i could support multiple routes tied to the same action? if this is what you were thinking?
<FromGitter> <j8r> for example we have `get (root_path "/:app_name/config/:key")`
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cade1d9b34ccd69e795e2a8]
<FromGitter> <j8r> `root_path` is configurable, that's why it's done this way
<FromGitter> <Blacksmoke16> configurable at runtime?
<FromGitter> <Blacksmoke16> afk abit ,driving to work
<FromGitter> <j8r> hum nvm, no it's to avoid boilerplating
<FromGitter> <j8r> that's a macro
<FromGitter> <j8r> but app_name is dynamic
<FromGitter> <j8r> `:key` too
<FromGitter> <Blacksmoke16> yea so like
<FromGitter> <Blacksmoke16> would `GET /foo/config/bar` match the same action handler as `GET /bar/config/baz`?
<FromGitter> <Blacksmoke16> if the answer is yes you could just do like `@[Athena::Routing::Get(path: "/:app_name/config/:key")]` like normal
<FromGitter> <j8r> yep
<FromGitter> <Blacksmoke16> or even use a prefix on a parent controller to make all routes have that prefix
<FromGitter> <Blacksmoke16> https://github.com/Blacksmoke16/athena/blob/master/docs/routing.md#defining-routes notice the annotation on the controller class
<FromGitter> <Blacksmoke16> afk abit
<FromGitter> <j8r> Nice!
<FromGitter> <j8r> not really a fan of using structs in place of a module, with `self.` for every method, though
<FromGitter> <j8r> I remember you said to me you use structs and inheritance due to a limitation
fanta7531 has quit [Quit: fanta7531]
Raimondi has joined #crystal-lang
<FromGitter> <Blacksmoke16> @j8r Yea, once https://github.com/crystal-lang/crystal/pull/7648 is merged it would be possible, as you could just annotate a module with like `@[Athena::Routing::Controller]`
<FromGitter> <Blacksmoke16> but i kinda like the inheritance setup now. easily share methods between all controllers, callbacks get inherited, prefix would trickle down to child controllers (i think i have to fix this tho), etc
<FromGitter> <Blacksmoke16> main blocker would be coming up with an alternative to https://github.com/Blacksmoke16/athena/blob/master/docs/routing.md#accessing-requestresponse
<FromGitter> <Blacksmoke16> since atm those methods just get added to all controllers via inheritance
mistergibson has joined #crystal-lang
mistergibson has quit [Remote host closed the connection]
DmitryBochkarev has quit [Ping timeout: 250 seconds]
marmotini has quit [Remote host closed the connection]
DmitryBochkarev has joined #crystal-lang
mistergibson has joined #crystal-lang
<mistergibson> Question: Is there a method to call to list the methods of an object? (similar to ruby's .public_methods)
<FromGitter> <GaryMiller> Any guestemates on when Crystal will have Native Windows support based on current funding and resources? I've reviewed the tasks and message traffic but it's still hard to get a feel if end of summer or end of year is doable. Because I understand that with OpenSource a lot relies on what outside funding is available and where the interests of the major contributors lie.
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6pa0
<FromGitter> <Blacksmoke16> @mistergibson
<FromGitter> <mistergibson> @Blacksmoke16 : thanks
mistergibson has quit [Quit: Leaving]
<FromGitter> <Blacksmoke16> more so showing its possible with macro, however depending on your specific use case you're trying to do might not work
<FromGitter> <Blacksmoke16> got an example of what you're trying to do?
<FromGitter> <mistergibson> no, I'm surveying the general capabilities of Crystal just now
<FromGitter> <mistergibson> I use ruby's respond_to? etc quite a bit in my ruby code
<FromGitter> <mistergibson> Just wondering about this env.
<FromGitter> <Blacksmoke16> rgr
<FromGitter> <mistergibson> I think I'm smitten though - the ability to compile to native code is sexy
<FromGitter> <Blacksmoke16> indeed
<FromGitter> <parruda> Hey guys, how’s Crystal in terms of funding?
DmitryBochkarev has quit [Ping timeout: 268 seconds]
<FromGitter> <Blacksmoke16> also https://crystal-lang.org/sponsors/
DmitryBochkarev has joined #crystal-lang
DmitryBochkarev has quit [Max SendQ exceeded]
DmitryBochkarev has joined #crystal-lang
ua has quit [Ping timeout: 268 seconds]
ua has joined #crystal-lang
<FromGitter> <drum445> How can I make a custom to_json method in a class?
<FromGitter> <drum445> ``` def to_json ⏎ {"hp" => @hp}.to_json ⏎ end``` ⏎ ⏎ I get: `no overload matches 'Player#to_json' with type JSON::Builder` [https://gitter.im/crystal-lang/crystal?at=5cae21efc55bd14d35c1356e]
<FromGitter> <Blacksmoke16> ``` def to_json(builder : ::JSON::Builder) ⏎ {"hp" => @hp}.to_json ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5cae220cc55bd14d35c135e4]
<FromGitter> <Blacksmoke16> try that
<FromGitter> <Blacksmoke16> might have to pass builder to the inner `.to_json` as well
<FromGitter> <drum445> hmm: Exception: Empty JSON (JSON::Error)
<FromGitter> <Blacksmoke16> :thinking:
<FromGitter> <Blacksmoke16> can you make a playground link?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6pbt had to pass `builder` to child as well i guess
<FromGitter> <drum445> lovely, thanks a lot sir
<FromGitter> <mistergibson> @Blacksmoke16 : is there an 'eval' implementation you know of? I'd like to exec ruby-ish code generated on the fly.
<FromGitter> <Blacksmoke16> is `crystal eval 'puts "foo"'`
<FromGitter> <Blacksmoke16> or can run a local version of hte playground
<FromGitter> <r00ster91> or try `icr`
<FromGitter> <mistergibson> ok thanks
lucasb has joined #crystal-lang
<FromGitter> <mistergibson> @Blacksmoke16 : um, how would one invoke that *within* a compiled code situation?
<FromGitter> <Blacksmoke16> oh
<FromGitter> <mistergibson> as a macro it seems
<FromGitter> <Blacksmoke16> in *that* case maybe look at https://crystal-lang.org/api/0.27.2/Crystal/Macros.html#run%28filename%2C%2Aargs%29%3AMacroId-instance-method or like `Process.run`
<FromGitter> <mistergibson> ok
<FromGitter> <Blacksmoke16> probably is a better method of doing what you trying to do tho
<FromGitter> <Blacksmoke16> using eval within code seems a bit hacky
<FromGitter> <mistergibson> Well, I want to generate code and compile/run it from compiled code
<FromGitter> <mistergibson> in theory
<FromGitter> <mistergibson> hacky yes
<FromGitter> <Blacksmoke16> :P then check out that run macro method
<FromGitter> <mistergibson> ok
DmitryBochkarev has quit [Ping timeout: 245 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
thews_ has joined #crystal-lang
<FromGitter> <bew> But it'll still be at compile time only
thews_ has quit [Ping timeout: 250 seconds]
<FromGitter> <bararchy> We really need a way to tell HTTP::Params to encode in URI or x-form-urlencoded
<FromGitter> <straight-shoota> Now live: https://www.youtube.com/watch?v=JkKqkzCoR-8
<FromGitter> <Blacksmoke16> 👍
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
<FromGitter> <j8r> nice, thanks to the core team for the initiative ❤️
<FromGitter> <vladfaust> Loved it!
<FromGitter> <ryanstout> yea, thanks for all of the hardwork from the core team and the community. My team is just starting to work with Crystal and we're really enjoying it so far.
<FromGitter> <ryanstout> unrelated to that, I finally managed to make a simple example that causes this "macro '......' must be defined before this point but is defined later" Even though it is defined. It only happens when its in a default variable assignment. ⏎ https://play.crystal-lang.org/#/r/6pe0 Is there something I'm missing here, or is this a bug? (the macro is defined before its used)
<FromGitter> <bew> Weird indeed, I'd say it's a bug
<FromGitter> <ryanstout> @bew ok, I figured, but I'm new to Crystal and wanted to make sure I wasn't doing something incorrectly
boughtly has joined #crystal-lang
<FromGitter> <rumenzu> Thanks to the core team for addressing my questions in the Q&A, I missed the live but watching it now
<boughtly> Is there a way to pass a symbol to a method and use it as a key in a double splat?
<boughtly> def call_splat(key, value) foo(key: value) end doesn't work :( it makes a key thatr's the literal symbol ":key")
<FromGitter> <bew> Those things must be known at compile time
<FromGitter> <straight-shoota> @ryanstout Looks like a bug. Care to open an issue?
<FromGitter> <ryanstout> yea, will do. Thanks
<boughtly> I have a generic class Foo(T). I have a macro baz defined in class Bar. If I have a Foo(Bar) and I try to include T.baz in the body of the class Foo(T), it tells me T is undefined
<boughtly> Is there a way around this?
<FromGitter> <Blacksmoke16> @z64 you around?
<FromGitter> <Blacksmoke16> well major breaking change to athena but its now concurrent safe
tsundsted has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]