Sha256: 36f5772426ab207cf16c2a5dd87ec01b804b976eeed092e5b493f35622efc05e
Contents?: true
Size: 1.37 KB
Versions: 3
Compression:
Stored size: 1.37 KB
Contents
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 # 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
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
traitorous-0.3.0 | lib/traitorous/converter/model.rb |
traitorous-0.2.2 | lib/traitorous/converter/model.rb |
traitorous-0.2.0 | lib/traitorous/converter/model.rb |