This repository has been archived by the owner on Jun 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is just a handy builder method that returns a rom relation that is mapped by the mapper using `Mapper#call(relation)` interface. Under the hood the mapper can do *whatever* it's needed to prepare the relation to be used. It can rename the attributes, perform projection etc.
@solnic this looks like a good start to me. i do agree that probably both |
Mapper::Header.build(project_header, map: mapping) | ||
end | ||
|
||
def mapper(mapper = Undefined) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should extract the options stuff from axiom-types. I took what was in virtus originally, rewrote it and mutation covered it, and it should be ready to be gemified. Then we can use it here and in virtus, as well as elsewhere.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This will add support for mapped relations. I'm still unsure where the DSL code should be located - here, in rom-mapper or maybe in rom.
The way I imagine it to work is that after you loaded the schema in the env you can call
Mapping.build(env) {}
to define how relations are mapped, you get a hash of mapped rom relations back. I think it has to support defining those mappings separately in multiple files, kinda like defining DM models in multiple files, because that will be a very common use case.This leads to a missing object because right now
Environment
already has a registry of relations from all repositories, but those are axiom ones, not rom mapped relations. Which makes me think we need a separateRegistry
that will hold rom relations created viaMapping.build
. You could create the registry yourself and pass it to the builder method as many times you want, this way we could have mappings defined in multiple files.Please note that naming is a total WIP as well as implementation. Let me know if you think
Mapping
orRegistry
aren't good names.Currently I made the DSL to look like this:
^ this will build a rom relation and inject a rom mapper configured based on the mapping definition. I will also add a way to just provide your mapper instance or specify which loading strategies you want to use (we have 3 right now).
In general my motivation behind the DSL is to have it as slick as possible. I also want to add convenient methods to
Environment
so that you can define schema+mapping as quickly as possible, otherwise that will be a bit discouraging because in order to load a model from a db you need to 1) configure env 2) set up schema 3) load schema into env 4) define mappings which is obviously a great separation and will be used like that in, for example, rails integration but in simple cases when you just want to get up and running quickly it will be an overkill (for instance think a dead-simple-one-file-sinatra-app).Ugh, that was a bit too long, sorry about that but please let me know your thoughts :)
refs #59