lib/traitorous/converter/model.rb in traitorous-0.1.0 vs lib/traitorous/converter/model.rb in traitorous-0.2.0
- old
+ new
@@ -1,16 +1,39 @@
module Traitorous
module Converter
+ # The Model converter is used a a simple way to instantiate an object from
+ # the model_class using the imported opts, and which will call .export on
+ # the data.
+ #
+ # This converter can be used when you have a set of opts that you can pass
+ # to a classes .new command in order to instantiate an object.
class Model
+ # @param model_klass [Class,#new] class to instantiate when importing
def initialize(model_klass)
@model_klass = model_klass
end
- def do_import(opts)
- @model_klass.new(opts)
- end
+
+ # do_export is called in order to take an existing piece of data and
+ # prepare it to be written to a simpler data structure.
+ #
+ # The model converter exports the data by calling .export on it
+ #
+ # @params data [Object] the data object passed in to be exported
+ # @return [Object] result of data.export
def do_export(data)
data.export
end
+ # do_import is called in order to take some opts and to turn them into
+ # instantiated objects, arrays, or other types of transformation
+ #
+ # The model converter imports the opts by instantiating a model_class
+ # object with it.
+ #
+ # @params opts [Object] the options to be exported
+ # @return [Object] result of model_klass.new(opts)
+ def do_import(opts)
+ @model_klass.new(opts)
+ end
end
end
end