<jokke>
is there something similare like sinatras mounts for kemal?
<jokke>
so that i could subclass something like Sinatra::Base and mount it at some route?
<jokke>
also, are kemal requests multithreaded? (i know, there's no _real_ multithreading yet), but i'm asking if one long request is blocking subsequent requests.
<BlaXpirit>
^try and see
<jokke>
:)
<jokke>
BlaXpirit: what about the other points?
<BlaXpirit>
no idea. i'm not interested in crystal for web at all
<jokke>
ok
<BlaXpirit>
sure is quiet here, almost all the nicks i've never seen speak
pawnbox has quit [Ping timeout: 256 seconds]
Bofu2U has left #crystal-lang ["Textual IRC Client: www.textualapp.com"]
<jokke>
are there any plans on making JSON.mapping extendable by subclasses?
<jokke>
or is it maybe already possible, and i just don't know about it
trapped has joined #crystal-lang
<jhass>
what do you mean by extendable?
<jokke>
jhass: let's say i have an abstract class A that defines some json mapping. then i have classes B, C and D extending A and defining additional mappings to the ones A defined
<jhass>
ah no, I don't think you can do inheritance yet
<jhass>
only composition
<jokke>
jhass: how?
<jhass>
simply by using an existing mapping as type
<jokke>
yeah ok
<jokke>
sure
<jokke>
is the type automatically used as converter then?
<jokke>
meaning if type == converter, i only have to define type?
tomchapin has joined #crystal-lang
<jokke>
also what about type: Array(SomeMapping)? does that kind of thing work ootb?
<jokke>
or do i have to provide a converter which parses the json array?
<jhass>
there's simply no need to specify it as a converter
<jhass>
a json mapping can receive a pull parser
<jhass>
and that's how it works internally
<jhass>
yes
<jhass>
no need for a converter
<jokke>
yeah ok. so it just calls Type.new(pull)
<jokke>
ok that's convenient
<jokke>
i really like the mappings
<jokke>
(yaml and json)
<jokke>
the only problem is when you got types that are only apparent after the json has been parsed
<jokke>
like when there's some "type" value in the json
<jhass>
yeah, I'd still double parse in that case
<jokke>
in that case it'd be great if there would be some kind of "pass-through" mode for the pull parser to get the json string
<jokke>
you know what i mean?
<jhass>
I can't imagine anything making much sense I'm afraid
<jokke>
so if i have some SometimesThisSometimesThatMapping it could parse the json and simultaniously write it back into a string which it would then pass to either ThisMapping.new or ThatMapping.new, depending on some "type" value
<jokke>
not the string, but a pull parser for that string of course
<jokke>
as far as i know, now the only way to do it is by parsing the stuff, then decide the type, then pass that stuff .to_json to the actual type, right?
<jhass>
I'd do case TypeMapping.from_json(json_string).type; when "foo"; FooMapping.from_json(json_string); when "bar"; BarMapping.from_json(json_string); end
<jhass>
depending on context with some macro sugar
<jokke>
jhass: but in a JSON.mapping i don't have access to the json string
<jhass>
I don't see how that's relevant to my suggestion
<jokke>
well if you assume your polymorphic json mapping type is somewhere at a deep level of a larger json mapping
<jokke>
then you have a problem
<jhass>
well I didn't
<jokke>
:)
<jhass>
of course my suggestions only apply to the requirements stated
<jokke>
yeah, i wasn't clear on that
<jokke>
so for those cases it'd be great if JSON::PullParser would have some kind of read_*_as_string method
<jokke>
but maybe i'm just overcomplicating things.
<jokke>
it won't kill me to read a hash of String => JSON::Type and then to_json it again
<jokke>
oh i just realized, that i can't do that either...
<jokke>
JSON::Parser doesn't use a pull parser
<jhass>
yeah, a pull parser interface over JSON::Any is still something that would be interesting
<jhass>
maybe mapping everything to iterators and building a stack of those, mmh
ponga has joined #crystal-lang
<jokke>
yeah
tomchapin has quit [Read error: Connection reset by peer]
pawnbox has quit [Ping timeout: 252 seconds]
tomchapin has joined #crystal-lang
Sadin has joined #crystal-lang
shama has joined #crystal-lang
<asterite>
Parsing polymorphic JSONs would be really nice. I guess there's no other way to do it other than parsing it twice, so that would be fine by me. Maybe what you did in the past (jhass), parsing from a json/any into an object could work
tomchapin has quit [Read error: Connection reset by peer]
pawnbox has quit [Remote host closed the connection]
ponga has quit [Quit: Connection closed for inactivity]
fka has quit [Remote host closed the connection]
greengriminal has joined #crystal-lang
Excureo has quit [Remote host closed the connection]
tomchapi_ has quit [Read error: Connection reset by peer]
tomchapin has joined #crystal-lang
Sadin has joined #crystal-lang
<jokke>
hey
<jokke>
i have another question about kemal
<jokke>
i'm writing a json api and it feels repetetive to always have to set content type to application/json
Philpax has joined #crystal-lang
<jokke>
so would this call for a handler? which set's the content type and calls next?
<jokke>
and i have another problem with kemal: i want to use my own error handler
<jokke>
so that i can raise a custom error class (or subclasses of it)
<jokke>
i tried wrapping call_next with begin ... rescue e : MyError and handle it in the rescue block but it seems that kemals own handler catches it before me
Sadin has quit [Ping timeout: 260 seconds]
fka has joined #crystal-lang
Philpax has quit [Ping timeout: 276 seconds]
tomchapin has quit [Read error: Connection reset by peer]
srenatus has quit [Quit: Connection closed for inactivity]
Excureo has joined #crystal-lang
tomchapin has joined #crystal-lang
pawnbox has joined #crystal-lang
fka has quit [Remote host closed the connection]
pawnbox has quit [Ping timeout: 272 seconds]
greengriminal has quit [Quit: Leaving]
<jokke>
ah never mind, found out about Kemal.config.error_handler