Sha256: 2123ddde7acd412dd269dc8a6af85f936a59f11636ade2c2666ad623738eefd2

Contents?: true

Size: 897 Bytes

Versions: 3

Compression:

Stored size: 897 Bytes

Contents

# frozen_string_literal: true

require "erb"
require "socket"
require "yaml"
require "data_taster/flavors"

module DataTaster
  # Ingests the list of data_taster_export_tables.yml files
  # and processes them through an erb template
  # returns a ruby hash of the data
  class Confection
    def assemble
      DataTaster.config.list.each_with_object(default_data) do |path, merged_list|
        merged_list.merge!(load_yml(path.to_s))
      end
    end

    def load_yml(filename)
      return {} unless File.exist?(filename)

      erb = ::ERB.new(File.read(filename))
      erb.filename = filename
      flavored_erb = erb.def_class(DataTaster::Flavors, "render()")
      erb_result = flavored_erb.new.render

      YAML.safe_load(erb_result.gsub(/((.|\n)*---)/, "\n---")) || {}
    end

  private

    def default_data
      {
        "schema_migrations" => "1 = 1",
      }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
data_taster-0.4.0 lib/data_taster/confection.rb
data_taster-0.3.0 lib/data_taster/confection.rb
data_taster-0.2.2 lib/data_taster/confection.rb