<FromGitter>
<Timbus> let me know if it works. also make a gitlab issue, now that you have all the details
<FromGitter>
<opensas_gitlab> > I'm any case, dependency injection requires runtime reflection, so that's not possible to implement
<FromGitter>
<Timbus> ?
<FromGitter>
<opensas_gitlab> Thanks a lot for your reply (I couldn't follow the conversation) What would be the more appropriate way to achieve DI (or something like that) in Crystal then? Or is it just something to be taken care of later in Crystal development.
<FromGitter>
<drum445> After our conversation yesterday I had a go at a little sql result set to object library ⏎ https://github.com/drum445/objectify
<FromGitter>
<drum445> Could you please have a look and let me know where it can be improved/what I have done wrong :)
lvmbdv has quit [Remote host closed the connection]
wojnar has quit [Remote host closed the connection]
<FromGitter>
<drum445> Ha that from_rs Is what I was after cheers, do you know any way of adding a class as a param?
<FromGitter>
<drum445> instead of having to manually map all the ?
<FromGitter>
<Timbus> Do you mean like.. you want to make a normal class and have something generate a mapping? instead of using a mapping to generate a class?
<FromGitter>
<drum445> So when you have an insert statement i want the vales to populate from a class
<FromGitter>
<Timbus> ohh
<FromGitter>
<drum445> Instead of having a load of question marks
<FromGitter>
<Timbus> I don't think it currently exists. I guess you could so it with a macro
<FromGitter>
<drum445> Cool that can be my lib then ;) Room for it after all
return0e_ has quit [Remote host closed the connection]
<FromGitter>
<asterite> I'm not sure why JSON is involved in what you are doing
<FromGitter>
<drum445> I couldn't find a reflection package in crystal so I can call the attributes via varaible
return0e has joined #crystal-lang
<FromGitter>
<asterite> Well, if JSON can do it, you can probably too :-) But yeah, it's not easy. There's compile-time reflection. You can define `sefl.to_sql(script : String, object : T) forall T` and then inside do something like `{% for ivar in T.instance_vars %}` using macros. But you'll have to learn a few things to manage to do it.
<FromGitter>
<drum445> Does crystal not have a send method like ruby?
<FromGitter>
<drum445> Not sure why we don't have a get attribute by name method
<FromGitter>
<rishavs> How do I rescue an exception with a specific error message? I know, I can "rescue DB::Error" , but I can't ` rescue DB::Error:no rows`. Of course, I can just check for the message in an if-else block but was wondering if this is possible with Raise method itself
<FromGitter>
<asterite> @drum445 no, there's no runtime reflection in crystal
<FromGitter>
<asterite> @rishavs not possible
<FromGitter>
<rishavs> ok. Thanks. I will just proceed with a string match in my rescue block
<oz>
it looks like Packt pub is looking for authors to co-author a book about Crystal...
<FromGitter>
<straight-shoota> @rishavs there is #1124 discussing this feature
<FromGitter>
<drum445> Shame about runtime reflection, what alternative is on offer then?
<FromGitter>
<rishavs> @straight-shoota Thanks 👍
<FromGitter>
<straight-shoota> But if the kind of error message demands different behaviour, it is likely that you should rather have more specific exception types.
<FromGitter>
<straight-shoota> @drum445 compile time reflection with macros 👍
<FromGitter>
<drum445> Could you give me an exmaple please my good sir
<FromGitter>
<asterite> I might try to implement exception filters, at least a first approach. Later we could limit them to avoid introducing new local variables
<FromGitter>
<jwoertink> on the `{{attr.id}}`, you don't want the `.id`
<FromGitter>
<jwoertink> if you were passing a string literal like `t, "name", "Gary"`, then you'd use the `.id` to say "don't use the string, use what the string outputs to"
<FromGitter>
<jwoertink> This is where it gets in to some tricky things. Currently it expands to the literal variable names. Since your variable is called `attr`, that's what the macro will expand to
<FromGitter>
<jwoertink> oh, there you go!
<FromGitter>
<j8r> Macros is about text
<FromGitter>
<jwoertink> I guess you do need the .id
<FromGitter>
<jwoertink> I really don't understand them, so I avoid using them if I can lol
<FromGitter>
<j8r> If you write `"mystring"`, this will be exactly this text passed to the macro
<FromGitter>
<j8r> if you only want the value that it represent, add an `.id`
<FromGitter>
<drum445> I have an array of strings
<FromGitter>
<drum445> and for each one I need to call that send method
<FromGitter>
<drum445> but it can't
<FromGitter>
<j8r> Macro are in compile time, they expands when you compile
<FromGitter>
<j8r> so you can't set a variables when running a macro - every arguments are taken as text
<FromGitter>
<adamgotterer_twitter> I'm having trouble figuring out what library I need to install on MacOS to be able to build a release. I'm getting the following error: ⏎ $ crystal build run.cr --release --static ⏎ ld: library not found for -lcrt0.o (this usually means you need to install the development package for libcrt0.o) ⏎ clang: error: linker command failed with exit code 1 (use -v to see invocation) ⏎ Error:
<FromGitter>
<asterite> shouldn't it error? It seems it just prints that info and lets you do it anyway
<RX14>
I dislike that PR
<RX14>
it's the totally wrong approach
<FromGitter>
<j8r> It print an information because it seems some may statically link on macOS
<FromGitter>
<straight-shoota> @j8r it prints this message whenever you are running the compiler with `--static` on MacOS. This is incorrect, because you can, for example, cross-compile to a target that supports static linking.
<FromGitter>
<drum445> seems to work as expected :)
baweaver_away is now known as baweaver
<FromGitter>
<rishavs> Hi. I am trying to put my app on Heroku. WHat should go into the Procfile? I see some apps using `web: crystal run src/server.cr` but this isn't the command for the production mode, is it?
<FromGitter>
<fridgerator> well you need to build it first with `crystal build file.cr --release`
<FromGitter>
<fridgerator> then run the build exectuable `./file`
<FromGitter>
<rishavs> I am having trouble deploying my app on heroku. M app is building properly without any issues. However, on deployment i getting the following error in my logs; ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b465ab71c0f906b1448f0b0]
<FromGitter>
<rishavs> is this likely a buildpack error?
<FromGitter>
<bew> I don't think so, you can hide this under a method, but in the end it will be what you wrote
<FromGitter>
<drum445> Is there anyway to initialize a class without having to call the initialize method, so I can then manually set the fields afterwards
<FromGitter>
<jspillers> it would be cool if `#to_h` took key/value types so you could just do `named_tuple.to_h(String, String)` and have it automatically cast
<FromGitter>
<bew> @jspillers it's not just a cast, it has to do a method call to get the string version of each symbols
<FromGitter>
<jspillers> right
<FromGitter>
<bew> Well you can always implement it yourself
<FromGitter>
<drum445> I'm very much struggling to turn a SQL result set into an object or array of object without having to set all my class attributes to Foo | Nil
<FromGitter>
<j8r> Try to avoid Nil unions as much as possible
<FromGitter>
<j8r> Catch them early, and raise when they occurs (or something else)
<FromGitter>
<drum445> I don't think this is possible due to language constraints then
<FromGitter>
<drum445> well not constraints just design
<FromGitter>
<drum445> shame
<FromGitter>
<bew> @drum445 it depends on your usecase, really: is it ok if some fields are missing? If not then you have an error, and you should handle it too
<FromGitter>
<j8r> I think you are designing like in a dynamic language rather than a static one
<FromGitter>
<drum445> This is what I'm working on: https://github.com/drum445/objectify ⏎ IF you look at the part "Result set to object", see they all need to be nil union, I don't want that but can't see away around it with my current lib
<FromGitter>
<drum445> @j8r I'm trying to mimic what dapper does in .net core
<FromGitter>
<j8r> You can also set the String to an empty one, or the Int64 to 0
<FromGitter>
<drum445> I can't as it's not being initialized in a standard way
<FromGitter>
<drum445> I need an empty version of that class then I work on assigning attributes
<FromGitter>
<j8r> Like `property mystring = ""` ?
<FromGitter>
<j8r> You can have an empty initialize method
<FromGitter>
<drum445> but it seems a mess to have to give every field a default
<FromGitter>
<bew> You could also define an initialize method that initializes all the fields at once, and your code will just get all the values, and create the object at the end with all the gathered fields
<FromGitter>
<drum445> I did try something like that, but it doesn't work with how I'm initializing the object
<FromGitter>
<drum445> I won't know what fields I have until it runs
<FromGitter>
<j8r> So you have no other choice, you have to deal with dynamic structures like Hash, Array
<FromGitter>
<j8r> And String of course
<FromGitter>
<drum445> from_json seems to achieve what I want though
alex`` has quit [Read error: Connection reset by peer]
<FromGitter>
<j8r> from_json ?
<FromGitter>
<drum445> yeah if you have a class with JSON.mapping you can initialize it from a json string
<FromGitter>
<drum445> which can only contain some of the fields, and you don't need an initialize method
<FromGitter>
<j8r> Yes, this means not all fields are dynamic after all
<FromGitter>
<bew> @drum445 note that JSON.mapping will generate a initialize method
<FromGitter>
<drum445> oh yeah, do you reckon it simply creates one with all the defaults?
<FromGitter>
<drum445> but, some of them are nil. I don't get it lol
<FromGitter>
<bew> Which defaults are you talking about ?
<FromGitter>
<drum445> defaults for all object types
<FromGitter>
<drum445> string, int, float etc...
<FromGitter>
<drum445> Because of how Crystal deals with nil where it becomes a union type it makes it a lot different to other languages like .net or go
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter>
<j8r> For go nil is error, no? You can also raise on nil
<FromGitter>
<drum445> ah well, fighting a losing battle I think. Either my Crystal skills have peaked or I'm trying to use it in a way it wasn't intended ⏎ Seems a real shame not to be able to convert a SQL result set to a class
<FromGitter>
<drum445> without pissing about with mappings
<FromGitter>
<asterite> Ed: when parsing json, if a field without a default value is missing, an exception is raised. You could do the same. Basically you have to copy what JSON::Serializable does