<FromGitter>
<dscottboggs_gitlab> > is invoked after instance variable types for all classes are known.
<FromGitter>
<bew> Because it's run just before typing
<FromGitter>
<bew> It's used to add more types for example
<FromGitter>
<bew> I was thinking about suggesting more macro hooks for this kind of case, I should probably do it one day..
<FromGitter>
<dscottboggs_gitlab> So I will need to implement this in some other way then?
tsundsted has quit [Ping timeout: 256 seconds]
_whitelogger has joined #crystal-lang
alexherbo2 has quit [Remote host closed the connection]
Vexatos has quit [Read error: Connection reset by peer]
<FromGitter>
<kvirani> Folks... Is there an idiomatic way to DRY this up? ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Also, I'm struggling making `@constraints` a NamedTuple with default value (is it even possible?) [https://gitter.im/crystal-lang/crystal?at=5cb2a2fc93fb4a7dc22628b5]
Vexatos has joined #crystal-lang
<FromGitter>
<kvirani> Also 👋 I'm new to Crystal and hoping to get good fast and contribute to Amber in the process.
<FromGitter>
<dscottboggs_gitlab> The initialize methods could be defined inside macros which iterate over `@t ype.instance_vars`
<FromGitter>
<kvirani> Interesting... didn't think of that. Before I go there, since that adds a bit more complexity for the sake of DRYing it up, any non-meta-programming way?
<FromGitter>
<dscottboggs_gitlab> Are there specific constraints that can be specified at *compile* time or are they based on a config file or something
<FromGitter>
<kvirani> The goal is that constraints can be passed in to this object as Hash or NamedTuple with any symbol/string based args
<FromGitter>
<dscottboggs_gitlab> no. I've heard that having so many function arguments can be bad for performance but other than that I don't think
<FromGitter>
<dscottboggs_gitlab> Symbols in crystal are like variants of a global enum, and must be known at *compile* time. If that's ok, then you can work with a `Hash(Symbol, Regex)` but if it's not then you need to use Strings.
<FromGitter>
<kvirani> Ah I understand your question now, since ultimately these are known at compile time, it's okay
DmitryBochkarev has joined #crystal-lang
<FromGitter>
<dscottboggs_gitlab> You could have a case..when statement in a function to create a hacky `Hash(String, Regex)` which accepts a symbol to match but really if you're going to go with a `Hash(Symbol, Regex)` then I feel like maybe a struct would be more appropriate?
<FromGitter>
<kvirani> The app dev defines them in their amber project's `routes.cr`file. The macro there would eventially pass it off to the object shown above ☝️
<FromGitter>
<dscottboggs_gitlab> ah you kinda lost me and I'm about to go to bed, sorry ✌️
<FromGitter>
<kvirani> np, i'll dig into what you said.
<FromGitter>
<kvirani> thx and gnight
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter>
<Blacksmoke16> @kvirani what do you need to do that for?
<FromGitter>
<Blacksmoke16> or just have constraints be like typed to `Hash | NamedTuple | Nil = nil`?
<FromGitter>
<Blacksmoke16> naw that doesnt work
<FromGitter>
<Blacksmoke16> might be easier to just have `constraints` be typed to like `@constraints = NamedTuple | Hash(String | Symbol, Regex?)? = nil`
<FromGitter>
<Blacksmoke16> then in each macro could do like `%verb, {{resource}}, %handler, {{action}}, valve, scope, "{{controller.id}}"{% if constraints %}, {{constraints}} {% end %}`
<FromGitter>
<Blacksmoke16> i.e. just default it to nil, since they arent required on the router's end. Router would be happy if that param is just excluded
<FromGitter>
<Blacksmoke16> ah crap, `NamedTuple` restriction doesnt work for ivars
<FromGitter>
<Blacksmoke16> yea afaik NamedTuples wouldn't be doable since we dont know the keys/types of each key
<FromGitter>
<Blacksmoke16> but imma get to bed as well o/
DmitryBochkarev has quit [Ping timeout: 240 seconds]
_whitelogger has joined #crystal-lang
DmitryBochkarev has joined #crystal-lang
olbat has quit [Ping timeout: 246 seconds]
teardown has quit [Ping timeout: 250 seconds]
olbat has joined #crystal-lang
olbat has quit [Ping timeout: 264 seconds]
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
olbat has joined #crystal-lang
_whitelogger has joined #crystal-lang
teardown has joined #crystal-lang
DmitryBochkarev has quit [Ping timeout: 255 seconds]
<FromGitter>
<r00ster91> How do I remove a non-empty directory?
_whitelogger has joined #crystal-lang
DmitryBochkarev has joined #crystal-lang
<FromGitter>
<r00ster91> My solution now is to delete each file in the directory and then delete the directory
ua has quit [Ping timeout: 246 seconds]
ashirase has quit [Ping timeout: 255 seconds]
ua has joined #crystal-lang
ashirase has joined #crystal-lang
teardown has quit [Ping timeout: 250 seconds]
laaron has joined #crystal-lang
DmitryBochkarev has quit [Remote host closed the connection]
DmitryBochkarev has joined #crystal-lang
DmitryBochkarev has quit [Ping timeout: 264 seconds]
laaron has quit [Remote host closed the connection]
<FromGitter>
<0x2C6> Starred. I hope one day I'll need this :D
<FromGitter>
<Blacksmoke16> 👍
<FromGitter>
<Blacksmoke16> is pretty slick
<FromGitter>
<Blacksmoke16> esp for JSON APIs as you can define your model, with the validation annotations, then catch the exception on deserialize, and return `ex.to_json`
<FromGitter>
<Blacksmoke16> the former would be the more common syntax
<FromGitter>
<nsuchy> awesome
<FromGitter>
<Blacksmoke16> the other option is `site` or `self.site` which would be calling that properties getter while `@site` accesses the value directly
<FromGitter>
<nsuchy> Proxmox's API is painful to work with so this is to abstract away the hard parts
<FromGitter>
<nsuchy> There's not a crystal shard that does promos yet
<FromGitter>
<nsuchy> (that I'm aware of)
<FromGitter>
<Blacksmoke16> well there you go, new shard is born ;0
<sp3ncer>
Blacksmoke16 I fully plan to, but it seems very silly that that's something I should even need to do
<sp3ncer>
and of course doesn't solve the problem for everyone still trying to reference the original repo
<FromGitter>
<dscottboggs_gitlab> I use type restrictions *religiously* in Crystal, although that's not really idiomatic.
<FromGitter>
<nsuchy> ```code paste, see link```
<FromGitter>
<nsuchy> However if I set my type restriction We go back to the can't infer the type of... error
<FromGitter>
<Blacksmoke16> right
<FromGitter>
<Blacksmoke16> this is because due to your `unless ticket.nil?` `ticket` *could* be `nil`
<FromGitter>
<Blacksmoke16> also since you dont cast `csrf_prevention_token` as a string its still a `JSON::Any`
<FromGitter>
<Blacksmoke16> if its okay that `ticket` could be `nil` then can add that to the type restriction, otherwise will have to have some logic to error or something if it is nil
<FromGitter>
<Blacksmoke16> removes `JSON::Any` by casting csrf token to string using [as_s}(https://crystal-lang.org/api/0.27.2/JSON/Any.html#as_s%3AString-instance-method) and makes the type of the hash contain either a string or nil
<FromGitter>
<nsuchy> ticket should never be will though
<FromGitter>
<Blacksmoke16> then why the `unless ticket.nil?` ;)
<FromGitter>
<nsuchy> ruby version had it from old dev