Sha256: dd43e7645a7a0e502abbfd12bc8335c23a039939ac20384ede3e0a59f294037d

Contents?: true

Size: 1.73 KB

Versions: 3

Compression:

Stored size: 1.73 KB

Contents

module Mongoid
  module Report

    AttachProxy = Struct.new(:context, :collection, :options) do
      attr_reader :report_name

      def initialize(context, collection, options)
        # Lets remove as option because of passing to the next blocks options
        report_name = options.delete(:as)

        if collection
          report_name ||= Collections.name(collection)
        end

        options.merge!(
          report_name:  report_name,
          collection:   collection,
        )

        super(context, collection, options)
      end

      def columns(*fields)
        proxy_options = fields.extract_options!
        proxy_options.merge!(options)
        context.columns(*fields, proxy_options)
      end

      def column(*fields)
        proxy_options = fields.extract_options!
        proxy_options.merge!(options)
        context.column(*fields, proxy_options)
      end

      def mapping(*fields)
        proxy_options = fields.extract_options!
        proxy_options.merge!(options)
        context.mapping(*fields, proxy_options)
      end

      def group_by(*fields)
        proxy_options = fields.extract_options!
        proxy_options.merge!(options)
        context.group_by(*fields, proxy_options)
      end

      def match(*fields)
        proxy_options = fields.extract_options!
        proxy_options.merge!(options)
        context.match(*fields, proxy_options)
      end

      def query(*fields)
        proxy_options = fields.extract_options!
        proxy_options.merge!(options)
        context.query(*fields, proxy_options)
      end

      def batches(*fields)
        proxy_options = fields.extract_options!
        proxy_options.merge!(options)
        context.batches(*fields, proxy_options)
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mongoid-report-0.2.2 lib/mongoid/report/attach_proxy.rb
mongoid-report-0.2.1 lib/mongoid/report/attach_proxy.rb
mongoid-report-0.2.0 lib/mongoid/report/attach_proxy.rb