<FromGitter>
<bew> Yeah but maybe not clear enough for ppl who don't want to care how your shard work, and don't want to debug this kind of errors in "not-in-my-code"
<FromGitter>
<bew> But i'll try it when it's done :)
<FromGitter>
<bew> See how my random-stupidity-generator handle this case
<FromGitter>
<bew> Bed is calling though, ++
<FromGitter>
<Blacksmoke16> by compile time error i was thinking like `Assertion Foo requires x generic types, but only 1 was given`
<FromGitter>
<Blacksmoke16> as ill have access to all that data
<FromGitter>
<Blacksmoke16> ill keep you posted ๐
ma__ has quit [Quit: My MacBook has gone to sleep. ZZZzzzโฆ]
<FromGitter>
<Blacksmoke16> deff can make it more clear
ma__ has joined #crystal-lang
<FromGitter>
<Blacksmoke16> `Error: wrong number of type vars for ExistsAssertion(P, M) (given 0, expected 2) on user_id@[Assert::Exists] in Item` im open to suggestions
_whitelogger has joined #crystal-lang
devil_tux has quit [Ping timeout: 258 seconds]
Yxhuvud has quit [Ping timeout: 264 seconds]
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
DTZUZU has joined #crystal-lang
alex`` has quit [Ping timeout: 258 seconds]
chemist69 has quit [Ping timeout: 252 seconds]
chemist69 has joined #crystal-lang
teardown has joined #crystal-lang
ht_ has joined #crystal-lang
ht_ has quit [Remote host closed the connection]
devil_tux has joined #crystal-lang
ma__ has quit [Quit: My MacBook has gone to sleep. ZZZzzzโฆ]
ma__ has joined #crystal-lang
ma__ has quit [Client Quit]
Yxhuvud has joined #crystal-lang
return0e_ has quit [Ping timeout: 245 seconds]
alex`` has joined #crystal-lang
<FromGitter>
<absolutejam_gitlab> I have a base class which has `name` and `description` as properties, which are defined in the `initialize`
<FromGitter>
<absolutejam_gitlab> I have classes that inherit from this that must also keep the `name` and `description` but can define other properties
<FromGitter>
<absolutejam_gitlab> Is there a way to run validations on the `name` property (which is being set by `initialize` at the moment) even if child classes overwrite `initialize`?
<FromGitter>
<absolutejam_gitlab> I thought `name=` on the parent might work but I guess that's not called by `initialize(@name = String)`
return0e has joined #crystal-lang
DTZUZO has quit [Ping timeout: 268 seconds]
DTZUZO has joined #crystal-lang
<FromGitter>
<Blacksmoke16> @absolutejam_gitlab if you define an initializer on the child and dont call super, it doesnt inherit both
<FromGitter>
<Blacksmoke16> so the parent would never be getting called
devil_tux has quit [Ping timeout: 272 seconds]
DTZUZO has quit [Quit: WeeChat 2.0]
<FromGitter>
<absolutejam_gitlab> Aye that's what I mean
<FromGitter>
<naqvis> Why I'm unable to send/recv data on SSL enabled sockets? Even below sample code from docs doesn't seem to work on Mac and Ubuntu โ *Server* โ โ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d5bef349507182477163095]
DTZUZO has quit [Ping timeout: 245 seconds]
<FromGitter>
<absolutejam_gitlab> @tenebrousedge Oh, there's the convertor info, thanks
<FromGitter>
<absolutejam_gitlab> Oh yeah definitely, but I just mean the spec itself
<FromGitter>
<absolutejam_gitlab> Just standardise on one type
<FromGitter>
<absolutejam_gitlab> Like how you can have `foo: ` as a network in docker-compose
<FromGitter>
<absolutejam_gitlab> Why an empty object. Why
<FromGitter>
<Blacksmoke16> :S
<FromGitter>
<naqvis> @Blacksmoke16 Appreciate your thoughts/comments/insights on what could be causing that SSL enabled communication issue?
<FromGitter>
<Blacksmoke16> uhh, could one of the reads be blocking?
<FromGitter>
<naqvis> seems like that way, I wasn't able to communicate to different server on SSL, so thought of doing the investigation to see if data does get transmitted on SSL sockets, but seems that's not happening
<FromGitter>
<naqvis> looking into `HTTP::Client` revealed that, have to manually invoke `flush` after every send (weird)
<FromGitter>
<naqvis> this is different from non-TLS sockets, where write doesn't need to end up with `flush`
<FromGitter>
<absolutejam_gitlab> I had a lot of distinct types, but they shared a lot of the same functionality. I did consider inheritance to clarify them a bit
<FromGitter>
<absolutejam_gitlab> but at the minute, I have an arbitrarily nestable object that gets erialized
<FromGitter>
<Blacksmoke16> success
<FromGitter>
<absolutejam_gitlab> gotta actually parse it now
<FromGitter>
<Blacksmoke16> gl
<FromGitter>
<absolutejam_gitlab> Probably should have used struct too...
<FromGitter>
<absolutejam_gitlab> nvm
<FromGitter>
<absolutejam_gitlab> Is there an inbuilt way to format text to certain columns, word wrapping, etc.?
<FromGitter>
<absolutejam_gitlab> I've seen `PrettyPrint` but I don't understand its use
<FromGitter>
<Blacksmoke16> that would be the way
<FromGitter>
<Blacksmoke16> or a custom to_s
<FromGitter>
<absolutejam_gitlab> any examples knocking about?
<FromGitter>
<absolutejam_gitlab> oh wait a minute
<FromGitter>
<Blacksmoke16> or without knowing any other context, try to handle the nilability higher up
<FromGitter>
<Blacksmoke16> which would remove the need for checking for nil
<FromGitter>
<kingsleyh> yup
<FromGitter>
<kingsleyh> Crystal doesn't have Option does it
<FromGitter>
<Blacksmoke16> hm?
<FromGitter>
<kingsleyh> like Some | None
<FromGitter>
<Blacksmoke16> still not sure i follow
<FromGitter>
<kingsleyh> Some("apple") or None
<FromGitter>
<sam0x17> how would I go about clearing all cookies in HTTP::Repsonse?
<FromGitter>
<sam0x17> ^ no, that's a rust thing
<FromGitter>
<sam0x17> @kingsleyh
* FromGitter
* Blacksmoke16 still doesnt know what thats supposed to do :p
<FromGitter>
<sam0x17> that's the way rust deals with nillability
<FromGitter>
<Blacksmoke16> like noop if its nil?
<FromGitter>
<sam0x17> there is a generic enum `Option<T>` that is either `None` or `Some(T)`
<FromGitter>
<sam0x17> rust enums are weird they are really fancy type unions and can have methods and stuff
<FromGitter>
<kingsleyh> sorry I do a lot of functional programming in Scala
<FromGitter>
<sam0x17> oh, is that a scala thing?
<FromGitter>
<sam0x17> I didn't know rust got it from there
<FromGitter>
<kingsleyh> and we have Option and Either which lets you wrap a value and then call map, getOrElse etc on it to handle it
<FromGitter>
<kingsleyh> which side steps the whole Nil thing
<FromGitter>
<sam0x17> yeah crystal is a lot more forgiving at least than rust with that, like you can or things together to get rid of the nil as @Blacksmoke16 demonstrated way above
<FromGitter>
<kingsleyh> yep
<FromGitter>
<sam0x17> and you can directly call `.as(T)` which in rust would be unsafe
<FromGitter>
<Blacksmoke16> and @sam0x17 i dont think there is a way to do that atm?
<FromGitter>
<kingsleyh> in Scala I would instead of returning something that could be String | Nil - I would return Option[String] - so I can map around the option of string if it's there - otherwise I can handle the else case
<FromGitter>
<sam0x17> the only implication for me is usually whenever I have to read something from a string-keyed hash like thing, I have to check if the key exists first before reading it, and then call `.not_nil`, other than that I typically never have nilable things
<FromGitter>
<sam0x17> yeah its basically the same thing, idiomatically
<FromGitter>
<Blacksmoke16> @sam0x17
<FromGitter>
<sam0x17> since enums in rust/scala are essentially type unions, `String | Nil` literally is the same as `Option[String]` or whatever
<FromGitter>
<Blacksmoke16> (is what i based it on in the first place)
<FromGitter>
<Blacksmoke16> so like `obj.validate ["group1"]` would only runs the assertions assigned to that group
<FromGitter>
<sam0x17> and the groups are like lists of fields with certain validations?
<FromGitter>
<Blacksmoke16> more like grouping assertions by names
<FromGitter>
<Blacksmoke16> so you can run a subset of them
<FromGitter>
<sam0x17> oh gotcha
<FromGitter>
<sam0x17> yeah its really funny, I didn't really mean to but I ended up writing a bunch of weird custom serialization tooling for this that also uses a groups context
<FromGitter>
<sam0x17> *concept
<FromGitter>
<sam0x17> it all operates on hashes and then at the end you would supposedly do `.to_json` if that's what you want
<FromGitter>
<sam0x17> but the syntax is like:
<FromGitter>
<Blacksmoke16> decided to split the serializer (still WIP), and this validation lib
<FromGitter>
<sam0x17> this is a real context I use plus a `:some_property` that I threw in just now for demonstration purposes
<FromGitter>
<sam0x17> but basically you can define any number of hash contexts, which internally are just procs that take in a hash and reference to the model and spit out a modified version of the hash
<FromGitter>
<sam0x17> and there is tooling for having a "parent" so in the second one we are saying `:extended` is based on `:safe`
<FromGitter>
<sam0x17> to use it you would just go `user.to_hash(:extended)`
<FromGitter>
<Blacksmoke16> fancy :p
<FromGitter>
<sam0x17> the default `.to_hash` with nil passed in just takes the crystal versions of the model fields
<FromGitter>
<sam0x17> but yeah getting procs to nest in each other is tricky
<FromGitter>
<sam0x17> as a general principle I like to have any string known at compile time to be a symbol, so I often end up writing custom stuff just so I can see lots of symbols everywhere xD
<FromGitter>
<sam0x17> which means I should use enums more lol
<FromGitter>
<sam0x17> but I like this a lot better than the old rails API, where these extended JSON properties were added literally within the API methods themselves in an ad-hoc sort of way, with code duplication across numerous methods (really bad)
<FromGitter>
<sam0x17> serialization should be a model thing, not a controller thing
<FromGitter>
<sam0x17> also it makes it so I can use them in non-JSON contexts if I want to, since they are crystal hashes / types
<FromGitter>
<sam0x17> I might extract it into a shard and add support for a few ORMs
<FromGitter>
<Blacksmoke16> at work we used to have transformer classes for our entities
<FromGitter>
<sam0x17> yeah this is probably really similar
<FromGitter>
<Blacksmoke16> but lately have been combining the ORM stuff, assertions, and serialization stuff on the entities themselves
<FromGitter>
<sam0x17> yeah, I like that approach
<FromGitter>
<sam0x17> the only problem with my approach is it relies on a massive and ugly type union, but I may be able to get around that somehow
<FromGitter>
<Blacksmoke16> whats the use case for working with hahes?
<FromGitter>
<sam0x17> I just like them
<FromGitter>
<Blacksmoke16> i always saw that in crystal land as a smell
<FromGitter>
<Blacksmoke16> due to the big unions you get and stuff
<FromGitter>
<absolutejam_gitlab> Surely it's better to have a defined class unless you need a big, nebulous glob of assorted data
<FromGitter>
<absolutejam_gitlab> which is a bit gross
<FromGitter>
<sam0x17> they print well, they `.to_json` well, they have real crystal types, but agreed on the unions
<FromGitter>
<Blacksmoke16> why not just call `to_json` on your objects?
<FromGitter>
<sam0x17> I do at the end
<FromGitter>
<Blacksmoke16> vs going from obj to hash to json?
<FromGitter>
<sam0x17> a big reason is most orms don't make the fields iterable
<FromGitter>
<sam0x17> and I always end up in that situation somehow where I have to iterate over them
<FromGitter>
<Blacksmoke16> i must be spoiled from granite
<FromGitter>
<sam0x17> and if I'm going to do that, I don't want it to be in JSON land
<FromGitter>
<Blacksmoke16> right, so what do you have to iterate over?
<FromGitter>
<sam0x17> but you can't do `User.first!.attributes.each do |k, v|`...
<FromGitter>
<sam0x17> some can, but most dont
<FromGitter>
<Blacksmoke16> sorry, but whats the use case for doing that?
<FromGitter>
<Blacksmoke16> to limit the properties that get serialized?
<FromGitter>
<sam0x17> often, yes, but my thing does that instead
<FromGitter>
<sam0x17> all it needs, (and all any of these systems need) is a clever system of macros where the type union is literally only the types that are actually used with that model's hashes in current code
<FromGitter>
<sam0x17> I haven't played with macro-defining the members of a type union before, but I think it would make this a lot better, like overhead wise no use than a `NamedTuple`, but with the advantages of `Hash(Symbol, TypeUnion)`
<FromGitter>
<Blacksmoke16> is my ideal setup i been working towards
<FromGitter>
<Blacksmoke16> exclude all properties by default, specify the ones you want serialized
<FromGitter>
<Blacksmoke16> also would be that `@[CRS::Groups("group1")]` you could add to only serialize those in a given group
<FromGitter>
<sam0x17> yeah with the grouping that fits my needs
<FromGitter>
<sam0x17> was basically just typing a long winded way of saying that
<FromGitter>
<Blacksmoke16> :P this way you avoid having to use hashes or anything, its all just natively built in
<FromGitter>
<sam0x17> yeah, pretty legit
<FromGitter>
<Blacksmoke16> thats a valid Granite model btw, other than the`CRS` stuff, as thats still WIP refactor of the current serializer shard i have
<FromGitter>
<Blacksmoke16> `@[CrSerializer::Options(expose: true)]` and `@[CrSerializer::ClassOptions(exclusion_policy: CrSerializer::ExclusionPolicy::ExcludeAll)]` is what it is atm
<FromGitter>
<Blacksmoke16> will get there one day :P
<FromGitter>
<sam0x17> love it, though the names get pretty long lol
<FromGitter>
<Blacksmoke16> yea thought of the `CRS` alias to help with that in the new world
<FromGitter>
<sam0x17> I like that
<FromGitter>
<Blacksmoke16> debating whether to have each "option" be its own annotation, or have it act like `JSON::Field` where you apply all serialization related options into one
<FromGitter>
<absolutejam_gitlab> you're such an annotations hoe, haha
<FromGitter>
<sam0x17> inevitably, the first one will be better for people who have way too many on the same field
<FromGitter>
<absolutejam_gitlab> Do any of the web frameworks use them?
<FromGitter>
<Blacksmoke16> *its the future*
<FromGitter>
<absolutejam_gitlab> Be good for middleware like auth
<FromGitter>
<Blacksmoke16> athena does
<FromGitter>
<absolutejam_gitlab> a la Python's Flask
<FromGitter>
<Blacksmoke16> only one afaik
<FromGitter>
<absolutejam_gitlab> Obviously :P
<FromGitter>
<absolutejam_gitlab> Do you work on Crystal proffesionally @Blacksmoke16 ?
<FromGitter>
<sam0x17> I do, but as CTO I get to decide what we use xD
<FromGitter>
<absolutejam_gitlab> But I'm not a developer
<FromGitter>
<Blacksmoke16> i dont mind it, most of my shard ideas comes from it
<FromGitter>
<sam0x17> symfony is a new one that I had never heard of
<FromGitter>
<Blacksmoke16> has some (IMO slick stuff), that i been putting into athena
<FromGitter>
<sam0x17> but makes sense I've been out of PHP ecosystem for over 10 years
<FromGitter>
<Blacksmoke16> namely the converters, DI, console commands, the assertion/serialization stuff
<FromGitter>
<Blacksmoke16> also the logger shard i did
<FromGitter>
<absolutejam_gitlab> monolog?
<FromGitter>
<Blacksmoke16> yea
<FromGitter>
<Blacksmoke16> my clone of it :P
<FromGitter>
<absolutejam_gitlab> crylog right?
<FromGitter>
<Blacksmoke16> yea
<FromGitter>
<absolutejam_gitlab> I like it, just don't have need for it yet
<FromGitter>
<Blacksmoke16> monolog is super cool
<FromGitter>
<Blacksmoke16> so flexible and powerful
<FromGitter>
<absolutejam_gitlab> I actually quite like Laravel
<FromGitter>
<absolutejam_gitlab> just a lot of magic, and I don't always like that. Maybe my inexperience being unable to reason about it all, and I don't use PHPStorm either
<FromGitter>
<absolutejam_gitlab> I don't have to write PHP though, so it's not the end of the world
<FromGitter>
<sam0x17> I only ever went from scratch with php haha I think back in 2005 ish there weren't any frameworks or I didn't know of any at least everything was like `mysql_connect` and `if($_GET['mode'] == 'blog') { require('blog'); }` and bad stuff like that lolol
<FromGitter>
<sam0x17> it was all very very procedural I dont think I even used classes ever
ht_ has quit [Remote host closed the connection]
<FromGitter>
<Blacksmoke16> :p
<FromGitter>
<Blacksmoke16> rails is like that too with the magic
<FromGitter>
<sam0x17> true, tho there is the orm
<FromGitter>
<Blacksmoke16> maybe one of you can tell me how can i have a property on a model in rails that doesnt represent a column?
<FromGitter>
<Blacksmoke16> can you even do that?
<FromGitter>
<sam0x17> I was working with raw mysql engine commands and just manipulating the associative arrays
<FromGitter>
<sam0x17> omg yeah there are a bunch of ways
<FromGitter>
<sam0x17> you basically use hooks to trick it
<FromGitter>
<sam0x17> like a "converter" in rails is easy for example
<FromGitter>
<sam0x17> because you can use `self[:db_field]` to access raw fields even if you override them with `def the_field` and `def the_field=(val)`
<FromGitter>
<sam0x17> so if you define getters and setters for something that manipulate something in `self[:whatever]`, you've effectively written a converter or a custom property
<FromGitter>
<Blacksmoke16> hmm interesting
<FromGitter>
<sam0x17> no reason that couldn't carry on in crystal orms ;)
<FromGitter>
<Blacksmoke16> i dont even remember what my models looked like
<FromGitter>
<sam0x17> here I'll show you an ugly one
<FromGitter>
<Blacksmoke16> `Latest commit 0b67aa9 on Jul 10, 2018`
<FromGitter>
<Blacksmoke16> didnt think it was that recent ha
<FromGitter>
<absolutejam_gitlab> I find symbols quite weird in Crystal
<FromGitter>
<Blacksmoke16> there was talk about removing them
<FromGitter>
<absolutejam_gitlab> I get them in Ruby and in Elixir they're useful
<FromGitter>
<Blacksmoke16> and just having them be specific to autocasting enums
<FromGitter>
<absolutejam_gitlab> and every time I think of using them for basic pattern matching, an enum is better
<FromGitter>
<Blacksmoke16> can use an symbol, instead of full name of the enum
<FromGitter>
<sam0x17> and if you are wondering, yes, `safe_id_constraint` makes it so that a certain range of production ids for that model are off limits to ensure that filenames in aws that are used in production dont get overwritten by anything in development. Yes that bad lol
<FromGitter>
<Blacksmoke16> i meant to make a feature request about that
<FromGitter>
<Blacksmoke16> allow to type a method arg to a enum member
<FromGitter>
<absolutejam_gitlab> the example you posted
<FromGitter>
<absolutejam_gitlab> Yeah, I see Enums doing the same job in Crystal tbh
<FromGitter>
<Blacksmoke16> @sam0x17 jeeze
<FromGitter>
<absolutejam_gitlab> They're not used as heavily as in Elixir, and Elixir's VM allows reflection on them and shit, which wouldn't really be possible in Crystal
<FromGitter>
<absolutejam_gitlab> as they have to be known at compile time and all that
<FromGitter>
<Blacksmoke16> current way to do it would be have a log method typed to the enum
<FromGitter>
<Blacksmoke16> and inside of it have a clas
<FromGitter>
<absolutejam_gitlab> I guess thinking about it, I dunno how destructuring would work
<FromGitter>
<absolutejam_gitlab> Because it doesn't rely on hashes/structs & objects like Elixir & JS
<FromGitter>
<absolutejam_gitlab> And the associated literals
<FromGitter>
<Blacksmoke16> dunno
<FromGitter>
<absolutejam_gitlab> i wish `Array(String)` worked the same as `[] of String`
<FromGitter>
<Blacksmoke16> hm?
<FromGitter>
<absolutejam_gitlab> wait, `.new` is the same right?
<FromGitter>
<Blacksmoke16> yes
<FromGitter>
<absolutejam_gitlab> it always catches me out
<FromGitter>
<absolutejam_gitlab> The former syntax is my preference