Class: Bidu::House::ErrorReport

Inherits:
Object
  • Object
show all
Includes:
JsonParser
Defined in:
lib/bidu/house/error_report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ErrorReport

Returns a new instance of ErrorReport.



12
13
14
15
16
17
18
19
# File 'lib/bidu/house/error_report.rb', line 12

def initialize(options)
  @json = {
    external_key: :id,
    threshold: 0.02,
    period: 1.day,
    scope: :with_error
  }.merge(options)
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json.



6
7
8
# File 'lib/bidu/house/error_report.rb', line 6

def json
  @json
end

Instance Method Details

#as_jsonObject



37
38
39
40
41
42
# File 'lib/bidu/house/error_report.rb', line 37

def as_json
  {
    ids: scoped.pluck(external_key),
    percentage: percentage
  }
end

#error?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/bidu/house/error_report.rb', line 33

def error?
  percentage > threshold
end

#percentageObject



25
26
27
# File 'lib/bidu/house/error_report.rb', line 25

def percentage
  @percentage ||= last_entires.percentage(scope)
end

#scopedObject



29
30
31
# File 'lib/bidu/house/error_report.rb', line 29

def scoped
  @scoped ||= last_entires.public_send(scope)
end

#statusObject



21
22
23
# File 'lib/bidu/house/error_report.rb', line 21

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