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
notzmv has quit [Ping timeout: 250 seconds]
notzmv has joined #crystal-lang
notzmv has quit [Ping timeout: 252 seconds]
ua_ has quit [Excess Flood]
ua_ has joined #crystal-lang
ur5us__ has quit [Ping timeout: 256 seconds]
<FromGitter> <Blacksmoke16> it's usually considered a bad idea to inherit from stdlib types like that
ur5us__ has joined #crystal-lang
notzmv has joined #crystal-lang
<riza> well, that may be true... but it seems like .clone and .dup should work regardless
notzmv has quit [Ping timeout: 245 seconds]
notzmv has joined #crystal-lang
<riza> is BigFloat just for arbitrarly large (as in magnitude) numbers? Or is it also capable of representing arbitrarly precise floats numbers
<FromGitter> <HertzDevil> it has a default precision of 64 bits in the mantissa
<riza> I remember knowing how to figure out if that was enough, but I no longer know that
notzmv has quit [Ping timeout: 240 seconds]
ua_ has quit [Ping timeout: 258 seconds]
ua_ has joined #crystal-lang
ua_ has quit [Ping timeout: 272 seconds]
ua_ has joined #crystal-lang
riza has quit [Read error: Connection reset by peer]
ur5us__ has quit [Ping timeout: 272 seconds]
notzmv has joined #crystal-lang
debayer has joined #crystal-lang
ua_ has quit [Ping timeout: 258 seconds]
ua_ has joined #crystal-lang
notzmv has quit [Ping timeout: 258 seconds]
debayer has quit [Quit: Client closed]
ins0mni4c has joined #crystal-lang
ins0mni4c has quit [Client Quit]
debayer has joined #crystal-lang
HumanG33k has quit [Ping timeout: 258 seconds]
HumanG33k has joined #crystal-lang
debayer has quit [Quit: Textual IRC Client: www.textualapp.com]
notzmv has joined #crystal-lang
riza has joined #crystal-lang
maxpowa has joined #crystal-lang
notzmv has quit [Ping timeout: 272 seconds]
SamantazFox has joined #crystal-lang
<raz> does spec have a macro hook or callback that fires when a test fails? i wanna capture logging at debug level and dump it to the screen when a test fails, but only then.
<raz> `after_suite` might do what i want, but how do i find out whether it succeeded, hmm
<FromGitter> <Blacksmoke16> not that im aware of
<raz> will try an experiment with clearing log in before_each, after_each and dumping to screen in after_suite
<FromGitter> <Blacksmoke16> maybe checkout https://crystal-lang.org/api/master/Log.html#capture(source:String=%22*%22,level:Severity=Log::Severity::Trace,*,builder=Log.builder,&)-class-method
<raz> ohhh, that looks promising
<FromGitter> <Blacksmoke16> dont think its exactly what you want tho
<raz> hmm indeed, looks like it's not intended to actually print the log
<raz> but well, the capturing part is easy anyway (MemoryBackend). just hope that `after_each` won't fire when a spec fails
<FromGitter> <plambert> Can anyone quickly point me to an example of reading a JSON config file, that handles exceptions (missing file, malformed JSON, etc) well?
<FromGitter> <plambert> By "well" I mean I want to create the file and dir path if they're missing, with default configs... and if it's malformed, I want to say it's malformed, not throw an exception and trace...
<FromGitter> <plambert> Thanks, @Blacksmoke16
<FromGitter> <Blacksmoke16> well you're going to need to handle most of that yourself
<FromGitter> <Blacksmoke16> at least the former
<FromGitter> <plambert> Right. I'm pretty sure I'm not the first person to do this, so I figured I'd look for an example of how someone else did it.
<FromGitter> <plambert> My first pass at it isn't very elegant, and is very hard to follow...
<FromGitter> <Blacksmoke16> whats it look like?
<FromGitter> <plambert> It's pretty ugly, and will be uglier when I add support for environment variables…
<FromGitter> <plambert> I'm just trying to find a way to make it easier to follow
<FromGitter> <Blacksmoke16> prob dont need to use pull parser in this context
<FromGitter> <plambert> what do you recommend?
<FromGitter> <Blacksmoke16> just have a config type with default values, then have your create method check if the file exists, if not to like `File.write path, Config.new.to_json`
<FromGitter> <Blacksmoke16> otherwise do a `Config.from_json file_contents`
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/JSON/Serializable.html#extensions-jsonserializablestrict-and-jsonserializableunmapped the strict one can also be used if you want to forbit extranous properties
<FromGitter> <plambert> OK, so I'd make a …::Config class, include JSON::Serializable and JSON::Serializable::Unmapped (because I want to preserve unknown keys), give it a read_file class method, and a write_file instance method... I think I get it.
<FromGitter> <plambert> I'll give it a shot. Thanks for pointing me in that direction.
<FromGitter> <Blacksmoke16> sounds good
<FromGitter> <plambert> Hmm... I was trying to avoid as many nillable properties in my main object as I could...
<FromGitter> <Blacksmoke16> give them default values then?
<FromGitter> <plambert> But if I make a Config class, it'll have to allow things like token to be nilable
<FromGitter> <plambert> There's no default value for an OAuth token, for example.
<FromGitter> <Blacksmoke16> how did you have it not be nilable before then?
<FromGitter> <Blacksmoke16> just using a hash?
<FromGitter> <plambert> No, I call Thing.create instead of Thing.new
<FromGitter> <plambert> And create reads the config file, and if there's no token, or the token is expired, does the OAuth stuff to get a new one
<FromGitter> <plambert> *then* creates the Thing
<FromGitter> <plambert> That way Thing.initialize can require the token exist and be valid, and I don't have to pepper my code with checks for nil
<FromGitter> <Blacksmoke16> cant just include that logic in there still?
<FromGitter> <Blacksmoke16> doesnt have to be `.new.to_json` `.create.to_json` would be fine too
<FromGitter> <plambert> I'll think about it. There has to be a way. And what I'm doing now *works* so I can survive with it, it's just hard to follow
<FromGitter> <Blacksmoke16> your current implementation could prob be easier if you just check if it exists first
<FromGitter> <Blacksmoke16> and use `Hash(String, String).from_json contents`
ur5us__ has joined #crystal-lang