ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | 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
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 268 seconds]
f1reflyylmao is now known as f1refly
fifr` has quit [Ping timeout: 252 seconds]
aquijoule_ has joined #crystal-lang
richbridger has quit [Ping timeout: 240 seconds]
fifr` has joined #crystal-lang
_ht has joined #crystal-lang
hendursa1 has joined #crystal-lang
hendursaga has quit [Ping timeout: 240 seconds]
postmodern has joined #crystal-lang
mps has quit [Ping timeout: 276 seconds]
mps has joined #crystal-lang
hsh has joined #crystal-lang
* hsh I have some classes using `crystal-lang/json_mapping` and I notice that the docs created with `crystal docs` automatically pick up the bindings. That's quite cool! But how can I document the bindings?
<hsh> so for instance if I have
<hsh> class Entity
<hsh> JSON.mapping({
<hsh> ```crystal
<hsh> name: {type: String?, presence: false, nilable: true},
<hsh> language: {type: String?, presence: false, nilable: true}
<hsh> })
<hsh> end
<hsh> ```
* hsh I'll have an entry `def language : Union(String, Nil)?` in the module's doc
<straight-shoota> JSON.mapping is no longer supported
<straight-shoota> but yes, that would be the expected output when JSON.mapping was a thing
<hsh> this from the repo https://github.com/crystal-lang/json_mapping.cr, not the standard lib, is that deprecated as well?
<hsh> (I'm using Crystal 1.0.0)
<straight-shoota> Kind of. That shard is there to keep legacy code going for a bit longer, but it's unlikely to reveice any updates
<straight-shoota> I'd konsider it deprecated
* hsh oh, I see. thanks. Is there anything similar in the ecosystem?
<straight-shoota> Of course. JSON::Serializable is the reason why it got deprecated. https://crystal-lang.org/api/1.0.0/JSON/Serializable.html
* hsh wow, that's incredible. guess I have some porting to do... :) thanks!
<straight-shoota> how did you end up with json_mapping without knowing about JSON::Serializable?
<hsh> I've used Crystal a lot around 2 years ago, but then had to focus on other things. I've just picked it up again now with the 1.0 release.
<hsh> I guess 2 years ago `json_mapping` was the way to do it :)
<hsh> I saw that json mapping had gone to an outside repo, but didn't see the new Serializable
<straight-shoota> two years ago JSON.mapping was still in stdlib. At some point you must've pulled in the crystal-lang/json_mapping.cr shard as a replacement
<straight-shoota> And at that point you shoud've been made aware of the replacement
<hsh> I was literally starting a new project and saw that JSON mapping was not anymore, and saw that I could pull from that repo
<hsh> all my projects were hobby stuff, so even if I didn't touched them for 2 years, no one would complain :)
<straight-shoota> Well, the readme is not very clear on where things stand. Going to change that: https://github.com/crystal-lang/json_mapping.cr/pull/3
<hsh> that's a good idea
deavmi has quit [Ping timeout: 246 seconds]
deavmi has joined #crystal-lang
mipmip has quit [Ping timeout: 252 seconds]
ua has quit [Ping timeout: 240 seconds]
ua has joined #crystal-lang
DTZUZU_ has joined #crystal-lang
DTZUZU has quit [Ping timeout: 268 seconds]
<FromGitter> <zomatree0:matrix.org> is there a way to eval code from a string?
<FromGitter> <Blacksmoke16> not at runtime
DTZUZU has joined #crystal-lang
DTZUZU_ has quit [Ping timeout: 265 seconds]
<FromGitter> <Blacksmoke16> well i suppose you could pass it to like `crystal eval` but :shrug:
sorcus has quit [Ping timeout: 246 seconds]
<FromGitter> <Daniel-Worrall> You'd have to include the compiler in your project :^)
<FromGitter> <Daniel-Worrall> or include a different language's runtime
<FromGitter> <jrei:matrix.org> using eval is generally no advised
<FromGitter> <jrei:matrix.org> what's possible is to broad. what do you want to do?
hendursa1 has quit [Remote host closed the connection]
hendursa1 has joined #crystal-lang
f1refly has quit [Quit: see ya in hell]
f1refly has joined #crystal-lang
DTZUZU_ has joined #crystal-lang
DTZUZU has quit [Ping timeout: 240 seconds]
f1refly has quit [Ping timeout: 258 seconds]
sorcus has joined #crystal-lang
<FromGitter> <zomatree0:matrix.org> it was mostly for debug purposes so i can interact with stuff while its running to make sure everything is correct
<FromGitter> <Blacksmoke16> unit tests :)
<FromGitter> <zomatree0:matrix.org> its hard to unit test an api wrapper
<FromGitter> <zomatree0:matrix.org> as i would need to either send loads of request or fake requests
<FromGitter> <Blacksmoke16> theres a shard to mock request/resposnes
<FromGitter> <Blacksmoke16> wont catch changes/issues with upstream API but could at least ensure your lib handles various cases as expected
<FromGitter> <zomatree0:matrix.org> whats the best way to turn `Bool | Nil` into `true` or `false`, `false` if its `nil` else the bool value
<FromGitter> <Blacksmoke16> `true == val`?
<FromGitter> <Blacksmoke16> or really `val`
<FromGitter> <Blacksmoke16> `false` and `nil` are the only falsey values so can just use it as is?
f1refly has joined #crystal-lang
f1refly has quit [Client Quit]
f1refly has joined #crystal-lang
f1refly has quit [Quit: see ya in hell]
f1refly has joined #crystal-lang
f1refly has quit [Quit: see ya in hell]
f1refly has joined #crystal-lang
<FromGitter> <Blacksmoke16> `!!val` if you actually need a `Bool` instance`
_ht has quit [Remote host closed the connection]
mipmip has joined #crystal-lang
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 240 seconds]
f1reflyylmao is now known as f1refly
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 245 seconds]
f1reflyylmao is now known as f1refly
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
<FromGitter> <zomatree0:matrix.org> ```Unhandled exception in spawn: cast from Nil to String failed``` [https://gitter.im/crystal-lang/crystal?at=606655941dbd860a23274b90]
<FromGitter> <Blacksmoke16> `if nick = data["nick"]?`
<FromGitter> <Blacksmoke16> or `nick = data["nick"]?.try &.as_s`
<FromGitter> <Blacksmoke16> although id suggest looking into https://crystal-lang.org/api/master/JSON/Serializable.html versus using JSON.parse
<FromGitter> <zomatree0:matrix.org> even with `.try &.as_s` im getting the same error
<FromGitter> <zomatree0:matrix.org> i did look at serializable but i didnt think it gave me enough flexability for what i want
<FromGitter> <Blacksmoke16> no? should be much easier that working with `JSON::Any`
<FromGitter> <Blacksmoke16> than working*
<FromGitter> <Blacksmoke16> and can you share the full code? `.try &.as_s` should totally work assuming you're also doing like `data["nick"]?`
<FromGitter> <zomatree0:matrix.org> ```def parse_obj(data : JSON::Any)```
<FromGitter> <zomatree0:matrix.org> shit woops i pressed enter
<FromGitter> <zomatree0:matrix.org> thats the bit thats relevent
<FromGitter> <Blacksmoke16> oh i wonder if `try` doesnt work on `JSON::Any` nil types
<FromGitter> <Blacksmoke16> because it would be like `JSON::Any.new(nil)` not `nil`
<FromGitter> <Blacksmoke16> prob could do `.try &.as_s?`
<FromGitter> <Blacksmoke16> but id still suggest trying to use serializable if the data's structure is known ahead of time