02:01
<
FromGitter >
<Blacksmoke16> is a PR to fix it when doing `#to_h`
02:01
<
FromGitter >
<eliasjpr> no
02:01
<
FromGitter >
<eliasjpr> I just open a ticket
02:01
<
FromGitter >
<eliasjpr> I need to look into the current implementation to propose a fix
02:02
<
FromGitter >
<Blacksmoke16> however the `#create` or `#new` is going to be a bit more tricky
02:02
<
FromGitter >
<Blacksmoke16> since you cant use `Enum` in a union
02:02
<
FromGitter >
<eliasjpr> yeah
02:02
<
FromGitter >
<eliasjpr> No?
02:02
<
FromGitter >
<Blacksmoke16> nope
02:02
<
FromGitter >
<eliasjpr> You cant use an Enum in a union? WTF!
02:02
<
FromGitter >
<eliasjpr> Is a type no?
02:02
<
FromGitter >
<Blacksmoke16> not like `Enum`
02:02
<
FromGitter >
<Blacksmoke16> but `MyEnum` would work
02:03
<
FromGitter >
<Blacksmoke16> so either we can maybe remove some type restrictions on new/create to allow anything, or define some way to "register" custom types?
02:04
<
FromGitter >
<Blacksmoke16> yea you could use `ProductTypes` in a union, but not the base `Enum` type
02:04
<
FromGitter >
<Blacksmoke16> i.e. like `alias = String | Int32 | Enum`
02:04
<
FromGitter >
<eliasjpr> got it
02:05
<
FromGitter >
<eliasjpr> We should be able to push the custom type to the `Granite::ModelArgs`
02:05
<
FromGitter >
<eliasjpr> I would expect that each model would have a `ModelArgs` constant that we can add the custom type
02:05
<
FromGitter >
<Blacksmoke16> i have an idea
02:06
<
FromGitter >
<Blacksmoke16> i wonder if we can generate that alias based on types in the model
02:06
<
FromGitter >
<eliasjpr> that should would since the column is a macro
02:06
<
FromGitter >
<Blacksmoke16> sec
02:07
<
FromGitter >
<eliasjpr> Like `alias ModelArgs = Bool | ProductType` in my case?
02:08
<
FromGitter >
<Blacksmoke16> like i did for `#to_h`
02:08
<
FromGitter >
<eliasjpr> just started to look at the PR
02:09
<
FromGitter >
<eliasjpr> Yeah I see what you did
02:09
<
FromGitter >
<eliasjpr> but instead of having the fields inside the method we should be able to create a reusable constant. Wdyt?
02:10
<
FromGitter >
<eliasjpr> `ModelTypes = {{"Hash(String, Union(#{@type.instance_vars.select { |ivar| ivar.annotation(Granite::Column) }.map(&.type.id).splat})).new".id}}`
02:11
<
FromGitter >
<Blacksmoke16> hmm can you use a const as a type restriction like that?
02:13
<
FromGitter >
<eliasjpr> I believe is doable since is a constant (pre compilation), we can also do an alias
02:15
<
FromGitter >
<eliasjpr> that will work for me.
02:15
<
FromGitter >
<eliasjpr> And I like having the alias per model definition since it will allow me to create any method that takes that union alias
02:16
<
FromGitter >
<eliasjpr> This works too `MODEL_TYPES = Union(Int32 | String)`
02:17
<
FromGitter >
<Blacksmoke16> cool yea, and looks like you can define an alias per model
02:17
<
FromGitter >
<Blacksmoke16> let me see if i can get this working
02:17
<
FromGitter >
<eliasjpr> This makes me think that `(alias TYPE = Int32 | String) == (MODEL_TYPES = Union(Int32 | String)) `
02:18
<
FromGitter >
<Blacksmoke16> think it has to be `alias`
02:19
<
FromGitter >
<eliasjpr> im fine with that, what ever works :)
02:22
<
FromGitter >
<eliasjpr> I really like the idea of having the `MODEL_TYPES` restricted only to the types defined for that model
02:24
<
FromGitter >
<Blacksmoke16> i dont think i can be done
02:24
<
FromGitter >
<Blacksmoke16> only have access to the ivars within a method
02:24
<
FromGitter >
<Blacksmoke16> :/
02:25
<
FromGitter >
<Blacksmoke16> let me try something else
02:28
<
FromGitter >
<Blacksmoke16> hm
02:29
<
FromGitter >
<Blacksmoke16> we can, but how would you define the `ModelArgs` type?
02:29
<
FromGitter >
<eliasjpr> within the macro
02:29
<
FromGitter >
<Blacksmoke16> based on ivar types?
02:29
<
FromGitter >
<Blacksmoke16> oh
02:30
<
FromGitter >
<Blacksmoke16> i have an idea
02:30
<
FromGitter >
<eliasjpr> we keep appending to the constant 😅 :
02:30
<
FromGitter >
<eliasjpr> so each model overwrites the ModelArgs constants from Granite::Base
02:37
<
FromGitter >
<Blacksmoke16> should be doable
02:37
<
FromGitter >
<eliasjpr> yeah, it might take some thinking before approaching
02:39
<
FromGitter >
<Blacksmoke16> indeed
02:43
<
FromGitter >
<Blacksmoke16> well there's a problem
02:43
<
FromGitter >
<Blacksmoke16> granite supports converting string input to their types
02:45
<
FromGitter >
<Blacksmoke16> holy shit it worked
02:48
<
FromGitter >
<Blacksmoke16> Will have to think more if this would work
02:51
<
FromGitter >
<eliasjpr> :0
10:37
feepbot has quit [Ping timeout: 240 seconds]
10:41
feepbot has joined #amber
12:48
<
FromGitter >
<Blacksmoke16> neat
13:21
<
FromGitter >
<eliasjpr> I am running into a problem
13:22
<
FromGitter >
<eliasjpr> I cannot generate the alias because @type.instance_vars is only available at the instance level
13:25
<
FromGitter >
<Blacksmoke16> right, you'd have to do that mutable constant thing you were talking about
13:25
<
FromGitter >
<Blacksmoke16> declare it as empty array and push the type within the `column` macro
13:26
<
FromGitter >
<eliasjpr> we would have to convert the array into an Union after
13:26
<
FromGitter >
<eliasjpr> thats where I am stuck
13:26
<
FromGitter >
<Blacksmoke16> thats easy enough
13:26
<
FromGitter >
<Blacksmoke16> just call `.splat` on the array
13:27
<
FromGitter >
<eliasjpr> sweet
13:27
<
FromGitter >
<Blacksmoke16> and use `Union()`
13:27
<
FromGitter >
<Blacksmoke16> not sure im a big fan of bringing back some mutable constants tho
13:27
<
FromGitter >
<Blacksmoke16> also requires the user use the macro
13:27
<
FromGitter >
<Blacksmoke16> the user to use the*
13:28
<
FromGitter >
<Blacksmoke16> would it not be doable to just remove/loosen the restrictions by default?
13:28
<
FromGitter >
<eliasjpr> Well the idea this constant will only mutate before compilation
13:29
<
FromGitter >
<eliasjpr> I mean I can live with me defining the ModelArgs alias manually
13:30
<
FromGitter >
<Blacksmoke16> hmm
13:34
<
FromGitter >
<eliasjpr> I basically created a helper module
13:38
<
FromGitter >
<Blacksmoke16> gotcha
13:41
<
FromGitter >
<eliasjpr> I would be nice to generate that alias
13:43
<
FromGitter >
<Blacksmoke16> i had that working
13:45
<
FromGitter >
<eliasjpr> show me
13:45
<
FromGitter >
<eliasjpr> 😅
13:54
<
FromGitter >
<Blacksmoke16> something like that
13:57
<
FromGitter >
<Blacksmoke16> always push string because of that case i put yesterday
20:03
<
FromGitter >
<eliasjpr> I think I am going to switch over to Clear
20:16
<
FromGitter >
<Blacksmoke16> oh?
20:24
<
FromGitter >
<eliasjpr> Yeah it seems that it has all the needed features to ease Dev
20:25
<
FromGitter >
<Blacksmoke16> i remember it was quite nice when i tried it a while ago
20:26
<
FromGitter >
<Blacksmoke16> but couldnt use annotations and serialization was less useful than granite was
20:26
<
FromGitter >
<Blacksmoke16> but its been a while
21:15
<
FromGitter >
<eliasjpr> If it wasn’t because of the enums custom types I would stick to granite
21:16
<
FromGitter >
<eliasjpr> But I need to come up with a poc soon and I don’t want to wait until the next release
21:16
<
FromGitter >
<eliasjpr> Clear has similar Api
21:22
<
FromGitter >
<Blacksmoke16> its less than ideal but you could just do like
21:23
<
FromGitter >
<Blacksmoke16> ```model = MyModel.new(val: 1, name: "string")```
21:23
<
FromGitter >
<Blacksmoke16> ```model.enum = MyEnum::One```
21:23
<
FromGitter >
<Blacksmoke16> only problem is including it within `#new` or `#create`