<FromGitter>
<Blacksmoke16> requiring "json" *after* applying the nodoc
chachasmooth has quit [Ping timeout: 240 seconds]
chachasmooth has joined #crystal-lang
<FromGitter>
<sam0x17> @straight-shoota was cuz I wrote 300 lines of code not realizing that `[]=` wasn't a thing (because some macros were in progress as well) so did the lazy thing
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
rocx has quit [Ping timeout: 260 seconds]
rcvalle_ has joined #crystal-lang
_ht has joined #crystal-lang
_ht has quit [Remote host closed the connection]
<FromGitter>
<galvertez> hey guys i noticed something weird and i can't seem to figure out if it's a documentation issue or... something else? ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ since they're both defined more or less the same way - they are both contained w/in the namespace `OpenSSL::SSL::Socket` and both inherit from the abstract class of the same name [https://gitter.im/crystal-lang/crystal?at=5ebce7922cf0da0ad9fff000]
_ht has joined #crystal-lang
<FromGitter>
<galvertez> at first i thought "oh, yeah it makes sense, because it inherits from the socket so it includes itself in the namespace so it's valid, but the doc generator wouldn't know that
<FromGitter>
<galvertez> but then i couldn't do the same thing w/ `OpenSSL::SSL::Client` - it only works as `OpenSSL::SSL::Socket::Client`
<FromGitter>
<galvertez> i guess i don't really care either way, it's just a little confusing because i can't find anywhere in the openssl src that should make `OpenSSL::SSL::Server` work that wouldn't also make `OpenSSL::SSL::Client` work lol
<FromGitter>
<galvertez> so maybe somebody who's better at reading code can figure it out
bazaar has quit [Quit: leaving]
bazaar has joined #crystal-lang
DTZUZU has quit [Ping timeout: 260 seconds]
ua has quit [Ping timeout: 240 seconds]
alexherbo2 has joined #crystal-lang
ua has joined #crystal-lang
yxhuvud has quit [Remote host closed the connection]
Human_G33k has quit [Remote host closed the connection]
Human_G33k has joined #crystal-lang
Human_G33k has quit [Remote host closed the connection]
<raz>
of is one of my best friends, never lets me down
<jhass>
you can think of alias Foo = Bar as record Foo, value : Bar where crystal implicitly accesses value for you
<jhass>
and forwards all method calls
<yxhuvud>
at least historically, aliasing generics have been fraught with bugs though. so beware that any issues *may* not be your fault.
<raz>
hmm yep. i half-wonder if the compiler could actually figure it out itself w/o an explicit alias
<yxhuvud>
perhaps it is fixed now though
<raz>
well, that would be my first compiler bug ever. lookin forward to it!
<yxhuvud>
That's the spirit!
<raz>
will write a ticket of epic proportions and somehow blame it all on the existence of symbols in the end.
<raz>
that's the plan at least, will see how it goes
<jhass>
most of the alias compiler bugs can be worked around with a simple wrapper struct like above. It's just less convenient
<raz>
yup yup, not too worried. in this particular case i could also just write out the two hash variants i want to allow. but good to know about the alias-route for more complicated cases
<FromGitter>
<Uzay-G> oh ok. I am looking at the granite docs to see how I can run queries like that. Am i correct in thinking that this gets posts from the last 7 days: `Post.where(:created_at, :gt, Time.local - 7.days)`
<FromGitter>
<Uzay-G> what does the `:gt` operator do?
<FromGitter>
<Blacksmoke16> greater than
<FromGitter>
<Uzay-G> oh yeah lol 😄
<FromGitter>
<Blacksmoke16> that would get you posts created in last week
<FromGitter>
<Blacksmoke16> but id hope you're storing UTC in the db
<FromGitter>
<Blacksmoke16> thus `Time.utc` would prob be better here
<FromGitter>
<Uzay-G> i'm not sure. I will check how Granite handles its automatic timestamps.
<FromGitter>
<Blacksmoke16> 99% sure they're utc
<FromGitter>
<Uzay-G> ok thanks. I am going to find a way to get the time object of the current day at time 00:00 and use that to compare
<FromGitter>
<Uzay-G> So i can get all posts of the day
<FromGitter>
<Blacksmoke16> `Time.utc.at_beginning_of_day` would prob do it
<FromGitter>
<tenebrousedge> I don't want to say that hashes in Crystal are less useful than in Ruby, but in Crystal it's less useful to use hashes as an ad-hoc data structure. Having to type your hash as `Hash(String, Int32 | String)` is unpleasant
<FromGitter>
<xmonader> @Blacksmoke16 looks like that latest alpine has crystal 0.31 :(
<FromGitter>
<Uzay-G> but it works when i don't pass any arguments
<FromGitter>
<Uzay-G> has this happened before?
<FromGitter>
<Blacksmoke16> is possible your time is nil
<FromGitter>
<tenebrousedge> or nilable
<FromGitter>
<Blacksmoke16> ^
<FromGitter>
<watzon> Wait, did you just add ICR to DeBot?
<FromGitter>
<tenebrousedge> `try` is good
<FromGitter>
<Uzay-G> that's at compile time
<FromGitter>
<Blacksmoke16> or figure out if you can remove `nil` all together
<FromGitter>
<Uzay-G> and I tried using `not_nil!`
<FromGitter>
<Blacksmoke16> where if your time coming from?
<FromGitter>
<Blacksmoke16> can you share some code
<FromGitter>
<Uzay-G> oh no actually that worked
<FromGitter>
<Uzay-G> I had the same problem in two areas
<FromGitter>
<Uzay-G> so when i fixed problem 1 with `not_nil!`, I thought problem 1 still existed because there was the same problem :clumsy:
<FromGitter>
<Blacksmoke16> but is it impossible for it to be nil?
<FromGitter>
<Blacksmoke16> a better solution would be avoiding that union in the first place
<FromGitter>
<tenebrousedge> yis
<FromGitter>
<Uzay-G> yeah but again it's an automatic timestamp generated by granite
<FromGitter>
<Blacksmoke16> ah, via `timestamps` macro?
<FromGitter>
<Uzay-G> so I assume they must have that a Nil union
<FromGitter>
<Uzay-G> yeah
<FromGitter>
<Blacksmoke16> yea, since they wont have a value until its saved
<FromGitter>
<Blacksmoke16> prob could define those with `property!` tho
<FromGitter>
<Blacksmoke16> is one of my bigger questions in regards how to best handle it
<FromGitter>
<Blacksmoke16> in reality those columns are not nilable
<FromGitter>
<Blacksmoke16> but they have to be nilable on the model, similar to the PK
<FromGitter>
<tenebrousedge> hmmmmm
<FromGitter>
<Blacksmoke16> so you lose compile time saftey, but idk how else you would handle that
<FromGitter>
<Blacksmoke16> w/o going into crazy `uninitialized` stuff
<FromGitter>
<tenebrousedge> I dunno, it sounds like they would have to be nilable, unless an unsaved record had a different type
<FromGitter>
<Blacksmoke16> yea, so runtime checks are best you're going to get
<FromGitter>
<Blacksmoke16> kinda unfortunate, but makes the whole model much easier to work with. like partial hydration, etc
Dreamer3 has joined #crystal-lang
DTZUZU has joined #crystal-lang
<oprypin>
i have `class A; def initialize(x); end; end; class B; def initialize(x, y); end; end`. can I define a method that implicitly refers to the base `new`? like `class B; def foo; self.new(x: 1); end; end`
<oprypin>
important correction
<oprypin>
i have `class A; def initialize(x); end; end; class B < A; def initialize(x, y); end; end`. can I define a method that implicitly refers to the base `new`? like `class B < A; def foo; self.new(x: 1); end; end`
<FromGitter>
<tenebrousedge> `previous_def` is a thing
<FromGitter>
<bararchy> This is a working example to make custom level on 0.34.0, it still is a bummer that I can't just make new Severity :\ I guess I need two Log now
<FromGitter>
<bararchy> yeha, fully aware :\ hence, define two logs
<FromGitter>
<bararchy> hahaha
<FromGitter>
<Blacksmoke16> imo you could get the same effect using metdata
<FromGitter>
<Blacksmoke16> if given, use that, otherwise fallback on `entry#severity`
<FromGitter>
<Blacksmoke16> :shrug:
<FromGitter>
<Blacksmoke16> whats the actual usecase for a custom severity?
<FromGitter>
<bararchy> Allowing to filter specific logs so that it can be feed into a customer facing system without exposing data
<FromGitter>
<Blacksmoke16> wouldnt that be better suited to a metadata/context value?
<FromGitter>
<bararchy> What would that give me? (I'm a bit new to the new log module)
<FromGitter>
<Blacksmoke16> i imagine you have a backend to kibana or something?
<FromGitter>
<Blacksmoke16> that you want these specific logs to go to?
<FromGitter>
<bararchy> I see, so sadly the source of the logs will all be STDOUT, it's running inside an AWS fargate task, and then using cloudwatch API being feed into the relevant system
<FromGitter>
<Blacksmoke16> (will need to wait for `0.35.0` for this but ) `Log.info &.emit("User logged in", user_id: 42)`
<FromGitter>
<Blacksmoke16> i.e. `Log.info &.emit("Message", public: true)`
<FromGitter>
<Blacksmoke16> or `priority: Priority::Public`, which you could then use that key/value to do the filtering
<FromGitter>
<Blacksmoke16> or something along those lines?
<FromGitter>
<bararchy> makes sense, I guess I can just instead use one of the levels I'm not usually using like NOTICE or VERBOSE, maybe that would be the easiest thing right now
<FromGitter>
<Blacksmoke16> that too
kradnoel has joined #crystal-lang
rocx has quit [Ping timeout: 260 seconds]
<FromGitter>
<Blacksmoke16> oprypin: but how do those artifacts make it into GH Actions?
<FromGitter>
<Blacksmoke16> like when building his diffing binary
<jhass>
oprypin: mmh they're still pushing HTML for the live updating stuff?
<jhass>
I mean it's by no means a JS free frontend
<jhass>
but maybe it actually degrades nicely, I never tried
<oprypin>
@Blacksmoke16: the action literally scours through artifacts of the repo crystal-lang/crystal
<oprypin>
u can check the source code :>
<oprypin>
that's not the word i wanted
<oprypin>
ah no there is a usage of it like that
<FromGitter>
<Blacksmoke16> ah its something your `install-crystal` thing does
<oprypin>
yes
<FromGitter>
<Blacksmoke16> might have to look into that for making an `oq` binary for windows :0
<oprypin>
inb4 running it through Wine is the most portable approach on Linux
<oprypin>
i should actually try it in Wine, how have i not thought of that
<FromGitter>
<kinxer> It seems pretty clear what's going on there, though. Thanks for correcting my unnecessary `.class`.
<jhass>
oh, both is a class so it overrides
<jhass>
mh, no ok I don't get this
<FromGitter>
<kinxer> Also, for the sake of clarity, the solution for the `.class` version (if that was what I actually wanted) was to declare `Gubbins`, declare `LilGubbins`, and then re-open `Gubbins` to add the method that required `LilGubbins` to be defined.
<oprypin>
what :D it sounds so funny
<oprypin>
i cant get over it
<FromGitter>
<kinxer> I just wanted to have more fun with class names. :P
<raz>
it seems to make sense to me. Gubbin is more specific than LilGubbin
<raz>
but...
<jhass>
why would the order you define these in matter though
<FromGitter>
<kinxer> Well, that is a fair point. I'd expect it to error in both cases in the (accidental) `.class` example.
<jhass>
I would understand if the one where it comes seconds errors out because it overrides the first one and thus the first one is never called but idk
<jhass>
it all doesn't make real sense
<raz>
yea, i don't understand why the first declared one take precedence
<raz>
i would've thought it gets overwritten if both declarations result in the same thing
<jhass>
maybe the override triggers the error to check if it should overload or override, idk
<jhass>
but then why wouldn't it need to instantiate the argument for that check in the other case
<FromGitter>
<kinxer> Oh, yeah. I wonder if that's it. The compiler doesn't *need* to know anything about that type before the method it overridden.
<raz>
oh, actually, i guess it does make sense. the compiler just keeps both and checks them in order as declared. both match, so the first one wins.
<FromGitter>
<kinxer> I guess there's something different between doing that check for `Klass` and `Klass.class`?
<jhass>
mmh, maybe
<raz>
having declaration order matter like that feels like a bug waiting to happen tho
<jhass>
well actually in the error case one doesn't match, if both match both ways work
<raz>
i wonder if the compiler could/should guarantee that the more specific match wins, regardless of declaration order
<oprypin>
raz, it does that normally
<oprypin>
just that in this case apparently it sees them as equally specific
<FromGitter>
<kinxer> To be honest, it's a little confusing that when you override a method exactly (in the same type), the newer definition wins, whereas when the methods are different but the compiler can't decide on one, the *older* definition wins.
lanodan has quit [Ping timeout: 265 seconds]
<FromGitter>
<kinxer> Okay, uh... There's this, I guess?
<FromGitter>
<kinxer> Lol. Thanks for the help, @raz.
<raz>
yw, and sorry. i'll go have my beer now, these gubbies melt my brain ;)
lanodan has joined #crystal-lang
<FromGitter>
<kinxer> For explanation of the links I just sent, basically it seems like the behavior is the following (where `def` means an exact method signature, and `defX'` is a re-definition with the exact method signature of `defX` but a different body): ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ebdbcb013878c30b57d26bb]
Dreamer3 has quit [Quit: Leaving...]
kradnoel has quit [Remote host closed the connection]