bidu-house 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1bce0f17bbdd46d4d769e1b3a6d086abad2ba9b4
4
- data.tar.gz: ab14a3c78154d146481f730c198face541890f24
3
+ metadata.gz: a8ee8b5568f69553340146072bce28f3887689fc
4
+ data.tar.gz: 2260ec4004e11743cb309b17abcb39128f0df8bc
5
5
  SHA512:
6
- metadata.gz: 173182741ddeb9f5ec7bcf41beb5e084777d8039cd6d13e3dee181c9b6bddab21ebe052248199c8bd8450ea79ce12523a00439140629a35337c374ca6ac7698b
7
- data.tar.gz: 5d83943edac6382f139c0f7d61b35c32b1566cd355f28ccf5816c326f093a431b515d7edee0a81ab8fa0d4863f32d05fd96351ca62ac3801d6c0f1a5c129648d
6
+ metadata.gz: df4558e098446b0d289a6e243894f2e77c0912d996e16a4bdf6bb7bb9d4966dc74f7628c1ebbe7cc1812cdf302d4aee2996cc280d2b193942d3c89bffdc293e8
7
+ data.tar.gz: 640c40f723e5ec0568de883080043bebf05c3d5cca4828f2ae3ffcc9d81afd2d53af96bd1432b3bbfaddf51f7dfce19cef27c7b2420efd68ab3635501c28658c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bidu-house (1.1.0)
4
+ bidu-house (1.2.0)
5
5
  activesupport
6
6
  bidu-active_ext
7
7
  concern_builder
data/README.md CHANGED
@@ -2,6 +2,7 @@ Bidu House
2
2
  ==========
3
3
 
4
4
  [![Code Climate](https://codeclimate.com/github/Bidu/house/badges/gpa.svg)](https://codeclimate.com/github/Bidu/house)
5
+ [![Test Coverage](https://codeclimate.com/github/Bidu/house/badges/coverage.svg)](https://codeclimate.com/github/Bidu/house/coverage)
5
6
 
6
7
  This gem tries to make server monitoring easier and more reliable by adding an easly configurable
7
8
  report and making it avaliable in a controller
@@ -23,7 +24,7 @@ with error and render the report
23
24
  include Bidu::House
24
25
 
25
26
  status_report :failures, clazz: Document
26
- status_report :'failures.schedules', clazz: Schedules, on: :schedules
27
+ status_report :failures, clazz: Schedules, on: :schedules
27
28
  status_report :delays, clazz: Schedules, scope: :late, on: :schedules
28
29
  status_report :'documents.count', clazz: Document, scope: :active, type: House::Range, minimum: 100
29
30
  status_report :'documents.errors', clazz: Document, scope: :'active.with_error', type: :range, maximum: 1000
data/circle.yml ADDED
@@ -0,0 +1,3 @@
1
+ test:
2
+ pre:
3
+ - bundle install
@@ -0,0 +1,28 @@
1
+ module Bidu
2
+ module House
3
+ class Report::ActiveRecord < Report
4
+ json_parse :period, type: :period
5
+ json_parse :clazz, :base_scope, case: :snake
6
+
7
+ private
8
+
9
+ def fetch_scoped(base, scope)
10
+ if (scope.is_a?(Symbol))
11
+ scope.to_s.split('.').inject(base) do |entries, method|
12
+ entries.public_send(method)
13
+ end
14
+ else
15
+ base.where(scope)
16
+ end
17
+ end
18
+
19
+ def last_entries
20
+ @last_entries ||= base.where('updated_at >= ?', period.seconds.ago)
21
+ end
22
+
23
+ def base
24
+ fetch_scoped(clazz, base_scope)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,7 +1,7 @@
1
1
  module Bidu
2
2
  module House
3
3
  class Report
4
- class Error < Report
4
+ class Error < Report::ActiveRecord
5
5
  ALLOWED_PARAMETERS=[:period, :threshold]
6
6
  DEFAULT_OPTION = {
7
7
  external_key: :id,
@@ -0,0 +1,29 @@
1
+ class Bidu::House::Report::Multiple < Bidu::House::Report
2
+ def as_json
3
+ {
4
+ status: status
5
+ }.merge(sub_reports_hash)
6
+ end
7
+
8
+ def error?
9
+ sub_reports.any?(&:error?)
10
+ end
11
+
12
+ private
13
+
14
+ def sub_reports_hash
15
+ sub_reports.map(&:as_json).as_hash(reports_ids.map(&:to_s))
16
+ end
17
+
18
+ def sub_reports
19
+ @sub_reports ||= reports_ids.map do |id|
20
+ build_sub_report(id)
21
+ end
22
+ end
23
+
24
+ def build_sub_report(id)
25
+ sub_report_class.new(json.merge(key => id))
26
+ end
27
+ end
28
+
29
+
@@ -1,7 +1,7 @@
1
1
  module Bidu
2
2
  module House
3
3
  class Report
4
- class Range < Report
4
+ class Range < Report::ActiveRecord
5
5
  ALLOWED_PARAMETERS=[:period, :maximum, :minimum]
6
6
  DEFAULT_OPTION = {
7
7
  period: 1.day,
@@ -2,6 +2,7 @@ module Bidu
2
2
  module House
3
3
  class Report
4
4
  include JsonParser
5
+ require 'bidu/house/report/active_record'
5
6
  require 'bidu/house/report/error'
6
7
  require 'bidu/house/report/range'
7
8
  ALLOWED_PARAMETERS = []
@@ -9,10 +10,9 @@ module Bidu
9
10
 
10
11
  attr_reader :json
11
12
 
12
- json_parse :period, type: :period
13
- json_parse :clazz, :base_scope, :id, case: :snake
13
+ json_parse :id, case: :snake
14
14
 
15
- def initialize(options)
15
+ def initialize(options = {})
16
16
  @json = DEFAULT_OPTION.merge(options)
17
17
  end
18
18
 
@@ -27,26 +27,6 @@ module Bidu
27
27
  def as_json
28
28
  { status: status }
29
29
  end
30
-
31
- private
32
-
33
- def fetch_scoped(base, scope)
34
- if (scope.is_a?(Symbol))
35
- scope.to_s.split('.').inject(base) do |entries, method|
36
- entries.public_send(method)
37
- end
38
- else
39
- base.where(scope)
40
- end
41
- end
42
-
43
- def last_entries
44
- @last_entries ||= base.where('updated_at >= ?', period.seconds.ago)
45
- end
46
-
47
- def base
48
- fetch_scoped(clazz, base_scope)
49
- end
50
30
  end
51
31
  end
52
32
  end
@@ -1,5 +1,5 @@
1
1
  module Bidu
2
2
  module House
3
- VERSION = '1.1.0'
3
+ VERSION = '1.2.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bidu-house
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bidu Dev's Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-25 00:00:00.000000000 Z
11
+ date: 2016-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -192,13 +192,16 @@ files:
192
192
  - LICENSE
193
193
  - README.md
194
194
  - Rakefile
195
+ - circle.yml
195
196
  - house.gemspec
196
197
  - lib/bidu.rb
197
198
  - lib/bidu/house.rb
198
199
  - lib/bidu/house/class_methods.rb
199
200
  - lib/bidu/house/concern.rb
200
201
  - lib/bidu/house/report.rb
202
+ - lib/bidu/house/report/active_record.rb
201
203
  - lib/bidu/house/report/error.rb
204
+ - lib/bidu/house/report/multiple.rb
202
205
  - lib/bidu/house/report/range.rb
203
206
  - lib/bidu/house/report_builder.rb
204
207
  - lib/bidu/house/report_config.rb