02:28
f1reflyylmao has joined #crystal-lang
02:32
f1refly has quit [Ping timeout: 268 seconds]
02:32
f1reflyylmao is now known as f1refly
02:32
fifr` has quit [Ping timeout: 252 seconds]
02:37
aquijoule_ has joined #crystal-lang
02:39
richbridger has quit [Ping timeout: 240 seconds]
06:03
fifr` has joined #crystal-lang
06:06
_ht has joined #crystal-lang
08:06
hendursa1 has joined #crystal-lang
08:09
hendursaga has quit [Ping timeout: 240 seconds]
09:12
postmodern has joined #crystal-lang
09:12
mps has quit [Ping timeout: 276 seconds]
09:13
mps has joined #crystal-lang
10:22
hsh has joined #crystal-lang
10:24
* 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?
10:26
<
hsh >
so for instance if I have
10:26
<
hsh >
JSON.mapping({
10:26
<
hsh >
name: {type: String?, presence: false, nilable: true},
10:26
<
hsh >
language: {type: String?, presence: false, nilable: true}
10:27
* hsh
I'll have an entry `def language : Union(String, Nil)?` in the module's doc
10:28
<
straight-shoota >
JSON.mapping is no longer supported
10:28
<
straight-shoota >
but yes, that would be the expected output when JSON.mapping was a thing
10:30
<
hsh >
(I'm using Crystal 1.0.0)
10:31
<
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
10:32
<
straight-shoota >
I'd konsider it deprecated
10:32
* hsh
oh, I see. thanks. Is there anything similar in the ecosystem?
10:35
* hsh
wow, that's incredible. guess I have some porting to do... :) thanks!
10:35
<
straight-shoota >
how did you end up with json_mapping without knowing about JSON::Serializable?
10:38
<
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.
10:38
<
hsh >
I guess 2 years ago `json_mapping` was the way to do it :)
10:39
<
hsh >
I saw that json mapping had gone to an outside repo, but didn't see the new Serializable
10:40
<
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
10:40
<
straight-shoota >
And at that point you shoud've been made aware of the replacement
10:41
<
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
10:41
<
hsh >
all my projects were hobby stuff, so even if I didn't touched them for 2 years, no one would complain :)
10:43
<
hsh >
that's a good idea
10:47
deavmi has quit [Ping timeout: 246 seconds]
10:55
deavmi has joined #crystal-lang
11:40
mipmip has quit [Ping timeout: 252 seconds]
14:04
ua has quit [Ping timeout: 240 seconds]
14:19
ua has joined #crystal-lang
15:18
DTZUZU_ has joined #crystal-lang
15:20
DTZUZU has quit [Ping timeout: 268 seconds]
15:23
<
FromGitter >
<zomatree0:matrix.org> is there a way to eval code from a string?
15:23
<
FromGitter >
<Blacksmoke16> not at runtime
15:35
DTZUZU has joined #crystal-lang
15:38
DTZUZU_ has quit [Ping timeout: 265 seconds]
16:04
<
FromGitter >
<Blacksmoke16> well i suppose you could pass it to like `crystal eval` but :shrug:
16:10
sorcus has quit [Ping timeout: 246 seconds]
16:42
<
FromGitter >
<Daniel-Worrall> You'd have to include the compiler in your project :^)
16:42
<
FromGitter >
<Daniel-Worrall> or include a different language's runtime
16:55
<
FromGitter >
<jrei:matrix.org> using eval is generally no advised
16:56
<
FromGitter >
<jrei:matrix.org> what's possible is to broad. what do you want to do?
17:06
hendursa1 has quit [Remote host closed the connection]
17:07
hendursa1 has joined #crystal-lang
18:38
f1refly has quit [Quit: see ya in hell]
18:38
f1refly has joined #crystal-lang
18:43
DTZUZU_ has joined #crystal-lang
18:45
DTZUZU has quit [Ping timeout: 240 seconds]
18:55
f1refly has quit [Ping timeout: 258 seconds]
18:59
sorcus has joined #crystal-lang
19:02
<
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
19:03
<
FromGitter >
<Blacksmoke16> unit tests :)
19:06
<
FromGitter >
<zomatree0:matrix.org> its hard to unit test an api wrapper
19:07
<
FromGitter >
<zomatree0:matrix.org> as i would need to either send loads of request or fake requests
19:07
<
FromGitter >
<Blacksmoke16> theres a shard to mock request/resposnes
19:08
<
FromGitter >
<Blacksmoke16> wont catch changes/issues with upstream API but could at least ensure your lib handles various cases as expected
19:12
<
FromGitter >
<zomatree0:matrix.org> whats the best way to turn `Bool | Nil` into `true` or `false`, `false` if its `nil` else the bool value
19:12
<
FromGitter >
<Blacksmoke16> `true == val`?
19:12
<
FromGitter >
<Blacksmoke16> or really `val`
19:12
<
FromGitter >
<Blacksmoke16> `false` and `nil` are the only falsey values so can just use it as is?
19:13
f1refly has joined #crystal-lang
19:16
f1refly has quit [Client Quit]
19:17
f1refly has joined #crystal-lang
19:37
f1refly has quit [Quit: see ya in hell]
19:38
f1refly has joined #crystal-lang
19:48
f1refly has quit [Quit: see ya in hell]
19:49
f1refly has joined #crystal-lang
20:03
<
FromGitter >
<Blacksmoke16> `!!val` if you actually need a `Bool` instance`
20:03
_ht has quit [Remote host closed the connection]
20:32
mipmip has joined #crystal-lang
20:53
f1reflyylmao has joined #crystal-lang
20:54
f1refly has quit [Ping timeout: 240 seconds]
20:54
f1reflyylmao is now known as f1refly
21:54
f1reflyylmao has joined #crystal-lang
21:54
f1refly has quit [Ping timeout: 245 seconds]
21:54
f1reflyylmao is now known as f1refly
22:30
HumanG33k has quit [Remote host closed the connection]
22:32
HumanG33k has joined #crystal-lang
23:35
<
FromGitter >
<Blacksmoke16> `if nick = data["nick"]?`
23:36
<
FromGitter >
<Blacksmoke16> or `nick = data["nick"]?.try &.as_s`
23:38
<
FromGitter >
<zomatree0:matrix.org> even with `.try &.as_s` im getting the same error
23:38
<
FromGitter >
<zomatree0:matrix.org> i did look at serializable but i didnt think it gave me enough flexability for what i want
23:39
<
FromGitter >
<Blacksmoke16> no? should be much easier that working with `JSON::Any`
23:39
<
FromGitter >
<Blacksmoke16> than working*
23:39
<
FromGitter >
<Blacksmoke16> and can you share the full code? `.try &.as_s` should totally work assuming you're also doing like `data["nick"]?`
23:42
<
FromGitter >
<zomatree0:matrix.org> ```def parse_obj(data : JSON::Any)```
23:42
<
FromGitter >
<zomatree0:matrix.org> shit woops i pressed enter
23:43
<
FromGitter >
<zomatree0:matrix.org> thats the bit thats relevent
23:45
<
FromGitter >
<Blacksmoke16> oh i wonder if `try` doesnt work on `JSON::Any` nil types
23:45
<
FromGitter >
<Blacksmoke16> because it would be like `JSON::Any.new(nil)` not `nil`
23:48
<
FromGitter >
<Blacksmoke16> prob could do `.try &.as_s?`
23:48
<
FromGitter >
<Blacksmoke16> but id still suggest trying to use serializable if the data's structure is known ahead of time