Sha256: 87161eaecc7c8c95bcdea7429c94779f2f1b109e9fe77624e48607c2c80386f4

Contents?: true

Size: 1021 Bytes

Versions: 1

Compression:

Stored size: 1021 Bytes

Contents

module Bidu
  module House
    class Report
      include JsonParser
      require 'bidu/house/report/error'
      ALLOWED_PARAMETERS = []
      DEFAULT_OPTION = {}

      attr_reader :json

      json_parse :period, type: :period
      json_parse :clazz, :base_scope, case: :snake

      def initialize(options)
        @json = DEFAULT_OPTION.merge(options)
      end

      def status
        @status ||= error? ? :error : :ok
      end

      def error?
        raise 'Not implemented yet'
      end

      def as_json
        { status: status }
      end

      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

1 entries across 1 versions & 1 rubygems

Version Path
bidu-house-1.0.0 lib/bidu/house/report.rb