Sha256: a39ca82f175d7f00c3a2434a6107fb3dca81799ce5620695ccc3e2f0cb0775d4

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require 'yaml'

module TableSaw
  class Manifest
    class Table
      attr_reader :variables, :config

      def initialize(variables, config)
        @variables = variables
        @config = config
      end

      def table
        config['table']
      end

      alias name table

      def query
        return unless partial?

        format(config['query'], variables.transform_keys(&:to_sym))
      end

      def partial?
        config.key?('query')
      end
    end

    def self.instance
      raise ArgumentError, 'Could not find manifest file' unless File.exist?(TableSaw.configuration.manifest)

      new(YAML.safe_load(File.read(TableSaw.configuration.manifest)))
    end

    attr_reader :config

    def initialize(config)
      @config = config
    end

    def variables
      config.fetch('variables', {})
    end

    def tables
      @tables ||= config['tables'].map { |entry| Table.new(variables, entry) }.each_with_object({}) do |t, memo|
        memo[t.name] = t
      end
    end

    # rubocop:disable Naming/PredicateName
    def has_many_mapping
      @has_many_mapping ||= config.fetch('has_many', {})
    end
    # rubocop:enable Naming/PredicateName
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
table_saw-1.0.1 lib/table_saw/manifest.rb
table_saw-1.0.0 lib/table_saw/manifest.rb