Class: MiniEtl::Generator

Inherits:
Object
  • Object
show all
Includes:
Status
Defined in:
lib/mini_etl/generator.rb

Overview

Generate record information from a source

Constant Summary collapse

VALID_STATES =
{
  initialized: 0,
  bootstrapped: 1,
  transformed: 2,
  failed: 3
}.freeze

Constants included from Status

Status::DEFAULT_STATES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Status

included

Constructor Details

#initializeGenerator

TODO: This needs to know the type of the receiver



20
21
22
23
24
# File 'lib/mini_etl/generator.rb', line 20

def initialize
  @lazy = false
  @payload = []
  initialized!
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



15
16
17
# File 'lib/mini_etl/generator.rb', line 15

def data
  @data
end

#lazyObject

Returns the value of attribute lazy.



15
16
17
# File 'lib/mini_etl/generator.rb', line 15

def lazy
  @lazy
end

#payloadObject (readonly)

Returns the value of attribute payload.



17
18
19
# File 'lib/mini_etl/generator.rb', line 17

def payload
  @payload
end

#type=(value) ⇒ Object (writeonly)

Sets the attribute type

Parameters:

  • value

    the value to set the attribute type to.



16
17
18
# File 'lib/mini_etl/generator.rb', line 16

def type=(value)
  @type = value
end

Instance Method Details

#bootstrap(type, data) ⇒ Object

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
# File 'lib/mini_etl/generator.rb', line 26

def bootstrap(type, data)
  raise ArgumentError if type.nil? || data.nil?

  @type = type
  @data = data
  bootstrapped!
end

#transformObject



34
35
36
37
38
39
40
# File 'lib/mini_etl/generator.rb', line 34

def transform
  failed! && return unless bootstrapped?

  strategy = MiniEtl::Strategy.for(@type)
  @payload = strategy.generate(@data)
  transformed!
end