Class: Traitorous::Converter::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/traitorous/converter/model.rb

Overview

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.

Instance Method Summary collapse

Constructor Details

#initialize(model_klass) ⇒ Model

Returns a new instance of Model.

Parameters:

  • model_klass (Class, #new)

    class to instantiate when importing



11
12
13
# File 'lib/traitorous/converter/model.rb', line 11

def initialize(model_klass)
  @model_klass = model_klass
end

Instance Method Details

#do_export(data) ⇒ Object

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

Returns:

  • (Object)

    result of data.export



22
23
24
# File 'lib/traitorous/converter/model.rb', line 22

def do_export(data)
  data.export
end

#do_import(opts) ⇒ Object

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.

Returns:

  • (Object)

    result of model_klass.new(opts)



34
35
36
# File 'lib/traitorous/converter/model.rb', line 34

def do_import(opts)
  @model_klass.new(opts)
end