Closed maddievision closed 8 years ago
I'm wondering if we should rename TranslatorBase
to Translator
, and come up with another name for the Translator
. Same with ReaderBase
and Reader
The Polo::Reader
class as it is might be completely unnecessary.
wow.. this is looking cool, @djbouche. I like where this is headed.
I'll look into it in depth tomorrow to try and give you some accurate feedback.
Hey, @djbouche. I just thought of something that could simplify things a lot.
What if insted of using a Reader
and Importer
we just modified Polo.explore
to take in an extra Translator
object as an argument?
We could do something like this:
def self.explore(base_class, id, dependencies={}, translator=Translator.new)
traveler = Traveler.collect(base_class, id, dependencies)
translator.run(traveler.selects)
end
This might reduce the number of changes we need to make to the core library and allow for a lot of flexibility. i.e. you can pass in whatever custom translator you want (as long as it complies to the Polo::Translator
protocol).
This adds the idea of having a configurable Translator (transforms AR instances into a serial form) and configurable Reader (transforms serial form back into AR instances).
SqlTranslator
now inherits from aTranslatorBase
base class.A
JsonTranslator
has been also added, which outputs the AR instances into a JSON string with an array of objects of the following structure:A
JsonReader
(which inherits fromReaderBase
) has been added which takes the above format and transforms it into AR instances. It is dependent on the model classes being loaded as it will iterate throughActiveRecord::Base
descendants to create a mapping of table name to model classes. Since there is no straightforward way of implicitly preload the models (and that behavior may be unideal for certain projects) so I don't believe we should be doing that.The configuration now accepts the options
:use_reader
and:use_translator
(they have defaults toJsonReader
andSqlTranslator
, respectively).A new convenience method
Polo#read
has added to read and translate a serialized form of instances.Example
will produce
(whitespace added for legibility)
will then produce:
TODO
JsonTranslator
to validate the format of the serialized input (perhaps through something like JSON Schema)