Sha256: 7eb38b3a89090e0696f79f34055c3700e463975a026a151518342ab38d9e50d3

Contents?: true

Size: 579 Bytes

Versions: 1

Compression:

Stored size: 579 Bytes

Contents

require_relative "../columns"
require_relative "paths"

module Arable::Columns::FromStructure
  module_function

  def call(table_name)
    return if structure.blank?

    table_definition_match = structure.match(/CREATE TABLE\s\w+\.#{table_name}.*?\n(.*?)\n *\);/m)

    table_definition_match[1]
      .lines
      .map(&:strip)
      .map { |line| line.match(/(\w*)\s/)[1] }
  end

  private

  def self.structure
    @structure ||= begin
      return unless File.exist?(Arable::Columns::Paths::STRUCTURE)

      File.read(Arable::Columns::Paths::STRUCTURE)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
arable-0.2.0 lib/arable/columns/from_structure.rb