Sha256: 65d50452bcc6ad6d3c43a12f61e291d4d52b73ad65b3ca1dc1932423cfd2103f

Contents?: true

Size: 620 Bytes

Versions: 2

Compression:

Stored size: 620 Bytes

Contents

module Bidu
  module Mercy
    class Report::ActiveRecord < Report
      json_parse :period, type: :period
      json_parse :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
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
mercy-1.3.0 lib/bidu/mercy/report/active_record.rb
bidu-mercy-1.3.0 lib/bidu/mercy/report/active_record.rb