pretty_sql 0.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.
- checksums.yaml +7 -0
- data/lib/pretty_sql.rb +57 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 196812e34da97f2780a601080ddab959f5a6a784
|
4
|
+
data.tar.gz: 766fe8df45cb2785db4ac3979d2b55747407e935
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1cb706e8085f0c29fd91cb45bc7c999e764776ac7ec12d6c2a12db58fc652959dabd8fd473c1ec8dedec40af8b6086eeb2ffbc4da11663b293917675b9bc8dc9
|
7
|
+
data.tar.gz: e806cf1763f71b28a71341abb819018b6094e49fc97e4bc53b1040d8689ff8ee8f4749bafc559b36442cb68c6ab6fdbc2b97028f7e73eb6c3c137b16145d60f2
|
data/lib/pretty_sql.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'anbt-sql-formatter/formatter'
|
2
|
+
|
3
|
+
|
4
|
+
module PrettySql
|
5
|
+
PYGMENTIZE_EXEC_NAME = 'pygmentize'
|
6
|
+
|
7
|
+
def prettify_sql(sql)
|
8
|
+
pygmentize_sql(tidy_sql(sql))
|
9
|
+
end
|
10
|
+
|
11
|
+
def pygmentize_sql(sql)
|
12
|
+
# Colorize SQL by piping to pygmentize if it exists.
|
13
|
+
|
14
|
+
return sql unless pygmentize_path
|
15
|
+
|
16
|
+
IO.popen("#{pygmentize_path} -l sql", 'r+') do |process|
|
17
|
+
process.write(sql)
|
18
|
+
process.close_write
|
19
|
+
process.read
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def tidy_sql(sql)
|
24
|
+
# Auto-indent SQL
|
25
|
+
|
26
|
+
rule = AnbtSql::Rule.new
|
27
|
+
rule.keyword = AnbtSql::Rule::KEYWORD_UPPER_CASE
|
28
|
+
%w(count sum substr date).each do |func_name|
|
29
|
+
rule.function_names << func_name.upcase
|
30
|
+
end
|
31
|
+
rule.indent_string = " "
|
32
|
+
formatter = AnbtSql::Formatter.new(rule)
|
33
|
+
formatter.format(sql)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def pygmentize_path
|
39
|
+
@pygmentize_path ||= get_pygmentize_executable
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_pygmentize_executable
|
43
|
+
# Find executable for pygmentize
|
44
|
+
|
45
|
+
return ENV['PYGMENTIZE_PATH'] if ENV['PYGMENTIZE_PATH']
|
46
|
+
|
47
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
48
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
49
|
+
exts.each { |ext|
|
50
|
+
exe = File.join(path, "#{PYGMENTIZE_EXEC_NAME}#{ext}")
|
51
|
+
return exe if File.executable?(exe) && !File.directory?(exe)
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
return nil
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pretty_sql
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Benoit C. Sirois
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: anbt-sql-formatter
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.2
|
27
|
+
description: Uses pygmentize and anbt-sql-formatter to auto-indent and colorize SQL
|
28
|
+
email: benoitcsirois@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/pretty_sql.rb
|
34
|
+
homepage: https://github.com/benwah/pretty_sql
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.0.3
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Indents and colorizes SQL
|
58
|
+
test_files: []
|