Sha256: 5258364a8f62c42fcebc1b77388c4591311b26cf65df9e16cb2d4b89963f51b9

Contents?: true

Size: 814 Bytes

Versions: 3

Compression:

Stored size: 814 Bytes

Contents

module Groupdate
  class Series
    attr_accessor :magic, :relation

    def initialize(magic, relation)
      @magic = magic
      @relation = relation
    end

    # clone to prevent modifying original variables
    def method_missing(method, *args, &block)
      # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation/calculations.rb
      if ActiveRecord::Calculations.method_defined?(method)
        magic.perform(relation, method, *args, &block)
      elsif @relation.respond_to?(method, true)
        Groupdate::Series.new(magic, relation.send(method, *args, &block))
      else
        super
      end
    end

    def respond_to?(method, include_all = false)
      ActiveRecord::Calculations.method_defined?(method) || relation.respond_to?(method) || super
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
groupdate-2.5.2 lib/groupdate/series.rb
groupdate-2.5.1 lib/groupdate/series.rb
groupdate-2.5.0 lib/groupdate/series.rb