module Cranium::DSL

Public Instance Methods

after(&block) click to toggle source
# File lib/cranium/dsl.rb, line 104
def after(&block)
  Cranium.application.register_hook :after, &block
end
archive(*sources) click to toggle source
# File lib/cranium/dsl.rb, line 74
def archive(*sources)
  sources.each do |source_name|
    Cranium::Archiver.archive *Cranium.application.sources[source_name].files
  end
end
database(name, &block) click to toggle source
# File lib/cranium/dsl.rb, line 10
def database(name, &block)
  Cranium::Database.register_database name, &block
end
deduplicate(source, options) click to toggle source
# File lib/cranium/dsl.rb, line 46
def deduplicate(source, options)
  transform source => options[:into] do |record|
    output record if unique_on_fields? *options[:by]
  end
end
extract(name, &block) click to toggle source
# File lib/cranium/dsl.rb, line 22
def extract(name, &block)
  extract_definition = ExtractDefinition.new name
  extract_definition.instance_eval &block
  Cranium::Extract::DataExtractor.new.execute extract_definition
end
import(name, &block) click to toggle source
# File lib/cranium/dsl.rb, line 66
def import(name, &block)
  import_definition = ImportDefinition.new(name)
  import_definition.instance_eval &block
  Cranium::DataImporter.new.import import_definition
end
join(source_name, options) click to toggle source
# File lib/cranium/dsl.rb, line 54
def join(source_name, options)
  Cranium::Transformation::Join.new.tap do |join|
    join.source_left = Cranium.application.sources[source_name]
    join.source_right = Cranium.application.sources[options[:with]]
    join.target = Cranium.application.sources[options[:into]]
    join.match_fields = options[:match_on]
    join.type = options[:type] || :inner
  end.execute
end
move(*sources, to: "") click to toggle source
# File lib/cranium/dsl.rb, line 90
def move(*sources, to: "")
  sources.each do |source_name|
    Cranium::Archiver.move *Cranium.application.sources[source_name].files, target_directory: to
  end
end
read(name, &block) click to toggle source
# File lib/cranium/dsl.rb, line 30
def read(name, &block)
  source = Cranium.application.sources[name]
  Cranium::DataReader.new(source).read(&block)
end
remove(*sources) click to toggle source
# File lib/cranium/dsl.rb, line 82
def remove(*sources)
  sources.each do |source_name|
    Cranium::Archiver.remove *Cranium.application.sources[source_name].files
  end
end
sequence(name) click to toggle source
# File lib/cranium/dsl.rb, line 98
def sequence(name)
  Cranium::Transformation::Sequence.new name
end
source(name, &block) click to toggle source
# File lib/cranium/dsl.rb, line 16
def source(name, &block)
  Cranium.application.register_source name, &block
end
transform(names, &block) click to toggle source
# File lib/cranium/dsl.rb, line 37
def transform(names, &block)
  source = Cranium.application.sources[names.keys.first]
  target = Cranium.application.sources[names.values.first]

  Cranium::DataTransformer.new(source, target).transform(&block)
end