mongoid-colors 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mongoid-colors/colorizer.rb +33 -28
- data/lib/mongoid-colors/version.rb +1 -1
- metadata +20 -4
@@ -2,42 +2,46 @@
|
|
2
2
|
|
3
3
|
require 'mongoid'
|
4
4
|
require 'coderay'
|
5
|
+
require 'colorize'
|
5
6
|
|
6
7
|
module MongoidColors::Colorizer
|
7
8
|
def self.setup
|
8
9
|
return unless Mongoid.logger
|
9
10
|
|
10
11
|
old_formatter = Mongoid.logger.formatter
|
11
|
-
Mongoid.logger.formatter =
|
12
|
+
Mongoid.logger.formatter = lambda do |severity, datetime, progname, msg|
|
12
13
|
m = parse(msg)
|
14
|
+
return if m == :ignore
|
15
|
+
|
13
16
|
if m.nil?
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
17
|
+
old_formatter.call(severity, datetime, progname, msg)
|
18
|
+
return
|
19
|
+
end
|
20
|
+
|
21
|
+
m[:query].gsub!(/BSON::ObjectId\('([^']+)'\)/, '0x\1')
|
22
|
+
m[:duration] = m[:duration].split('.')[0] if m[:duration]
|
23
|
+
|
24
|
+
line = "☘ ".green + "MongoDB ".white
|
25
|
+
line << "(#{m[:duration]}ms) " if m[:duration]
|
26
|
+
|
27
|
+
if m[:database]
|
28
|
+
if m[:collection]
|
29
|
+
line << "[#{m[:database]}::#{m[:collection]}] "
|
30
|
+
else
|
31
|
+
line << "[#{m[:database]}] "
|
30
32
|
end
|
33
|
+
end
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
+
line << case m[:operation]
|
36
|
+
when 'QUERY' then 'QUERY '.colorize(:green)
|
37
|
+
when 'INSERT' then 'INSERT '.red
|
38
|
+
when 'UPDATE' then 'UPDATE '.red
|
39
|
+
else m[:operation].to_s
|
35
40
|
end
|
36
|
-
end
|
37
|
-
end
|
38
41
|
|
39
|
-
|
40
|
-
|
42
|
+
line << CodeRay.scan(m[:query], :ruby).term
|
43
|
+
line << "\n"
|
44
|
+
end
|
41
45
|
end
|
42
46
|
|
43
47
|
def self.parse(msg)
|
@@ -46,10 +50,11 @@ module MongoidColors::Colorizer
|
|
46
50
|
{:duration => $1, :database => $2, :collection => $3, :query => $4}
|
47
51
|
when /^MONGODB (.*)\['(.*)'\]\.(.*)$/
|
48
52
|
{:database => $1, :collection => $2, :query => $3}
|
49
|
-
when /^ *MOPED: (\S+:\S+) (\S+) +database=(\S+) collection=(\S+) (.*) \((.*)ms\)
|
50
|
-
{:host => $1, :operation => $2, :database => $3, :collection => $
|
51
|
-
when
|
52
|
-
|
53
|
+
when /^ *MOPED: (\S+:\S+) (\S+) +database=(\S+)( collection=(\S+))? (.*[^)])( \((.*)ms\))?$/
|
54
|
+
{:host => $1, :operation => $2, :database => $3, :collection => $5, :query => $6, :duration => $8}
|
55
|
+
when /which could negatively impact client-side performance/
|
56
|
+
when /COMMAND.*getlasterror/
|
57
|
+
:ignore
|
53
58
|
end
|
54
59
|
end
|
55
60
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-colors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: colorize
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
46
62
|
description: Colorize your Mongoid debug statments
|
47
63
|
email:
|
48
64
|
- nicolas@viennot.biz
|
@@ -50,9 +66,9 @@ executables: []
|
|
50
66
|
extensions: []
|
51
67
|
extra_rdoc_files: []
|
52
68
|
files:
|
53
|
-
- lib/mongoid-colors/version.rb
|
54
|
-
- lib/mongoid-colors/colorizer.rb
|
55
69
|
- lib/mongoid-colors.rb
|
70
|
+
- lib/mongoid-colors/colorizer.rb
|
71
|
+
- lib/mongoid-colors/version.rb
|
56
72
|
- README.md
|
57
73
|
homepage: http://github.com/nviennot/rspec-console
|
58
74
|
licenses: []
|