records_count 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/lib/records_count/version.rb +1 -1
- data/lib/records_count.rb +40 -5
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a25450f400477f7089905f9748afea5ac5f220f0
|
4
|
+
data.tar.gz: c825c3868068cfc1818f6abc496f370126697c66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63d79d74ad424424816b07b8926223dbb90fcced56435a5980e924fc9f4cb3e1d7f05a208e80294098bb3788a6dc96b5910f2e2fa7e5300dffb5b16383b5652f
|
7
|
+
data.tar.gz: 3780f35fc5fe47c6f372858483d0f5be0eeee13dc7105b868f0ebaa6d74d4c88f923da457057c2ce1df6e7026e02b5d289d9b9294066c4bf78593e9fb7d7dbc0
|
data/README.md
CHANGED
data/lib/records_count.rb
CHANGED
@@ -1,7 +1,17 @@
|
|
1
|
-
require 'colorize'
|
2
|
-
require 'colorized_string'
|
3
|
-
|
4
1
|
module RecordsCount
|
2
|
+
class Colorizer
|
3
|
+
class << self
|
4
|
+
def red(str); colorize_string(str, "\e[1m\e[31m"); end
|
5
|
+
def green(str); colorize_string(str, "\e[1m\e[32m"); end
|
6
|
+
def dark_green(str); colorize_string(str, "\e[32m"); end
|
7
|
+
def yellow(str); colorize_string(str, "\e[1m\e[33m"); end
|
8
|
+
def blue(str); colorize_string(str, "\e[1m\e[34m"); end
|
9
|
+
def dark_blue(str); colorize_string(str, "\e[34m"); end
|
10
|
+
def pur(str); colorize_string(str, "\e[1m\e[35m"); end
|
11
|
+
def colorize_string(text, color_code); "#{color_code}#{text}\e[0m"; end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
5
15
|
class Message
|
6
16
|
include ActionView::Helpers::TextHelper
|
7
17
|
|
@@ -12,16 +22,41 @@ module RecordsCount
|
|
12
22
|
end
|
13
23
|
|
14
24
|
def message
|
15
|
-
" --> #{pluralize(payload[:record_count], payload[:class_name].underscore.humanize.downcase)}"
|
25
|
+
" --> #{pluralize(payload[:record_count], payload[:class_name].underscore.humanize.downcase)}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def format
|
29
|
+
-> { Colorizer.dark_green(yield) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def print
|
33
|
+
Rails.logger.debug(format { message }.call)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Warning
|
38
|
+
WARNING_TIME = 10 # ms
|
39
|
+
|
40
|
+
attr_reader :duration
|
41
|
+
|
42
|
+
def initialize(start, finish)
|
43
|
+
@duration = (finish - start).round(1)
|
44
|
+
end
|
45
|
+
|
46
|
+
def format
|
47
|
+
-> { Colorizer.yellow(yield) }
|
16
48
|
end
|
17
49
|
|
18
50
|
def print
|
19
|
-
|
51
|
+
if duration > WARNING_TIME
|
52
|
+
Rails.logger.debug format { " Warning instantiation time: #{duration}ms" }.call
|
53
|
+
end
|
20
54
|
end
|
21
55
|
end
|
22
56
|
|
23
57
|
def RecordsCount.do_work!
|
24
58
|
ActiveSupport::Notifications.subscribe('instantiation.active_record') do |name, start, finish, id, payload|
|
59
|
+
RecordsCount::Warning.new(start, finish).print
|
25
60
|
RecordsCount::Message.new(payload).print
|
26
61
|
end
|
27
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: records_count
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Kasyanchuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: colorize
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: sqlite3
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|