Sha256: 23dac692098b222ef4def484f0b5f89917f9509fae511052500c17f228e1ed4f

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

module Remi
  # A loader is an object meant to load data into a some external system.
  # This is a parent class meant to be inherited by child classes that
  # define specific ways to load data.
  class Loader

    def initialize(*args, context: nil, logger: Remi::Settings.logger, **kargs, &block)
      @context = context
      @logger = logger
    end

    attr_accessor :logger, :context

    # Any child classes need to define a load method that loads data from
    # the given dataframe into the target system.
    # @param data [Remi::DataFrame] Data that has been encoded appropriately to be loaded into the target
    # @return [true] On success
    def load(data)
      raise NoMethodError, "#{__method__} not defined for #{self.class.name}"
    end

    # If autoload is set to true, then any loaders are called at the moment
    # a dataframe is assigned to a target (e.g., `my_target.df = some_df` will
    # call `#load` on any loaders associated with `my_target`).
    def autoload
      false
    end

    # @return [Remi::Fields] The fields defined in the context
    def fields
      context && context.respond_to?(:fields) ? context.fields : Remi::Fields.new({})
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
remi-0.3.3 lib/remi/loader.rb
remi-0.3.2 lib/remi/loader.rb
remi-0.3.1 lib/remi/loader.rb