best_boy 2.2.0 → 2.2.1
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 +4 -4
- data/README.md +5 -2
- data/lib/best_boy/engine.rb +1 -0
- data/lib/best_boy/models/active_record/best_boy/day_report.rb +18 -26
- data/lib/best_boy/models/active_record/best_boy/eventable.rb +8 -18
- data/lib/best_boy/models/active_record/best_boy/month_report.rb +19 -26
- data/lib/best_boy/models/active_record/best_boy/reporting.rb +25 -0
- data/lib/best_boy/version.rb +1 -1
- metadata +21 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1ce44945739f534f6c56910503f9f0b408955d0
|
4
|
+
data.tar.gz: 39836bfe40b0ce0e2acf1aa3ae33221763b95ea6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b211c7f6f6b6cb1135415d5a50d3f4f674a7d4f96a7de9087cd994d04610455722eecab5b7a8ee9646959ac5ac7e87828eaff757b673000a0bdf6403985739c8
|
7
|
+
data.tar.gz: 45d8ece941242fdb99260083e9672b3dc45de514c0d7729e91e49124e81037c777d14c29d8a03fa68113400c2dbdd847811c7e5129d562cd8a88570d533dbdf7
|
data/README.md
CHANGED
@@ -3,6 +3,7 @@ best_boy
|
|
3
3
|
[](https://secure.travis-ci.org/Absolventa/best_boy)
|
4
4
|
[](https://gemnasium.com/Absolventa/best_boy)
|
5
5
|
[](https://codeclimate.com/github/Absolventa/best_boy)
|
6
|
+
[](https://www.omniref.com/ruby/gems/best_boy)
|
6
7
|
|
7
8
|
A simple event driven logging for ActiveRecord models.
|
8
9
|
|
@@ -61,12 +62,14 @@ Run the migration
|
|
61
62
|
|
62
63
|
Changelog
|
63
64
|
---------
|
65
|
+
#### 2.2.1
|
66
|
+
* flexibilized report creation method to create reports for a specific date
|
67
|
+
|
64
68
|
#### 2.2.0
|
65
69
|
* Updated dependencies for rspec and kaminari
|
66
70
|
* Make recover_report_history rake task a noop for no previously tracked BestBoyEvents
|
67
|
-
|
68
|
-
#### 2.1.4
|
69
71
|
* Bugfix for report recovery rake task
|
72
|
+
* use appraisal for testing against different gemsets and Ruby versions
|
70
73
|
|
71
74
|
#### 2.1.3
|
72
75
|
* Compatible with Rails 4.1
|
data/lib/best_boy/engine.rb
CHANGED
@@ -17,6 +17,7 @@ module BestBoy
|
|
17
17
|
initializer 'best_boy.model' do |app|
|
18
18
|
if BestBoy.orm == :active_record
|
19
19
|
require "best_boy/models/active_record/best_boy/obeys_test_mode.rb"
|
20
|
+
require "best_boy/models/active_record/best_boy/reporting.rb"
|
20
21
|
require "best_boy/models/active_record/best_boy_event.rb"
|
21
22
|
require "best_boy/models/active_record/best_boy/eventable.rb"
|
22
23
|
require "best_boy/models/active_record/best_boy/day_report.rb"
|
@@ -2,6 +2,7 @@ module BestBoy
|
|
2
2
|
class DayReport < ActiveRecord::Base
|
3
3
|
|
4
4
|
include BestBoy::ObeysTestMode
|
5
|
+
include BestBoy::Reporting
|
5
6
|
|
6
7
|
# db configuration
|
7
8
|
#
|
@@ -33,37 +34,28 @@ module BestBoy
|
|
33
34
|
#
|
34
35
|
#
|
35
36
|
|
36
|
-
|
37
|
-
self.for(owner, type, source).created_on(date)
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.current_or_create_for(owner, type, source = nil)
|
41
|
-
day_report = self.current_for(Time.zone.now, owner, type, source).last
|
42
|
-
day_report.present? ? day_report : self.create_for(owner, type, source)
|
43
|
-
end
|
37
|
+
class << self
|
44
38
|
|
45
|
-
|
46
|
-
|
47
|
-
|
39
|
+
def create_for(owner, type, source = nil, date = Time.zone.now)
|
40
|
+
month_report = BestBoy::MonthReport.current_or_create_for(owner, type, source, date)
|
41
|
+
day_report = BestBoy::DayReport.new
|
48
42
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
43
|
+
day_report.owner_type = owner
|
44
|
+
day_report.event = type
|
45
|
+
day_report.month_report_id = month_report.id
|
46
|
+
day_report.event_source = source
|
47
|
+
day_report.created_at = date
|
53
48
|
|
54
|
-
|
55
|
-
|
49
|
+
day_report.save ? day_report : nil
|
50
|
+
end
|
56
51
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
def self.daily_occurrences_for(owner, type, source = nil, date)
|
62
|
-
self.created_on(date).for(owner, type, source).sum(:occurrences)
|
63
|
-
end
|
52
|
+
def daily_occurrences_for(owner, type, source = nil, date)
|
53
|
+
created_on(date).for(owner, type, source).sum(:occurrences)
|
54
|
+
end
|
64
55
|
|
65
|
-
|
66
|
-
|
56
|
+
def weekly_occurrences_for(owner, type, source = nil)
|
57
|
+
week.for(owner, type, source).sum(:occurrences)
|
58
|
+
end
|
67
59
|
end
|
68
60
|
end
|
69
61
|
end
|
@@ -28,6 +28,11 @@ module BestBoy
|
|
28
28
|
create_best_boy_event_with_type(type, source)
|
29
29
|
end
|
30
30
|
|
31
|
+
def report(klass: self.class.to_s, type: '', source: nil, date: Time.zone.now)
|
32
|
+
BestBoy::MonthReport.current_or_create_for(klass, type, source, date).increment!(:occurrences)
|
33
|
+
BestBoy::DayReport.current_or_create_for(klass, type, source, date).increment!(:occurrences)
|
34
|
+
end
|
35
|
+
|
31
36
|
private
|
32
37
|
|
33
38
|
def trigger_create_event
|
@@ -40,7 +45,7 @@ module BestBoy
|
|
40
45
|
create_best_boy_event_with_type "destroy"
|
41
46
|
end
|
42
47
|
|
43
|
-
def create_best_boy_event_with_type
|
48
|
+
def create_best_boy_event_with_type(type, source = nil)
|
44
49
|
raise "nil event is not allowed" if type.blank?
|
45
50
|
best_boy_event = BestBoyEvent.new do |bbe|
|
46
51
|
bbe.event = type
|
@@ -48,25 +53,10 @@ module BestBoy
|
|
48
53
|
bbe.owner = self
|
49
54
|
end
|
50
55
|
best_boy_event.save
|
51
|
-
report type, source
|
52
|
-
end
|
53
|
-
|
54
|
-
def report type, source = nil
|
55
|
-
month_report = BestBoy::MonthReport.current_or_create_for(self.class.to_s, type)
|
56
|
-
month_report_with_source = BestBoy::MonthReport.current_or_create_for(self.class.to_s, type, source) if source.present?
|
57
56
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
increment_occurrences_in_reports month_report, month_report_with_source, day_report, day_report_with_source
|
57
|
+
report(type: type, source: source) if source.present?
|
58
|
+
report(type: type, source: nil)
|
62
59
|
end
|
63
60
|
|
64
|
-
def increment_occurrences_in_reports(month_report, month_report_with_source, day_report, day_report_with_source)
|
65
|
-
day_report_with_source.increment!(:occurrences) if day_report_with_source.present?
|
66
|
-
month_report_with_source.increment!(:occurrences) if month_report_with_source.present?
|
67
|
-
|
68
|
-
day_report.increment!(:occurrences)
|
69
|
-
month_report.increment!(:occurrences)
|
70
|
-
end
|
71
61
|
end
|
72
62
|
end
|
@@ -2,6 +2,7 @@ module BestBoy
|
|
2
2
|
class MonthReport < ActiveRecord::Base
|
3
3
|
|
4
4
|
include BestBoy::ObeysTestMode
|
5
|
+
include BestBoy::Reporting
|
5
6
|
|
6
7
|
# db configuration
|
7
8
|
#
|
@@ -33,37 +34,29 @@ module BestBoy
|
|
33
34
|
#
|
34
35
|
#
|
35
36
|
|
36
|
-
|
37
|
-
self.for(owner, type, source).between(date.beginning_of_month, date)
|
38
|
-
end
|
37
|
+
class << self
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
def create_for(owner, type, source = nil, date = Time.zone.now)
|
40
|
+
month_report = BestBoy::MonthReport.new
|
41
|
+
month_report.owner_type = owner.to_s
|
42
|
+
month_report.event = type
|
43
|
+
month_report.event_source = source
|
44
|
+
month_report.created_at = date || Time.zone.now
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
month_report.owner_type = owner.to_s
|
48
|
-
month_report.event = type
|
49
|
-
month_report.event_source = source
|
50
|
-
month_report.save ? month_report : nil
|
51
|
-
end
|
46
|
+
month_report.save ? month_report : nil
|
47
|
+
end
|
52
48
|
|
53
|
-
|
54
|
-
|
55
|
-
|
49
|
+
def monthly_occurrences_for(owner, type, source = nil, date)
|
50
|
+
MonthReport.for(owner, type, source).between(date.beginning_of_month, date.end_of_month).sum(:occurrences)
|
51
|
+
end
|
56
52
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
def self.yearly_occurrences_for(owner, type, source = nil, date)
|
62
|
-
self.for(owner, type, source).between(date.beginning_of_year, date).sum(:occurrences)
|
63
|
-
end
|
53
|
+
def yearly_occurrences_for(owner, type, source = nil, date)
|
54
|
+
MonthReport.for(owner, type, source).between(date.beginning_of_year, date).sum(:occurrences)
|
55
|
+
end
|
64
56
|
|
65
|
-
|
66
|
-
|
57
|
+
def overall_occurrences_for(owner, type, source = nil)
|
58
|
+
MonthReport.for(owner, type, source).sum(:occurrences)
|
59
|
+
end
|
67
60
|
end
|
68
61
|
end
|
69
62
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module BestBoy
|
2
|
+
module Reporting
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def current_for(date, owner, type, source = nil)
|
9
|
+
self.for(owner, type, source).created_on(date)
|
10
|
+
end
|
11
|
+
|
12
|
+
def current_or_create_for(owner, type, source = nil, date = Time.zone.now)
|
13
|
+
report = current_for(date, owner, type, source).last
|
14
|
+
report.present? ? report : create_for(owner, type, source, date)
|
15
|
+
end
|
16
|
+
|
17
|
+
def for(owner, type, source = nil)
|
18
|
+
where(owner_type: owner, event: type, event_source: source)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
data/lib/best_boy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: best_boy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Christoph Seydel, Robin Neumann, Daniel Schoppmann
|
7
|
+
- Christoph Seydel, Carsten Zimmermann, Robin Neumann, Daniel Schoppmann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -37,7 +37,7 @@ dependencies:
|
|
37
37
|
- - '>='
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: 0.14.1
|
40
|
-
- -
|
40
|
+
- - ~>
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: 0.16.1
|
43
43
|
type: :runtime
|
@@ -47,7 +47,7 @@ dependencies:
|
|
47
47
|
- - '>='
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: 0.14.1
|
50
|
-
- -
|
50
|
+
- - ~>
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: 0.16.1
|
53
53
|
- !ruby/object:Gem::Dependency
|
@@ -106,6 +106,20 @@ dependencies:
|
|
106
106
|
- - ~>
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '3.5'
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: appraisal
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
109
123
|
- !ruby/object:Gem::Dependency
|
110
124
|
name: haml
|
111
125
|
requirement: !ruby/object:Gem::Requirement
|
@@ -169,6 +183,7 @@ files:
|
|
169
183
|
- lib/best_boy/models/active_record/best_boy/eventable.rb
|
170
184
|
- lib/best_boy/models/active_record/best_boy/month_report.rb
|
171
185
|
- lib/best_boy/models/active_record/best_boy/obeys_test_mode.rb
|
186
|
+
- lib/best_boy/models/active_record/best_boy/reporting.rb
|
172
187
|
- lib/best_boy/models/active_record/best_boy_event.rb
|
173
188
|
- lib/best_boy/version.rb
|
174
189
|
- lib/generators/active_record/best_boy_generator.rb
|
@@ -203,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
218
|
version: '0'
|
204
219
|
requirements: []
|
205
220
|
rubyforge_project:
|
206
|
-
rubygems_version: 2.
|
221
|
+
rubygems_version: 2.4.5
|
207
222
|
signing_key:
|
208
223
|
specification_version: 4
|
209
224
|
summary: a simple event driven logging for models
|