Sha256: 20d7cf990511fd4b2b19973a5f2321b78c8a2d6beefde051dd8bab012ab46441

Contents?: true

Size: 811 Bytes

Versions: 15

Compression:

Stored size: 811 Bytes

Contents

module Adhoq
  module Reporter
    class UnsupportedFormat < Adhoq::Error; end

    autoload 'Csv',  'adhoq/reporter/csv'
    autoload 'Json', 'adhoq/reporter/json'
    autoload 'Xlsx', 'adhoq/reporter/xlsx'

    class << self
      def generate(execution)
        executor = Executor.new(execution.raw_sql)
        reporter = lookup(execution.report_format).new(executor.execute)

        reporter.build_report
      end

      def lookup(format)
        reporters[format.to_s] || raise(UnsupportedFormat)
      end

      def supported_formats
        reporters.keys.sort
      end

      private

      def reporters
        @reporters ||= {
          'csv'  => Adhoq::Reporter::Csv,
          'json' => Adhoq::Reporter::Json,
          'xlsx' => Adhoq::Reporter::Xlsx,
        }
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
adhoq-1.0.2 lib/adhoq/reporter.rb
adhoq-1.0.1 lib/adhoq/reporter.rb
adhoq-1.0.0 lib/adhoq/reporter.rb
adhoq-0.5.0 lib/adhoq/reporter.rb
adhoq-0.5.0.beta1 lib/adhoq/reporter.rb
adhoq-0.4.0 lib/adhoq/reporter.rb
adhoq-0.3.0 lib/adhoq/reporter.rb
adhoq-0.2.0 lib/adhoq/reporter.rb
adhoq-0.1.2 lib/adhoq/reporter.rb
adhoq-0.1.1 lib/adhoq/reporter.rb
adhoq-0.1.0 lib/adhoq/reporter.rb
adhoq-0.0.7 lib/adhoq/reporter.rb
adhoq-0.0.6 lib/adhoq/reporter.rb
adhoq-0.0.5 lib/adhoq/reporter.rb
adhoq-0.0.4 lib/adhoq/reporter.rb