Sha256: 1539706e373b70b1a9ded14895c9b052f593dc7fe9b19ee6357132314af9d512

Contents?: true

Size: 1005 Bytes

Versions: 2

Compression:

Stored size: 1005 Bytes

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)
        field_options = fields.extract_options!
        field_options.merge!(options)

        context.aggregation_field(*fields, field_options)
      end

      def group_by(*fields)
        group_options = fields.extract_options!
        group_options.merge!(options)

        context.group_by(*fields, group_options)
      end

      def filter(*fields)
        filter_options = fields.extract_options!
        filter_options.merge!(options)

        context.filter(*fields, filter_options)
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mongoid-report-0.1.1 lib/mongoid/report/attach_proxy.rb
mongoid-report-0.1.0 lib/mongoid/report/attach_proxy.rb