Class: Remi::DataTarget

Inherits:
DataSubject show all
Defined in:
lib/remi/data_subject.rb

Overview

The DataTarget is a DataSubject meant to load data from an associated dataframe into one or more target systems.

Examples:


my_data_target = DataTarget.new do
  encoder some_encoder
  loader some_loader
end

my_data_target.df = some_great_dataframe
my_data_target.load #=> loads data from the dataframe into some target defined by some_loader

Instance Attribute Summary

Attributes inherited from DataSubject

#context, #name

Instance Method Summary collapse

Methods inherited from DataSubject

#df, #df_type, #dsl_eval, #dsl_eval!, #enforce_types, #field_symbolizer, #fields, #fields=

Constructor Details

#initialize(*args, **kargs, &block) ⇒ DataTarget

Returns a new instance of DataTarget.



241
242
243
244
245
# File 'lib/remi/data_subject.rb', line 241

def initialize(*args, **kargs, &block)
  @encoder = Encoder::None.new
  @encoder.context = self
  super
end

Instance Method Details

#df=(new_dataframe) ⇒ Object



290
291
292
293
294
# File 'lib/remi/data_subject.rb', line 290

def df=(new_dataframe)
  super
  loaders.each { |l| l.load encoded_dataframe if l.autoload }
  df
end

#encoder(obj = nil) ⇒ Object

Returns the encoder set for this data source.

Parameters:

  • obj (Object) (defaults to: nil)

    sets the encoder for this data target

Returns:

  • (Object)

    the encoder set for this data source



249
250
251
252
253
254
# File 'lib/remi/data_subject.rb', line 249

def encoder(obj = nil)
  return @encoder unless obj
  obj.context = self

  @encoder = obj
end

#loadtrue

Loads data to all targets. This is automatically called after all transforms have executed, but could also get called manually. The actual load operation is only executed if hasn't already.

Returns:

  • (true)

    if successful



273
274
275
276
277
278
279
# File 'lib/remi/data_subject.rb', line 273

def load
  return nil if @loaded || df.size == 0
  dsl_eval

  load!
  @loaded = true
end

#load!nil

Performs the load operation, regardless of whether it has already executed.

Returns:

  • (nil)

    nothing



285
286
287
288
# File 'lib/remi/data_subject.rb', line 285

def load!
  loaders.each { |l| l.load encoded_dataframe }
  true
end

#loader(obj) ⇒ Array

Returns the full list of loaders.

Parameters:

  • obj (Object)

    adds a loader object to the list of loaders

Returns:

  • (Array)

    the full list of loaders



263
264
265
266
# File 'lib/remi/data_subject.rb', line 263

def loader(obj)
  obj.context = self
  loaders << obj unless loaders.include? obj
end

#loadersArray

Returns the list of loaders associated with the this data target.

Returns:

  • (Array)

    the list of loaders associated with the this data target



257
258
259
# File 'lib/remi/data_subject.rb', line 257

def loaders
  @loaders ||= []
end