basho / cuttlefish

never lose your childlike sense of wonder baby cuttlefish, promise me?
Apache License 2.0
205 stars 124 forks source link

Added prioritization of schema files. #71

Closed Licenser closed 10 years ago

Licenser commented 10 years ago

Fixing the behavior described in #70.

This patch changes the behavior of schema loading slightly, each schema gets a priority assigned, this priority is based on the alphabetical order. The priority is stored in both mappings and translations, putting them in validators would be easy but did not seem to make sense to me.

This allows mappings and transactions to be applied in any order while retaining the priority/order they had in regards to the loaded schema files. It works like this:

00.schema -> priority 2
01.schema -> priority 1
02.schema -> priority 0

A mapping of variable app.v in 00.schema will this overwrite a mapping to variable app.v in 01.schema since the priority of the first mapping would be 2 which is greater 1, then the priority of mapping of the 01.schema.

Even if 02.schema would have a translation for app.v this would not take affect since the priority of this translation would be 0, while the mapping form 00.schema wins with a priority of 2. While the other way around a translation to app.v from 00.schema would overwrite both, mappings to app.v and translations to app.v from 01.schema or 02.schema

joedevivo commented 10 years ago

Check out #73

Licenser commented 10 years ago

Looked at #73, I was thinking about this approach but it comes with one problem, it looses order when it comes to translations and mappings. The only way to work around that w/o keeping priorities around would be not splitting mappings and translations but that looked even messier then keeping the priority flag.

To illustrate the issue look at the test/order_test in the PR.

The result form this PR:

[{app,[{setting,[{a,"a0"},{b,"b0"},{t2,"c0"},{c,"t0.c"},{t1,"t0.1"}]}]}].

and from #73

[{app,[{setting,[{a,"a0"},{b,"b0"},{t2,"t1.2"},{c,"t0.c"},{t1,"t1.1"}]}]}].
joedevivo commented 10 years ago

I only see the schema files for the order_test. I can't find the actual test.

Licenser commented 10 years ago

And you are totally right, that was pretty lousy of me, added proper tests for the cases, with spec files and explanations in them.

Licenser commented 10 years ago

Wanted to annoy you a bit since the overwriting of translations to mappings is a actual issue I'm running into. I'm good living of my form but it would be nicer to be in sync with the original ;). That said I'm not at all focused on this implementation but it'd be nice to have the functionality in one way or another. #73 sadly did not solve the issue entirely.