mongoid-colors 0.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.
- data/README.md +37 -0
- data/lib/mongoid-colors/colorizer.rb +57 -0
- data/lib/mongoid-colors/version.rb +3 -0
- data/lib/mongoid-colors.rb +3 -0
- metadata +82 -0
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
Mongoid Colors
|
2
|
+
===============
|
3
|
+
|
4
|
+
Mongoid Colors colorizes the mongoid query debug traces.
|
5
|
+
It uses [Coderay](https://github.com/rubychan/coderay) to do so.
|
6
|
+
|
7
|
+
Best served chilled with [irb-config](https://github.com/nviennot/irb-config).
|
8
|
+
|
9
|
+
What does it look like?
|
10
|
+
------------------------
|
11
|
+
|
12
|
+
### Watch the screencast of irb config
|
13
|
+
|
14
|
+
[](http://velvetpulse.com/2012/11/19/improve-your-ruby-workflow-by-integrating-vim-tmux-pry/)
|
15
|
+
|
16
|
+
Usage
|
17
|
+
------
|
18
|
+
|
19
|
+
If you don't use irb-config, you can use it as follow:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'mongoid-colors'
|
23
|
+
```
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
MongoidColors::Colorizer.setup # hijack Mongoid.logger.formatter
|
27
|
+
```
|
28
|
+
|
29
|
+
TODO
|
30
|
+
----
|
31
|
+
|
32
|
+
* Testing
|
33
|
+
|
34
|
+
License
|
35
|
+
-------
|
36
|
+
|
37
|
+
MIT License
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'mongoid'
|
4
|
+
require 'coderay'
|
5
|
+
|
6
|
+
module MongoidColors::Colorizer
|
7
|
+
def self.setup
|
8
|
+
return unless Mongoid.logger
|
9
|
+
|
10
|
+
old_formatter = Mongoid.logger.formatter
|
11
|
+
Mongoid.logger.formatter = proc do |severity, datetime, progname, msg|
|
12
|
+
m = parse(msg)
|
13
|
+
if m.nil?
|
14
|
+
unless msg =~ /which could negatively impact client-side performance/
|
15
|
+
old_formatter.call(severity, datetime, progname, msg)
|
16
|
+
end
|
17
|
+
else
|
18
|
+
m[:query].gsub!(/BSON::ObjectId\('([^']+)'\)/, '0x\1')
|
19
|
+
m[:duration] = m[:duration].split('.')[0] if m[:duration]
|
20
|
+
|
21
|
+
line = "\033[1;32m☘ \033[1;37mMongoDB\033[0m "
|
22
|
+
line << "(#{m[:duration]}ms) " if m[:duration]
|
23
|
+
|
24
|
+
if m[:database]
|
25
|
+
if m[:collection]
|
26
|
+
line << colorize("[#{m[:database]}::#{m[:collection]}] ")
|
27
|
+
else
|
28
|
+
line << colorize("[#{m[:database]}] ")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
line << "#{colorize(m[:operation])} " if m[:operation]
|
33
|
+
line << colorize(m[:query])
|
34
|
+
line << "\n"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.colorize(msg)
|
40
|
+
CodeRay.scan(msg, :ruby).term
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.parse(msg)
|
44
|
+
case msg
|
45
|
+
when /^MONGODB \((.*)ms\) (.*)\['(.*)'\]\.(.*)$/
|
46
|
+
{:duration => $1, :database => $2, :collection => $3, :query => $4}
|
47
|
+
when /^MONGODB (.*)\['(.*)'\]\.(.*)$/
|
48
|
+
{: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 => $4, :query => $5, :duration => $6}
|
51
|
+
when /^ *MOPED: (\S+:\S+) (\S+) +database=(\S+) (.*) \((.*)ms\)/
|
52
|
+
{:host => $1, :operation => $2, :database => $3, :query => $4, :duration => $5}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
setup
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongoid-colors
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nicolas Viennot
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mongoid
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: coderay
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Colorize your Mongoid debug statments
|
47
|
+
email:
|
48
|
+
- nicolas@viennot.biz
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- lib/mongoid-colors/version.rb
|
54
|
+
- lib/mongoid-colors/colorizer.rb
|
55
|
+
- lib/mongoid-colors.rb
|
56
|
+
- README.md
|
57
|
+
homepage: http://github.com/nviennot/rspec-console
|
58
|
+
licenses: []
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.8.24
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: Colorize your Mongoid traces
|
81
|
+
test_files: []
|
82
|
+
has_rdoc: false
|