Sha256: e61c93183bd805ef105ca73ff4243b07ad24cf2bb30c4fe5b248802b4a71bf51

Contents?: true

Size: 1.17 KB

Versions: 13

Compression:

Stored size: 1.17 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

      def has_many
        config.fetch('has_many', [])
      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

    def has_many
      @has_many ||= config.fetch('has_many', {})
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
table_saw-2.6.0 lib/table_saw/manifest.rb
table_saw-2.5.0 lib/table_saw/manifest.rb
table_saw-2.4.3 lib/table_saw/manifest.rb
table_saw-2.4.2 lib/table_saw/manifest.rb
table_saw-2.4.1 lib/table_saw/manifest.rb
table_saw-2.4.0 lib/table_saw/manifest.rb
table_saw-2.3.0 lib/table_saw/manifest.rb
table_saw-2.2.0 lib/table_saw/manifest.rb
table_saw-2.1.0 lib/table_saw/manifest.rb
table_saw-2.0.0 lib/table_saw/manifest.rb
table_saw-1.3.0 lib/table_saw/manifest.rb
table_saw-1.2.0 lib/table_saw/manifest.rb
table_saw-1.1.0 lib/table_saw/manifest.rb