console-coloration 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/README.md +36 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/console-coloration.gemspec +33 -0
- data/lib/console-coloration.rb +9 -0
- data/lib/console_coloration/active_record/log_subscriber.rb +84 -0
- data/lib/console_coloration/version.rb +3 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f74c061e51441ee00e52d28a0f1b37e95536486
|
4
|
+
data.tar.gz: 008b33b6517400a51bedfb2de69cb210c4d9d206
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 24f642935d520ed6de8cf137b095afd68821b75b7777d17f0a50e25d9f83377a25418220aedc342cc6ab4755f8475a77981b8d4f51ba89576203f7429255574a
|
7
|
+
data.tar.gz: 62d6d09b131f2731d1bfdb446dac0fd42c09f0a98ceed4db5f2c6aad548aecbbb1fdbe03b4db7f843bcf1e265f0ee146a3e5f440c0badc132592c915df49068e
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# ConsoleColoration
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/console_coloration`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'console_coloration'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install console_coloration
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/console_coloration.
|
36
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "console-coloration"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'console_coloration/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "console-coloration"
|
8
|
+
spec.version = ConsoleColoration::VERSION
|
9
|
+
spec.authors = ["Andrew Ostroumov"]
|
10
|
+
spec.email = ["andrew.ostroumov@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Rails console coloration}
|
13
|
+
spec.description = %q{}
|
14
|
+
spec.homepage = "https://github.com/Ynnni/console-coloration"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_dependency "activesupport", "~> 3.2.22"
|
30
|
+
spec.add_dependency "activerecord", "~> 3.2.22"
|
31
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module ConsoleColoration
|
2
|
+
module ActiveRecord
|
3
|
+
class LogSubscriber < ActiveSupport::LogSubscriber
|
4
|
+
IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN"]
|
5
|
+
|
6
|
+
def self.runtime=(value)
|
7
|
+
Thread.current["active_record_sql_runtime"] = value
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.runtime
|
11
|
+
Thread.current["active_record_sql_runtime"] ||= 0
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.reset_runtime
|
15
|
+
rt, self.runtime = runtime, 0
|
16
|
+
rt
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.attach_to(namespace)
|
20
|
+
log_subscriber = new
|
21
|
+
log_subscriber.public_methods(false).each do |event|
|
22
|
+
ActiveSupport::Notifications.unsubscribe "#{event}.#{namespace}"
|
23
|
+
end
|
24
|
+
super namespace, log_subscriber
|
25
|
+
end
|
26
|
+
|
27
|
+
def render_bind(attribute)
|
28
|
+
value = if attribute.type.binary? && attribute.value
|
29
|
+
"<#{attribute.value.bytesize} bytes of binary data>"
|
30
|
+
else
|
31
|
+
attribute.value_for_database
|
32
|
+
end
|
33
|
+
|
34
|
+
[attribute.name, value]
|
35
|
+
end
|
36
|
+
|
37
|
+
def sql(event)
|
38
|
+
return unless logger.debug?
|
39
|
+
|
40
|
+
self.class.runtime += event.duration
|
41
|
+
|
42
|
+
payload = event.payload
|
43
|
+
|
44
|
+
return if IGNORE_PAYLOAD_NAMES.include?(payload[:name])
|
45
|
+
|
46
|
+
name = "#{payload[:name]} (#{event.duration.round(1)}ms)"
|
47
|
+
sql = payload[:sql]
|
48
|
+
binds = nil
|
49
|
+
|
50
|
+
unless (payload[:binds] || []).empty?
|
51
|
+
binds = " " + payload[:binds].map { |attr| render_bind(attr) }.inspect
|
52
|
+
end
|
53
|
+
|
54
|
+
name = color(name, nil, true)
|
55
|
+
sql = color(sql, sql_color(sql), true)
|
56
|
+
|
57
|
+
debug " #{name} #{sql}#{binds}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def sql_color(sql)
|
61
|
+
case sql
|
62
|
+
when /\s*\Ainsert/i then
|
63
|
+
GREEN
|
64
|
+
when /\s*\Aselect/i then
|
65
|
+
BLUE
|
66
|
+
when /\s*\Aupdate/i then
|
67
|
+
YELLOW
|
68
|
+
when /\s*\Adelete/i then
|
69
|
+
RED
|
70
|
+
when /(begin|commit|rollback)/i then
|
71
|
+
CYAN
|
72
|
+
else
|
73
|
+
MAGENTA
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def logger
|
78
|
+
::ActiveRecord::Base.logger
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
ConsoleColoration::ActiveRecord::LogSubscriber.attach_to :active_record
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: console-coloration
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Ostroumov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.22
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.22
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.22
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.2.22
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: ''
|
70
|
+
email:
|
71
|
+
- andrew.ostroumov@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- bin/console
|
82
|
+
- bin/setup
|
83
|
+
- console-coloration.gemspec
|
84
|
+
- lib/console-coloration.rb
|
85
|
+
- lib/console_coloration/active_record/log_subscriber.rb
|
86
|
+
- lib/console_coloration/version.rb
|
87
|
+
homepage: https://github.com/Ynnni/console-coloration
|
88
|
+
licenses: []
|
89
|
+
metadata:
|
90
|
+
allowed_push_host: https://rubygems.org
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.4.5
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Rails console coloration
|
111
|
+
test_files: []
|