Sha256: 263fe999c81ef71efeb9e1a578b23da118c4361f32a61ea43157cc61159bc94c

Contents?: true

Size: 620 Bytes

Versions: 2

Compression:

Stored size: 620 Bytes

Contents

module Bidu
  module House
    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 & 1 rubygems

Version Path
bidu-house-1.3.0 lib/bidu/house/report/active_record.rb
bidu-house-1.2.0 lib/bidu/house/report/active_record.rb