listen_sql 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bccbdff2ae002cf6221b8bb674d854b7f673fa3d
4
- data.tar.gz: f87ddc77910c2aabcf6757d30fb3f4b4e7c5e11e
3
+ metadata.gz: 0c54c83fcbf2176382bb77c8fc0c1b93a620ee5e
4
+ data.tar.gz: aae8823e8e3147e3d2043465d7a1af699062e101
5
5
  SHA512:
6
- metadata.gz: 4b9513391e249d252ba44ffb1f24df8031a4ebbe5abd04fc4582951ceaabef8ab00d8d6b639e5fc4a363d0561214ed52d55cb07dcf13e8bcddbc872ab0b07408
7
- data.tar.gz: 0053abd0c56fe20968ad6230c34ae2111c35f3001b3db6d0bd0f5c0abccc82057c8d39b065eddb67d21d02ca42e63dc53a2f7be288abee290f7708c2399c7187
6
+ metadata.gz: fede8c8451607716012a5fc9f64b64f75e49c6f4e34c984285779d41b6e3fd2dbb5cfa0474639d6a2f2d07789d77f5f3b1e6d21000c2c9504f8c82b84cddef09
7
+ data.tar.gz: a47a5b39da00fbf5f13a6d28ccb4dc286e67d34382ee366f0a51e06ae255058863511c4da41f80c9b0a1666548daf62cf42855bcc9d77749eab3ae891869039e
data/exe/exec_sql CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'shellwords'
4
- require 'coderay'
3
+ require 'bundler/setup'
4
+ require 'listen_sql'
5
5
 
6
6
  def usage(message=nil)
7
7
  text = <<-TEXT
@@ -26,27 +26,9 @@ def usage(message=nil)
26
26
  puts text
27
27
  end
28
28
 
29
- def exec_sql(db_name, file, color: true)
30
- puts "File: #{file}"
31
- puts "Time: #{Time.now}"
32
-
33
- # Show original SQL
34
- puts "SQL: "
35
- sql = File.read(file)
36
- puts(color ? CodeRay.scan(sql, :sql).terminal : sql)
37
-
38
- # Show Resultset
39
- puts "Rows: "
40
- puts `psql #{db_name} < #{Shellwords.escape file}`
41
- end
42
-
43
- def stop(message)
44
-
45
- end
46
-
47
29
  if $0 == __FILE__
48
30
  db_name = ARGV.shift || usage('DBNAME should be first argument or set PGDATABASE in ENV!')
49
31
  src = ARGV.shift || usage('SRC should be second argument!')
50
32
  no_color = ARGV.detect{|a| a == '--no-color'}
51
- exec_sql(db_name, src, color: !no_color)
33
+ ListenSql.exec_sql(db_name, src, color: !no_color)
52
34
  end
data/exe/listen_sql CHANGED
@@ -3,10 +3,9 @@
3
3
  # Listens for any SQL file changes and executes them using the default PSQL
4
4
  # settings.
5
5
 
6
+ require 'bundler/setup'
7
+ require 'listen_sql'
6
8
  require 'listen'
7
- require 'shellwords'
8
- require 'coderay'
9
- load File.join(__dir__, 'exec_sql')
10
9
 
11
10
  def usage(message=nil)
12
11
  text = <<-TEXT
@@ -28,11 +27,13 @@ db_name = ARGV.shift || ENV['PGDATABASE'] || usage('DBNAME should be second argu
28
27
 
29
28
  listener = Listen.to(dir, only: /\.sql$/) do |modified, _|
30
29
  modified.each do |file|
31
- exec_sql(db_name, file, color: true)
30
+ ListenSql.exec_sql(db_name, file, color: true)
32
31
  end
33
32
  end
34
33
 
35
34
  if $0 == __FILE__
36
35
  listener.start # not blocking
36
+ puts "Watching for changes to #{dir}"
37
+ puts "<CTRL-C> to quit"
37
38
  sleep
38
39
  end
@@ -1,3 +1,3 @@
1
1
  module ListenSql
2
- VERSION = "0.1.0"
2
+ VERSION = '0.1.1'
3
3
  end
data/lib/listen_sql.rb CHANGED
@@ -1,5 +1,22 @@
1
- require "listen_sql/version"
1
+ require 'listen_sql/version'
2
+
3
+ require 'shellwords'
4
+ require 'coderay'
2
5
 
3
6
  module ListenSql
4
- # Your code goes here...
7
+ module_function
8
+
9
+ def exec_sql(db_name, file, color: true)
10
+ puts "File: #{file}"
11
+ puts "Time: #{Time.now}"
12
+
13
+ # Show original SQL
14
+ puts "SQL: "
15
+ sql = File.read(file)
16
+ puts(color ? CodeRay.scan(sql, :sql).terminal : sql)
17
+
18
+ # Show Resultset
19
+ puts "Rows: "
20
+ puts `psql #{db_name} < #{Shellwords.escape file}`
21
+ end
5
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: listen_sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Pierce