pp_sql 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cd3dfaa01fbb7627de5389a43ede8449692eca12
4
+ data.tar.gz: 48fb42aef3883ec4e9c250e61f41e5092a3cd6b0
5
+ SHA512:
6
+ metadata.gz: 39c3f0b45e622129f391f768b5f572d34fecebfb4f7aa77bfbee1402d4ab2c5465afea27905b9b832ad2750bfae765c871c5924cdec6463e900efcbb97a4cdd9
7
+ data.tar.gz: aa3ae462c6cfda42971006c257e6b05c9f2304f2c39f52ed6fb1fd6100feeb752cd5453d7211fd9953a55854b94e54713984e137dcc286f2b3871ac1bd51f546
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Kvokka
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # PpSql
2
+
3
+ Replace stanpard `ActieRecord#to_sql` method with [`anbt-sql-formatter`](https://github.com/sonota88/anbt-sql-formatter)
4
+ gem for pretty SQL code output in console. For example:
5
+ ```
6
+ # was
7
+ User.all # =>
8
+ "SELECT `users`. * FROM `users`"
9
+
10
+ # thus
11
+ # =>
12
+ SELECT
13
+ `users`. *
14
+ FROM
15
+ `users`
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```
21
+ Post.first.to_sql
22
+ ```
23
+
24
+ If you need yo use it in some custome strings, you may include this funcional with
25
+
26
+ ```
27
+ String.send :include, PpSql::ToSqlBeautify
28
+ ```
29
+
30
+ and use formatter with any String.
31
+
32
+ ## Installation
33
+
34
+ add in Gemfile
35
+ ```
36
+ gem 'pp_sql', group :development
37
+ ```
38
+
39
+ And then execute:
40
+ ```bash
41
+ $ bundle
42
+ ```
43
+
44
+ ## With other formatters
45
+
46
+ If you are `pry` user, or use custom output formatter, use `puts` for output whitespaces,
47
+ like `puts User.all.to_sql`
48
+
49
+ ## License
50
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'PpSql'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,3 @@
1
+ module PpSql
2
+ VERSION = '0.1.0'
3
+ end
data/lib/pp_sql.rb ADDED
@@ -0,0 +1,26 @@
1
+ module PpSql
2
+ module ToSqlBeautify
3
+ def to_sql
4
+ _sql_formatter.format(super)
5
+ end
6
+
7
+ private
8
+
9
+ def _sql_formatter
10
+ return @_sql_formatter if @_sql_formatter
11
+ require "anbt-sql-formatter/formatter"
12
+ rule = AnbtSql::Rule.new
13
+ rule.keyword = AnbtSql::Rule::KEYWORD_UPPER_CASE
14
+ %w(count sum substr date).each { |func_name| rule.function_names << func_name.upcase }
15
+ rule.indent_string = " "
16
+ @_sql_formatter = AnbtSql::Formatter.new(rule)
17
+ end
18
+ end
19
+ class Railtie < Rails::Railtie
20
+ initializer "pp_sql.override_to_sql" do
21
+ ActiveSupport.on_load(:active_record) do
22
+ ActiveRecord::Relation.send(:prepend, ToSqlBeautify)
23
+ end
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pp_sql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kvokka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: anbt-sql-formatter
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.5
41
+ description: Helps to save your eyes, when reading hardcore SQL requests in console
42
+ email:
43
+ - root_p@mail.ru
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - lib/pp_sql.rb
52
+ - lib/pp_sql/version.rb
53
+ homepage: https://github.com/kvokka/pp_sql
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.5.1
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Beautify SQL output of ActiveRecord#to_sql
77
+ test_files: []