Sha256: 72fe6af41e3f2589bdf99e6f0d91e18fb1a2fe9acc948eb26fba9fa77e217dab

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

module Mongoid
  module Report

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

      def initialize(context, collection, options)
        # Lets remove as option because of passing to the next blocks options
        @attach_name = options.delete(:as) || collection
        options = options.merge(attach_name: attach_name, for: collection)
        super(context, collection, options)
      end

      def aggregation_field(*fields)
        proxy_options = fields.extract_options!
        proxy_options.merge!(options)
        context.aggregation_field(*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 filter(*fields)
        proxy_options = fields.extract_options!
        proxy_options.merge!(options)
        context.filter(*fields, proxy_options)
      end

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

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mongoid-report-0.1.6 lib/mongoid/report/attach_proxy.rb
mongoid-report-0.1.5 lib/mongoid/report/attach_proxy.rb
mongoid-report-0.1.3 lib/mongoid/report/attach_proxy.rb
mongoid-report-0.1.2 lib/mongoid/report/attach_proxy.rb