Sha256: 503d1bc09f16770662c6610f3dcd23d1c41b18c208d9ef8dad252c753c52befe

Contents?: true

Size: 552 Bytes

Versions: 2

Compression:

Stored size: 552 Bytes

Contents

module Mercy
  class Report::ActiveRecord < Report
    expose :period, type: :period
    expose :clazz, :base_scope, case: :snake

    private

    def fetch_scoped(base, scope)
      if (scope.is_a?(Symbol))
        scope.to_s.split('.').inject(base) do |entries, method|
          entries.public_send(method)
        end
      else
        base.where(scope)
      end
    end

    def last_entries
      @last_entries ||= base.where('updated_at >= ?', period.seconds.ago)
    end

    def base
      fetch_scoped(clazz, base_scope)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mercy-1.6.0 lib/mercy/report/active_record.rb
mercy-1.5.0 lib/mercy/report/active_record.rb