class ExportToGcloud::Exporter::Definition

Public Class Methods

load_definition(name, finder) click to toggle source
# File lib/export_to_gcloud/exporter/definition.rb, line 30
def self.load_definition name, finder
  file_path = finder.call name
  load file_path
  definition = @last_definition
  @last_definition = nil

  unless definition
    raise("File #{file_path.to_s} must define exporter for '#{name}'!")
  end

  unless definition.name == name
    raise "File #{file_path.to_s} defines '#{definition.name}' instead of '#{name}'"
  end

  definition
end
new(exporter_type, attrs) click to toggle source
Calls superclass method
# File lib/export_to_gcloud/exporter/definition.rb, line 3
def initialize exporter_type, attrs
  super attrs.merge!(type: exporter_type)
end
set_last_definition(klass, attrs={}) click to toggle source
# File lib/export_to_gcloud/exporter/definition.rb, line 22
def self.set_last_definition klass, attrs={}, &block
  last_definition = new klass, attrs
  block.call last_definition if block

  last_definition.validate!
  @last_definition = last_definition
end

Public Instance Methods

get_bq_table_name() click to toggle source
# File lib/export_to_gcloud/exporter/definition.rb, line 18
def get_bq_table_name
  bq_table_name || name
end
get_data(*args) click to toggle source
# File lib/export_to_gcloud/exporter/definition.rb, line 14
def get_data *args
  Proc === data ? data.call(*args) : data
end
validate!() click to toggle source
# File lib/export_to_gcloud/exporter/definition.rb, line 7
def validate!
  (String === name && !name.empty?)   || raise('`name` must be defined!')
  Proc === bq_schema                  || raise('`bq_schema` must be defined as a Proc!')
  data                                || raise('`data` must be defined!')
  type.validate_definition! self if type.respond_to? 'validate_definition!'
end