ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.32.1 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
Nicolab has quit [Ping timeout: 265 seconds]
ur5us has quit [Ping timeout: 260 seconds]
Nicolab has joined #crystal-lang
ur5us has joined #crystal-lang
<FromGitter> <grkek> Sleep is for the weak, I sleep with my eyes open standing in the center of my living room in a Tpose
Nicolab has quit [Quit: Leaving.]
duane has quit [Read error: Connection reset by peer]
duane has joined #crystal-lang
ur5us has quit [Ping timeout: 260 seconds]
ur5us has joined #crystal-lang
_whitelogger has joined #crystal-lang
duane has quit [Ping timeout: 240 seconds]
ur5us has quit [Ping timeout: 260 seconds]
ht_ has joined #crystal-lang
<FromGitter> <grkek> radiating dominance and power over my relatives
<FromGitter> <grkek> they bring me meat and wine
ht_ has quit [Quit: ht_]
alexherbo2 has quit [Ping timeout: 240 seconds]
ur5us has joined #crystal-lang
alex`` has quit [Ping timeout: 265 seconds]
ur5us has quit [Ping timeout: 260 seconds]
ur5us has joined #crystal-lang
yukai has quit [Ping timeout: 240 seconds]
uu91 has joined #crystal-lang
Nicolab has joined #crystal-lang
<FromGitter> <Nicolab> haha ⏎ ⏎ Hello
repo has left #crystal-lang ["WeeChat 2.7"]
repo has joined #crystal-lang
<repo> ping
ur5us has quit [Ping timeout: 260 seconds]
<f1refly> pong
* FromGitter * watzon also pongs
<repo> SWEEEET
<repo> parsed_relayed_message.pl works like a charm!
<repo> finally i have tab completion for gitter nicks!
<FromGitter> <watzon> There has to be a better way to turn a hex string into an IPv6 address than this https://carc.in/#/r/8ee0
<FromGitter> <watzon> Maybe I shouldn't be doing this at almost 3 am
<FromGitter> <watzon> Actually no, apparently that's wrong
<FromGitter> <watzon> Damn gopsutil documentation has their example wrong
<repo> yeah it looks wrong
<FromGitter> <j8r> wow omg all the intermediary arrays
uu91 has quit [Ping timeout: 268 seconds]
Nicolab has quit [Quit: Leaving.]
sz0 has joined #crystal-lang
<sorcus> https://gist.github.com/MrSorcus/bed6466d298ed714abc9561c66f10383 - what wrong? No any responses from WebSocket server (any server, include node.js script with minimal websocket server).
Nicolab has joined #crystal-lang
<sorcus> Hmm, ws.run required...
<FromGitter> <Nicolab> @sorcus I don't know if HTTP::WebSocket spawn every connection but if it doesn't, maybe it might be interesting to do it (to be tested)
<FromGitter> <Nicolab> Or not... Normally with listen and an on_open it might be nice to spawn the management of each connection.
<FromGitter> <Nicolab> But I don't see an equivalent of listen and on_open.
<FromGitter> <Nicolab> Is it possible to dynamically call methods from a module?
<FromGitter> <Nicolab> Like module[method] or module.object.get(method)
<FromGitter> <Nicolab> @sorcus I didn't say anything, I didn't see it was a WS client.
<sorcus> Nicolab: :-D :-)
Nicolab has quit [Ping timeout: 258 seconds]
Nicolab has joined #crystal-lang
<FromGitter> <Nicolab> Does anyone know a way to declare the type of a function that can receive one or more arguments of any type?
<FromGitter> <Nicolab> Naively a function of this type that returns a boolean, it would look like this: `Proc(**Any, Bool)`
<FromGitter> <Blacksmoke16> `def execute(*args) : Bool`?
<FromGitter> <Blacksmoke16> the `Proc` representation of that would need to use generics
<FromGitter> <Nicolab> Thanks but I'm not quite sure how to do that. ⏎ ⏎ `handlers = {} of String | Symbol => Proc(?, Bool)`
<FromGitter> <Nicolab> The idea is to call the callback: `handlers[name].call(?)`
* sorcus watches closely.
<FromGitter> <naqvis> per my understanding, `Proc` struct doesn't allow variadic arguments, so I would have gone with `Array` instead like ⏎ ⏎ ```alias Func = Proc(Array(Object), Bool)``` ⏎ ⏎ It might be bit cumbersome to pass arguments as you will have to enclose them inside array, but it does give you flexibility to pass multiple args. Using `Object` as its base type and in sync with what you are asking for Any type.
<FromGitter> <Nicolab> This works for the definition of my hash but not for the registration of the function: register :test1, ->(args : Array(Object)) { args } ⏎ [00] ^----- ⏎ [00] Error: can't use Object as generic type argument yet, use a more specific type
<FromGitter> <Nicolab> I look that
<FromGitter> <naqvis> aha, so `Object` not yet allowed. Either use Union or I would have gone with kind of Marker interface and do some monkey patching on Object, that will do the trick
<FromGitter> <Nicolab> @Blacksmoke16 The example is too complex, already I'm getting used to the Ruby syntax, macro syntax is the next step.
alexherbo2 has joined #crystal-lang
alex`` has joined #crystal-lang
<FromGitter> <Nicolab> I try with the macro & hook :)
<FromGitter> <Blacksmoke16> > per my understanding, `Proc` struct doesn't allow variadic arguments, so I would have gone with `Array` instead like ⏎ ⏎ that is correct but if you wrap the proc in a struct you can use splat generics to handle it
<FromGitter> <Nicolab> Oh! Also, indeed
<FromGitter> <Nicolab> I try the two
<FromGitter> <Nicolab> thanks
<FromGitter> <Blacksmoke16> https://github.com/crystal-lang/crystal/issues/8520 is an issue about it so you would have to have a generic be the proc
<FromGitter> <Nicolab> I look, thank you
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8eeg like this
<FromGitter> <Nicolab> I think you should activate the sponsorship on Github! ;)
<FromGitter> <Blacksmoke16> :p
<FromGitter> <Nicolab> realy :)
<FromGitter> <Nicolab> Of course I don't think is for the fortune, but the coffee, the beer, the pizza... :D
<FromGitter> <naqvis> ☝️ January 15, 2020 9:57 PM (https://gitter.im/crystal-lang/crystal?at=5e1f1a493ff141256d38e72b) Thanks @Blacksmoke16
<FromGitter> <Blacksmoke16> haha, maybe in the future 😉
jetpack_joe has quit []
jetpack_joe has joined #crystal-lang
duane has joined #crystal-lang
Nicolab has quit [Quit: Leaving.]
duane has quit [Ping timeout: 265 seconds]
flaviodesousa has joined #crystal-lang
duane has joined #crystal-lang
<repo> Blacksmoke16: heya. i noticed a problem with CrSerializer
<FromGitter> <Blacksmoke16> oh?
<repo> i defined a virtual property. the method didn't have a specified return type. This caused an error that was hard to debug (had to look into the code to realize i need to define the return type. However, my class including CrSerializer is a generic one, and the return type is a generic type as well. This fails with "undefined constant T"
<FromGitter> <Blacksmoke16> mm yea, the docs say its required
<FromGitter> <Blacksmoke16> but could deff raise a better error message
<repo> ah i should use S there, but still results in an "undefined constant" error
<repo> Blacksmoke16: i assume there's no way around this?
<FromGitter> <Blacksmoke16> got some example code?
<repo> yeah, i pasted it
<repo> second link
<FromGitter> <Blacksmoke16> oh sorry missed that
<repo> (just replace T with S in your mind in the return type)
<FromGitter> <Blacksmoke16> site is timing out for me
<repo> oh?
<repo> wow
<repo> hm
<repo> works for me
<repo> gist then
<FromGitter> <Blacksmoke16> there we go
<FromGitter> <Blacksmoke16> it loaded
<FromGitter> <Blacksmoke16> whats the use case versus just calling `.to_json` on the enumerable?
<repo> i'm wrapping the items in the collection with another serializer
<FromGitter> <Blacksmoke16> got some example input?
<repo> i mean sure, i could also just do {result: collection.map { |item| ItemSerializer.new(item) }}
<repo> it's a db model
<FromGitter> <Blacksmoke16> oo i see the issue
<FromGitter> <tenebrousedge> `{result: collection.map(&->ItemSerializer.new(Item))` assuming the collection is `Array(Item)`
<repo> or like that, yes
<repo> `{result: collection.map(&->ItemSerializer.new)}` even
<FromGitter> <tenebrousedge> it needs the type
<FromGitter> <Blacksmoke16> the way it works is it builds out an array of metadata about each property it has to serialize, like its name/type etc
<FromGitter> <Blacksmoke16> but in this case the return type for one is generic, which i guess it doesnt know about
Nicolab has joined #crystal-lang
<repo> yeah
<repo> tenebrousedge: didn't know that!
<FromGitter> <Blacksmoke16> which im not sure why because its inside of type, so should be able to
<repo> i rarely use ->
<FromGitter> <Blacksmoke16> yea i can fix that
<FromGitter> <Blacksmoke16> have to move some code around
<FromGitter> <Blacksmoke16> put that method in the `macro included` so that it is executed in the context of the class, versus the module
<FromGitter> <Blacksmoke16> going to cause some other issues, like now i need to support serializing all `Enumerable` types, like what would a `Range` look like?
<FromGitter> <Blacksmoke16> `0..10` => `"0..10"`? :shrug:
<FromGitter> <tenebrousedge> in JSON?
<FromGitter> <Blacksmoke16> yea
<repo> builder.array { collection.each(&.to_json(builder)) }?
<FromGitter> <Blacksmoke16> stdlib doesnt support it so maybe the solution here is to use a stricter alias?
<repo> yeah maybe
<FromGitter> <tenebrousedge> I think it would need to be `{begin: 0, end: 10, exclusive: false}`
<FromGitter> <Blacksmoke16> you *could* parse it from the string as it contains all the info you need
FromGitter has quit [Remote host closed the connection]
<repo> Blacksmoke16: meh also delegate_to won't work with @[CRS::VirtualProperty] because of the missing return type
FromGitter has joined #crystal-lang
<FromGitter> <tenebrousedge> I mean, you're not wrong, but I think that serializing things to strings that are not strings is kinda hacky
<repo> delegate foo, to: i mean
<FromGitter> <Blacksmoke16> for sure
<FromGitter> <Blacksmoke16> @repo id maybe not use Enumerable, pretty sure that would fail in the stdlib as well (since it doesnt support serializing Range)
<FromGitter> <Blacksmoke16> ill release a new version tonight with this fix
<FromGitter> <Blacksmoke16> also been thinking, when it gets ported to Athena org, im leaning towards moving the syntax from like `obj.to_json` to `serializer.serialize JSON, obj`
<FromGitter> <Blacksmoke16> will make the implementation simpler
<FromGitter> <kinxer> Why do you prefer that to `JSONSerializer.serialize obj`?
<FromGitter> <tenebrousedge> what about `def to_json(serializer : JSONSerializer0`
<FromGitter> <Blacksmoke16> well thats essentially what it would be @kinxer
<FromGitter> <Blacksmoke16> would be easy enough to do
<FromGitter> <Blacksmoke16> mainly the ideal process i want to try and get to is like
<FromGitter> <tenebrousedge> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e1f3d5425256256b7f89b41]
<FromGitter> <Blacksmoke16> yea exactly, would be easy to add helper methods to handle this
<FromGitter> <Blacksmoke16> current implementation does something similar but like `obj.serialize JSON`
<FromGitter> <Blacksmoke16> id like to just have an included module define two methods that return an array of "metadata" that describes the properties that should be serialized/deserialized
<FromGitter> <Blacksmoke16> metadata being independent of format, then each format implements the logic for handling the metadat
<FromGitter> <Blacksmoke16> which is 50% how it works now, just want to remove the tight coupling of the `#serialize` method into another type out from the actual obj being serialized for example
<FromGitter> <Blacksmoke16> which from a DI perspective would be better as well
confact has quit []
confact has joined #crystal-lang
<FromGitter> <sudomaxime> Hey guys, there is something I have noticed in the Crystal community. Coming from NodeJs I am traumatized of the events of the left-pad tragedy (https://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/). I'm noticing that with shards you can set github repos as dependency targets, and sometimes these targets also have branching github dependencies ... The problem I'm seeing is that any folk can pull out
<FromGitter> ... of github a dependency that everyone needs. What are you guys opinion on that ? Am I being too cautious here ?
<FromGitter> <Blacksmoke16> wouldnt that be an issue in any lang?
<FromGitter> <Blacksmoke16> idt crystal is as bad as node is tho
<FromGitter> <Blacksmoke16> installing a farmework doesnt install 1000 packages like node 😉
<FromGitter> <tenebrousedge> mostly right. JS is a clusterf*ck of a language that needs basic functionality to be provided via external packages
<FromGitter> <sudomaxime> The problem isn't node, the problem is NPM and the way people used it
<FromGitter> <pynixwang> node_modules
<FromGitter> <Nicolab> @sudomaxime If you want to avoid this problem, there are 50 solutions, you have to be the sources (commited modules folder) or a registry of your own that holds the sources.
<FromGitter> <pynixwang> 1000 packages.
<FromGitter> <pynixwang> you are awesome.
alexherbo20 has joined #crystal-lang
<FromGitter> <sudomaxime> The issue I am seeing is that it's far easier to pull out a repo on github than it is on NPM now, you basically cannot remove a dependency from NPM even if you own it
<FromGitter> <sudomaxime> and most people are not going to go to the lenghts of making their own secure repo
alex`` has quit [Ping timeout: 240 seconds]
alexherbo2 has quit [Ping timeout: 258 seconds]
alexherbo20 is now known as alexherbo2
<FromGitter> <sudomaxime> again, the problem is not the tool, the problem is how people tend to use open ended repos
<FromGitter> <sudomaxime> I don't see anywhere in the documentation that this can be an issue as well
<FromGitter> <pynixwang> dont warry, crystal has leftPad builtin.
<FromGitter> <sudomaxime> Ok let's theorycraft here
<FromGitter> <sudomaxime> Kamal is an awesome shard for making API's and services
alex`` has joined #crystal-lang
<FromGitter> <sudomaxime> let's say that I am looking to make an awesome CMS or framework and I want to open source-it, and I'm using Kamal as a dependency
flaviodesousa has quit [Quit: KVIrc 4.9.3 Aria http://www.kvirc.net/]
<FromGitter> <sudomaxime> now my community grows, add more features and stuff, and everything is fine and dandy in the butterfly world of "don't-worry land"
<FromGitter> <sudomaxime> then thousands of people starts using my CMS or framework
<FromGitter> <sudomaxime> then one day, the author of Kamal decides to pull off his shard because of copyright infringement or other reasons
<FromGitter> <tenebrousedge> you can delete gems from rubygems or packages from pypi
<FromGitter> <tenebrousedge> only JS has problems with this
<FromGitter> <tenebrousedge> and AFAIK just that once
<FromGitter> <pynixwang> crystal has no leftpad.
<FromGitter> <tenebrousedge> people have the right to revoke their license for the use of their code
<FromGitter> <sudomaxime> I cant wrap my head around the fact that this problem will happen again and this way of working with dependencies is scary
<FromGitter> <sudomaxime> How is the crystal community self-managing this ? I know that the standard lib is much larger than Node is, so dumb things like left-pad doesn't have to exists
<FromGitter> <tenebrousedge> if you're scared, keep a local repository somewhere. It will probably help performance too. I'm not scared
<FromGitter> <tenebrousedge> I don't think anyone else is particularly scared
<FromGitter> <Blacksmoke16> cant say it ever occurred to me that would happen
<FromGitter> <sudomaxime> I guess I just have to think about this some more and make peace with it
<FromGitter> <pynixwang> `ljust`?
<FromGitter> <Blacksmoke16> less packages required means statistically a smaller chance of it happening
<FromGitter> <tenebrousedge> you can take steps to mitigate these harms
<FromGitter> <Blacksmoke16> esp if most of your "core" libs are maintained by the same trusted source
<FromGitter> <tenebrousedge> are there any shards at the moment that "everyone" uses?
<FromGitter> <sudomaxime> I'm worried because I see the same patterns that I saw when node first came out
<FromGitter> <sudomaxime> Left pad is a famous example, but this problem hapenned bagillion of times for smaller things
<FromGitter> <Blacksmoke16> db drivers is one that comes to mind
<FromGitter> <sudomaxime> I can do a big bet that crystal is going to get very popular in the near future, and shit like this will bubble up
<FromGitter> <Blacksmoke16> im prob just not familiar with this, but what can crystal itself do about it?
<FromGitter> <Blacksmoke16> id imagine a central repo versus github would help?
<FromGitter> <Blacksmoke16> but even then if the ability is there to remove your thing from that repo, like npm, then what can you do?
<FromGitter> <sudomaxime> I'm going to check on NPM terms of use to see what they are saying about this
<FromGitter> <sudomaxime> I think a repo or a repo proxy of some sort would be a step in the right direction
<FromGitter> <tenebrousedge> > When Your Content is removed from npm Services, whether by you or npm, npm's special license ends when the last copy disappears from npm's backups, caches, and other systems. Other licenses, such as open source licenses, may continue after Your Content is removed. Those licenses may give others, or npm itself, the right to share Your Content with npm Services again.
<FromGitter> <tenebrousedge> so npm is free to say, 'we will continue to host and distribute your MIT-licensed content under that license, even if you want it removed'
<FromGitter> <sudomaxime> Yeah I'm not so found of that either
<FromGitter> <tenebrousedge> then don't release your code under a free license
<FromGitter> <sudomaxime> How about a community managed "extended-lib" for crystal ? Basically the community can promote shards that are well written / secure and are not likely to be removed for any reasons
<FromGitter> <tenebrousedge> https://github.com/crystal-community
<FromGitter> <sudomaxime> Folks can still remove stuff from github any day, doesn't fix the issue I am raising :(
<FromGitter> <sudomaxime> (just giving out ideas and concern here, not trying to be a troll or an ass)
<FromGitter> <tenebrousedge> but you don't like npm being able to keep hosting content without user consent either, so there is no soluton
<FromGitter> <sudomaxime> How about a liscence that basically says
<FromGitter> <sudomaxime> Here's a crystal hosted community, by uploading your code you essentially donate it to the community and you understand that we can requests or make changes to the repo and host it permanently
<FromGitter> <sudomaxime> we can deprecate or give warnings in the compiler that basically says
<FromGitter> <sudomaxime> " this solution is deprecated for x, y reasons, you can keep using it, but know that it has X amount of security vulnerabilities "
<FromGitter> <sudomaxime> I think open source is becoming a huge thing for the web, because you can build fast and cheaply essentially because everything is so open ended. The problem is that devs don't take the time to read the code they are pulling and it's making the web less and less secure
<FromGitter> <tenebrousedge> that would be an assignation of ownership rather than a license
<FromGitter> <watzon> @sudomaxime keeps people like @bararchy in business though 😉
<FromGitter> <sudomaxime> :P
<repo> i'm trying to use the static release of crystal but when i compile my program i get Error: can't find file 'prelude'
<repo> i copied share/crystal/src to /usr/lib/crystal
<repo> and there is prelude.cr
<repo> am i missing some env var?
<FromGitter> <sudomaxime> anyways, the road to hell is paved with good intentions
<FromGitter> <kinxer> @sudomaxime One of the nice things about GitHub is that anyone can fork a project. So if a project is popular enough that it's actually widely used, it's very likely that there are at least several up-to-date forks of it. So, in theory, if the repo were to be removed, it wouldn't be too difficult to find a sufficient fork until you decide a more long-term solution.
ht_ has joined #crystal-lang
<FromGitter> <sudomaxime> Would you think having a repo like NPM for crystal would increase the rate of adoption, or the use of github is deliberate ?
teardown has quit [Ping timeout: 265 seconds]
<repo> ah never mind
<repo> extracted to /opt and symlinked the bins to /usr/bin did the trick
teardown has joined #crystal-lang
<FromGitter> <kinxer> I'm not sure. I'm a relatively novice developer (bachelor's degree in CS and ~18 months of full-time developer work), so I don't think I have enough of a historical perspective on how things like NPM, PyPI, Crate, etc., have affected the adoption of those languages. I do know that it's really nice how easy it is to use Shards to either grab a dependency from GitHub or from the internal BitBucket at my work (or
<FromGitter> ... GitLab, or wherever).
<FromGitter> <sudomaxime> That's true, it's easy to make your own shards too
<FromGitter> <sudomaxime> All right, I think I'm being over-cautious here. In the end it's up to the devs and organisations to be responsible for the tools they are using
<FromGitter> <tenebrousedge> crystal could make a more resilient repository, but only by taking choice away from developers
<FromGitter> <straight-shoota> The good thing about git repositories is that it's really easy to have copies hanging around. So it's unlikely any get lost.
<FromGitter> <Blacksmoke16> essentially get a copy of it when you do `shards install` as well
duane has quit [Ping timeout: 240 seconds]
issyl0 has quit [Ping timeout: 260 seconds]
sz0 has quit [Ping timeout: 260 seconds]
jetpack_joe has quit [Ping timeout: 245 seconds]
melthelesbian has quit [Read error: Connection reset by peer]
OvermindDL1 has quit [Ping timeout: 248 seconds]
OvermindDL1 has joined #crystal-lang
<raz> the npm ecosystem is a trainwreck, why would we downgrade to that
jetpack_joe has joined #crystal-lang
<raz> like, would there be a single advantage?
issyl0 has joined #crystal-lang
sz0 has joined #crystal-lang
sz0 has quit [Excess Flood]
<FromGitter> <Blacksmoke16> @kinxer is a new brothers of metal album out
<FromGitter> <Blacksmoke16> 😮
<FromGitter> <kinxer> @Blacksmoke16 I'm sorry, I'm so behind on watching the videos you've sent me... I have no idea. :P
<FromGitter> <Blacksmoke16> :P
<FromGitter> <Blacksmoke16> :metal:
duane has joined #crystal-lang
sagax has quit [Read error: Connection reset by peer]
JuanMiguel has joined #crystal-lang
JuanMiguel has quit [Client Quit]
sagax has joined #crystal-lang
JuanMiguel has joined #crystal-lang
JuanMiguel has quit [Quit: This computer has gone to sleep]
ur5us has joined #crystal-lang
<FromGitter> <Nicolab> Hmm, I've been struggling all day. I can't make a container of callback. ⏎ ⏎ https://play.crystal-lang.org/#/r/8eiv
<FromGitter> <Nicolab> I'm stuck
<FromGitter> <tenebrousedge> well, you can't call a method using its name like that
<FromGitter> <tenebrousedge> maybe you want `Hash(String, Proc)`
<FromGitter> <Nicolab> no
<FromGitter> <Nicolab> need more specific type
<FromGitter> <Nicolab> (compiler error)
<FromGitter> <tenebrousedge> I mean, whatever your Proc type is
<FromGitter> <Blacksmoke16> your alias is what is causing it
<FromGitter> <tenebrousedge> eh?
<FromGitter> <Blacksmoke16> since you're saying the `@@validators` hash's value can be either of those the compiler doesnt know that `:hello` accepts a string versus 2 int32s
<FromGitter> <Blacksmoke16> hence the error
<FromGitter> <Nicolab> Hm
<FromGitter> <Blacksmoke16> would have to cast the union to a specific type, like `.as(Proc(String, Bool))`
<FromGitter> <Blacksmoke16> then do `.call("Crystal")`
<FromGitter> <Nicolab> Ok I try
JuanMiguel has joined #crystal-lang
<FromGitter> <Nicolab> I'm wrong https://play.crystal-lang.org/#/r/8eja
<FromGitter> <Blacksmoke16> your code is running before the `finished` macro
<FromGitter> <Nicolab> Is there an easier way?
<FromGitter> <Nicolab> less freestyle
<FromGitter> <Blacksmoke16> whats the end goal here?
<FromGitter> <Blacksmoke16> writing a validation lib?
<FromGitter> <Nicolab> Yes, but it's also to understand and reproduce with handlers, etc...
<FromGitter> <Blacksmoke16> could just use https://github.com/Blacksmoke16/assert/ 😉
<FromGitter> <Nicolab> I've already seen it, it's not what I'm looking for
<FromGitter> <Nicolab> I have written the rules, a parser, a hundred or so unit tests for functionality. But I'm blocked here :/
<FromGitter> <sudomaxime> Hey guys just coming back on the repo thing from this morning, I think Rust got their repo right with Cargo, check this out: https://doc.rust-lang.org/cargo/faq.html
<FromGitter> <Blacksmoke16> ah, more so looking for a way to define callbacks than validations?
<FromGitter> <Nicolab> yes! :)
<FromGitter> <Blacksmoke16> got an example of the API your shard would use?
<FromGitter> <Nicolab> It's simple but not, I can't do it in Crystal
<FromGitter> <Blacksmoke16> like an example usage*
<FromGitter> <Nicolab> Right now I'm all about parser and callbacks. But 1 minute a search an example
<FromGitter> <Nicolab> I made it in JS...
<FromGitter> <tenebrousedge> @Blacksmoke16 didn't someone write some sort of event library for callbacks?
ur5us has quit [Ping timeout: 260 seconds]
<FromGitter> <Blacksmoke16> and https://github.com/athena-framework/event-dispatcher my take on it
<FromGitter> <Nicolab> I can't find it, it must be on an old backup at the office. ⏎ If I can get the callbacks attached to a key, I'll be happy to show you the result (I'll put it on Github). In short, I should be able to do something like that: ⏎ ⏎ ```def validate(name : Symbol, *arg) ⏎ @@validators[name].call *arg ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e1f71f435e7a119095ce832]
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <Nicolab> I look your example
<FromGitter> <Blacksmoke16> idt thats possible
<FromGitter> <Blacksmoke16> procs have to have their types explicit, so unless all of your validators accept the same amount/types of arguments is prob a nogo (at least i cant think of a way atm)
ur5us has joined #crystal-lang
<FromGitter> <Blacksmoke16> hence why we went with the `Event` type based approach
<FromGitter> <Nicolab> :(
<FromGitter> <Nicolab> May be with a block?
<FromGitter> <tenebrousedge> maybe you want a generic
<FromGitter> <Nicolab> I tried but how can I add custom validators?
<FromGitter> <Nicolab> Same problem
<FromGitter> <Blacksmoke16> would be helpful to see how this is going to be used
<FromGitter> <Nicolab> Or I missed something.
JuanMiguel has quit [Quit: This computer has gone to sleep]
<FromGitter> <Blacksmoke16> depending on the desired API there are prob a few optoins
<FromGitter> <Nicolab> The rules are defined like: ⏎ ⏎ ```[{:min => [1]}, {:in => ["en", "fr"]}``` [https://gitter.im/crystal-lang/crystal?at=5e1f73eec86a6f1fb3830889]
<FromGitter> <Blacksmoke16> 😬
<FromGitter> <Blacksmoke16> that seems hard
<FromGitter> <Nicolab> `min` and `in` are 2 functions that receive the arguments (preferably not in array but if I don't have the choice)
<FromGitter> <Blacksmoke16> could iterate over key/values and use a `case` to execute the correct code?
<FromGitter> <Nicolab> by doing that, you can't add a custom validator.
<FromGitter> <Blacksmoke16> > I've already seen it, it's not what I'm looking for ⏎ ⏎ im just curious, was there a feature or something it didnt have or?
<FromGitter> <Nicolab> or with macro but I don't see how, most ORM do something like this...
<FromGitter> <tenebrousedge> I think I'd want syntax like `validate :property, min: 3, max: 5` or `validate :property { property.foobar }`
<FromGitter> <Nicolab> Yes
<FromGitter> <tenebrousedge> or perhaps `validate :property {|p| p.foobar }`
<FromGitter> <Blacksmoke16> ```@[Assert::InRange(Range(Int32, Int32), range: 3..5)] ⏎ property fav_number : Int32``` ⏎ ⏎ :sad: [https://gitter.im/crystal-lang/crystal?at=5e1f7576df9e137d58ed8ee5]
<FromGitter> <tenebrousedge> I mean, assertions are fine too, but syntax-wise not my favorite
<FromGitter> <Nicolab> The difficulty is to store the validators, a mapping: `"validator_name" => function or block`
<FromGitter> <Blacksmoke16> but i would prob advise not doing it the way they did, depending on your use case
<FromGitter> <Nicolab> I've been meditating and fiddling with this example all day, but I haven't been able to adapt it to my own needs.
<FromGitter> <Blacksmoke16> yes, it works for granite since all validators have the same types
<FromGitter> <Blacksmoke16> `Granite::Base, Bool`
<FromGitter> <Nicolab> ok
<FromGitter> <Blacksmoke16> versus how you want to do it where each validator has diff types in the proc
<FromGitter> <Blacksmoke16> could you not use structs or something for this?
<FromGitter> <Blacksmoke16> `InRangeAssertion.new(3, 5)` ?
<FromGitter> <Blacksmoke16> idk
<FromGitter> <Nicolab> It's good but I'm not fan of the Symfony way
<FromGitter> <Nicolab> All I have to do is figure out a way to run the validators. It'd be a shame to give up.
<FromGitter> <Blacksmoke16> use a macro to cast the union for you?
<FromGitter> <Blacksmoke16> macro validate(data, key, *args) ⏎ @@validators[{{key.symbolize}}].as(Proc({{args.splat}}, Bool)).call *data ⏎ end
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e1f781f25256256b7fa5ac8]
<FromGitter> <Blacksmoke16> something like that
<FromGitter> <Nicolab> If it works, that would be great, I'm testing
<FromGitter> <Blacksmoke16> deff not going to, but something like it may
<FromGitter> <tenebrousedge> does `args.splat` work like that, to get the types?
<FromGitter> <Nicolab> ok
<FromGitter> <Blacksmoke16> i was assuming it would work like `validate {"Crystal"}, :hello, String`
<FromGitter> <Blacksmoke16> let me try something
<FromGitter> <Nicolab> I'm going to put the kids to bed. I'll be back in five minutes.
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8elz
<FromGitter> <Blacksmoke16> not sure what the level of hack that should be considered but :shrug;
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
alexherbo2 has joined #crystal-lang
<FromGitter> <Nicolab> I'm back.
<FromGitter> <Nicolab> Oh great!
<FromGitter> <Nicolab> do you think there's a way to generate additional Proc in the ProcTypes?
<FromGitter> <Blacksmoke16> probably
<FromGitter> <Nicolab> Thank you, it frees me up to moving forward. I couldn't fight it anymore.
<sorcus> Blacksmoke16: https://play.crystal-lang.org/#/r/8eeg - where you find `ProcType`? I can't find it in Crystal book and Crystal API.
<FromGitter> <Nicolab> it's an alias
<FromGitter> <Nicolab> @sorcus
<FromGitter> <Blacksmoke16> oh, its just a generic arg
<FromGitter> <Blacksmoke16> like you dont have to use `T`
<sorcus> Mmm, ok. Thanks. :-)
<FromGitter> <Blacksmoke16> am i missing something here? https://play.crystal-lang.org/#/r/8enj
<FromGitter> <Blacksmoke16> shouldnt the ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ make it so the compiler knows what to do? [https://gitter.im/crystal-lang/crystal?at=5e1f8598123d916da242b716]
<FromGitter> <Blacksmoke16> also happens with ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e1f85b951fcd0256c94af34]
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8enl it seems my object is not is a Serializable?
<FromGitter> <Fryguy> Serializable doesn't define serialize from what I can see
<FromGitter> <Blacksmoke16> it shouldnt have to, im calling a method within the `JSON` module itself it it is
<FromGitter> <Blacksmoke16> i.e. it should never call `#serialize` on something that includes the module
<FromGitter> <Fryguy> Oh I missed the `unless` bit... Yeah this is weird
<FromGitter> <Blacksmoke16> ill see if i can reduce it when i get home
<FromGitter> <Blacksmoke16> the real problem is why in the second link ⏎ ⏎ ```#<Bar:0x7f86068ade80 @id="bar"> ⏎ false``` [https://gitter.im/crystal-lang/crystal?at=5e1f879e84894f56b66750a9]
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8eo2 works if i make it a class
<FromGitter> <Fryguy> I think you need to use if/else
<FromGitter> <Blacksmoke16> i also tried that, https://play.crystal-lang.org/#/r/8eo5
<FromGitter> <Fryguy> Otherwise, regardless of the `next`, the compiler doesn't constrain the type after the unless block
<FromGitter> <Blacksmoke16> root cause is `.is_a?` is returning `false` even tho that type includes the module
<FromGitter> <Fryguy> Beyond that I'm not sure 😕
ht_ has quit [Quit: ht_]
<FromGitter> <Blacksmoke16> omg
<FromGitter> <Blacksmoke16> i know why
<FromGitter> <Blacksmoke16> fml
<FromGitter> <Blacksmoke16> since its in the `JSON` namespace, its comparing it with https://crystal-lang.org/api/master/JSON/Serializable.html not my type
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8eog fixed :)
<FromGitter> <Nicolab> Is there a way to define a macro variable, accessible in a macro? https://play.crystal-lang.org/#/r/8eof
<FromGitter> <Blacksmoke16> `{% types = "foo" %}`?
<FromGitter> <Nicolab> > Error: undefined macro variable 'types'
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8eoj ?
<FromGitter> <Nicolab> Yes, thanks! I don't see where I went wrong, do you see it?
<FromGitter> <Blacksmoke16> you never defined the `types` variable
<FromGitter> <Blacksmoke16> hence the error `undefined macro variable 'types'`
<FromGitter> <Nicolab> ah! I didn't realize you redefined it.
<FromGitter> <Blacksmoke16> `defined` it was never defined in the first place 😉
<FromGitter> <Nicolab> I defined it at the top of the macro, to have it accessible in the macros but I don't know if it's possible.
<FromGitter> <Daniel-Worrall> @straight-shoota After looking at the makefiles on distribution-scripts, I went to see if there was anything that could be improved. The dockerfiles that use git clone and checkout a specific tag could use a shallow copy (ala `git clone --branch BRANCH --depth 1`) so they only receive the relevant stuff and not the full git history. ⏎ ⏎ Is this something that would be considered? If not, I won't
<FromGitter> ... bother.
<FromGitter> <Blacksmoke16> ah, well no thats not in the macro
<FromGitter> <Nicolab> This is my question :)
<FromGitter> <Blacksmoke16> you can reference constants in macros tho
<FromGitter> <Nicolab> Ok, not an array or something dynamic (a hash...)?
<FromGitter> <Daniel-Worrall> It'll make some of the processing quicker, and it might reduce the docker image size
<FromGitter> <perfecto25> Hello, is it possible to get the official CR docs in a pdf file?
<FromGitter> <Nicolab> My attempt is to put the types when adding the methods, then call the validate after
<FromGitter> <Nicolab> @Blacksmoke16
<FromGitter> <Nicolab> and other of course :)
<FromGitter> <Nicolab> It's not going to work, so I'm going to drop the idea of writing the types with macros, I'm going to list them by hand until I know how to do it. If there's ever anyone who has a solution I'm interested in...
<FromGitter> <Nicolab> Thanks
<FromGitter> <straight-shoota> @Daniel-Worrall Yeah, sure that sounds like an improvement. Probably not terribly important, but welcome anyways.
<FromGitter> <Daniel-Worrall> I just like the idea of small optimisations :)
<FromGitter> <straight-shoota> @perfecto25 Currently not. Which docs are you talking about API or language reference?
<FromGitter> <straight-shoota> You might take a look at https://pryp.in/crystal.html The builds are outdated, but the generation script is also available.
<FromGitter> <straight-shoota> If you just want offline API docs, you should take a look at https://devdocs.io/crystal/ which offers an offline mode (go to preferences to download).
<FromGitter> <straight-shoota> Besides that you can also download the docs archive: https://github.com/crystal-lang/crystal/releases/download/0.32.1/crystal-0.32.1-docs.tar.gz But devdocs is more user friendly
<FromGitter> <tenebrousedge> devdocs <3 <3
<FromGitter> <Daniel-Worrall> It doesn't have latest though :(
<FromGitter> <Daniel-Worrall> does it really need a PR for each version
<FromGitter> <tenebrousedge> I guess?
ur5us has quit [Ping timeout: 260 seconds]
ur5us has joined #crystal-lang
<FromGitter> <Blacksmoke16> @Nicolab got an example of what you were trying to do?
yukai has joined #crystal-lang
<FromGitter> <Nicolab> @Blacksmoke16 Same as before, I just want to define functions and be able to call them. By having the name in string for example and the arguments in an array. If this is not possible and another format is needed, why not.
<FromGitter> <Nicolab> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e1f9b1e123d916da2436c94]
<FromGitter> <Nicolab> with `rule_name` as the function name and `args` as arguments
<FromGitter> <Nicolab> Perhaps the ideal would be to use ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e1f9c098b5d766da1b03e51]
<FromGitter> <Blacksmoke16> Not sure I follow how method_added fits into this
ht_ has joined #crystal-lang
<FromGitter> <Nicolab> Because I can't find any solution, so I try with a macro / hook to add it in `@@validators`.
<FromGitter> <Nicolab> The hook is well called, I can add the symbol and then I search to add the method.
alexherbo25 has joined #crystal-lang
<FromGitter> <Nicolab> I tried with a register like it: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e1f9eff51a9c24bafa0e4c8]
<FromGitter> <Nicolab> But doesn't work
alex`` has quit [Ping timeout: 258 seconds]
alexherbo2 has quit [Ping timeout: 240 seconds]
alexherbo25 is now known as alexherbo2
alex`` has joined #crystal-lang
<FromGitter> <Nicolab> I've explained everything, I don't see how I can make it any clearer :(
<FromGitter> <Blacksmoke16> because of the union
<FromGitter> <Blacksmoke16> you cant just dynamically execute code like in ruby
<FromGitter> <Blacksmoke16> because the value of the `@@validators` hash could be either a `Proc(Int32, Int32, Bool)` or `Proc(String, Bool)`
<FromGitter> <Nicolab> if I have to list everything by hand, fine, I'll do it, but it doesn't work.
<FromGitter> <Nicolab> 12 hours for a callback, It's crazy... I'm disgusted.
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8eq0
<FromGitter> <Blacksmoke16> i have an idea for you, give me a bit
ur5us has quit [Ping timeout: 260 seconds]
<FromGitter> <Blacksmoke16> are your validators just going to be random methods on the type?
<FromGitter> <Nicolab> Yes
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8eq4
<FromGitter> <Blacksmoke16> something like that
<FromGitter> <Blacksmoke16> use a macro to set the type automatically
<FromGitter> <Blacksmoke16> each validator has its own alias, that you map to name
<FromGitter> <Blacksmoke16> could prob use annotations to build out the hash at compile time as well
<FromGitter> <Blacksmoke16> and the aliases for that matter
<FromGitter> <Nicolab> That's one solution, thanks! I'm trying with the `validate' from earlier to see if we can do without constancy and simplify the addition of custom validators.
<FromGitter> <Blacksmoke16> i mean it would just work assuming the user reopens the module, adds their method with the annotaiton
<FromGitter> <Nicolab> Oh!?
<FromGitter> <Nicolab> I try