sqltorial 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -2
- data/exe/sqltorial +3 -0
- data/lib/sqltorial/assemble_command.rb +14 -0
- data/lib/sqltorial/metadata.rb +1 -1
- data/lib/sqltorial/sql_to_example.rb +5 -5
- data/sqltorial.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b81ab5d2e41712b52e7b96f1f6332e5a28c2ee01
|
4
|
+
data.tar.gz: 88ad7165935ab617c70786ddd96546c2545c2e35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cbc570b9ea4c206a0811816e307ab89d05ef6904ea1250dacd4a976d9a9aebfdd59e601c460b3914a2462e76fbd55d4e5d62d4ae8da6cf1ebfdc98a22abec1a
|
7
|
+
data.tar.gz: dcaf1f0cef469d9ca8fc8b56d15b1b7ff6113368ce1f9c2d3b33a5b8aef26e1c5128166d180d4506df4be0d0483d106edf0e776c3c90ef86ebfedfab04bc8e3a
|
data/CHANGELOG.md
CHANGED
@@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file.
|
|
6
6
|
|
7
7
|
### Added
|
8
8
|
|
9
|
-
-
|
9
|
+
- Watch mode.
|
10
10
|
|
11
11
|
### Deprecated
|
12
12
|
|
@@ -18,7 +18,7 @@ All notable changes to this project will be documented in this file.
|
|
18
18
|
|
19
19
|
### Fixed
|
20
20
|
|
21
|
-
-
|
21
|
+
- Better handling of whitespace.
|
22
22
|
|
23
23
|
## 0.0.3 - 2015-09-03
|
24
24
|
|
data/exe/sqltorial
CHANGED
@@ -8,11 +8,14 @@ Escort::App.create do |app|
|
|
8
8
|
app.version SQLtorial::VERSION
|
9
9
|
app.summary SQLtorial::SUMMARY
|
10
10
|
app.description SQLtorial::DESCRIPTION
|
11
|
+
|
11
12
|
app.options do |opts|
|
12
13
|
opts.opt :no_results, "Don't Include Results", short: '-n', long: '--no-results', type: :boolean, default: false
|
13
14
|
opts.opt :output, "Output File", short: '-o', long: '--output', type: :string, default: 'output.md'
|
14
15
|
opts.opt :preface, "Preface File", short: '-p', long: '--preface', type: :string, default: 'preface.md'
|
16
|
+
opts.opt :watch, "Watch Mode", short: '-w', long: '--watch', type: :boolean, default: false
|
15
17
|
end
|
18
|
+
|
16
19
|
app.action do |options, arguments|
|
17
20
|
begin
|
18
21
|
SQLtorial::AssembleCommand.new(options, arguments).execute
|
@@ -1,11 +1,25 @@
|
|
1
1
|
require_relative 'sql_to_example'
|
2
2
|
require 'sequelizer'
|
3
3
|
require 'facets/pathname/chdir'
|
4
|
+
require 'listen'
|
4
5
|
|
5
6
|
module SQLtorial
|
6
7
|
class AssembleCommand < ::Escort::ActionCommand::Base
|
7
8
|
include Sequelizer
|
8
9
|
def execute
|
10
|
+
global_options[:watch] ? watch : process
|
11
|
+
end
|
12
|
+
|
13
|
+
def watch
|
14
|
+
listener = Listen.to(path) do |modified, added, removed|
|
15
|
+
process
|
16
|
+
end
|
17
|
+
listener.only(/\.sql$/)
|
18
|
+
listener.start
|
19
|
+
sleep while listener.processing?
|
20
|
+
end
|
21
|
+
|
22
|
+
def process
|
9
23
|
process_dir.chdir do
|
10
24
|
preface = Pathname.new(global_options[:preface]) if global_options[:preface]
|
11
25
|
File.open(global_options[:output], 'w') do |f|
|
data/lib/sqltorial/metadata.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module SQLtorial
|
2
|
-
VERSION = "0.0.
|
2
|
+
VERSION = "0.0.4"
|
3
3
|
SUMMARY = %q{Knitr, but for SQL files, sorta}
|
4
4
|
DESCRIPTION = %q{Ingests a set of commented SQL statements, executes them, and dumps the comments, queries, and results into a markdown file}
|
5
5
|
HOMEPAGE = "http://github.com/outcomesinsights/sqltorial"
|
@@ -3,6 +3,7 @@ require_relative 'query_to_md'
|
|
3
3
|
require_relative 'formatter'
|
4
4
|
|
5
5
|
module SQLtorial
|
6
|
+
WHITESPACE_REGEX = /^\s*--/
|
6
7
|
class SqlToExample
|
7
8
|
attr :file, :db
|
8
9
|
def initialize(file, db, number)
|
@@ -38,16 +39,16 @@ module SQLtorial
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def title
|
41
|
-
@title ||= title_line.gsub(
|
42
|
+
@title ||= title_line.gsub(WHITESPACE_REGEX, '')
|
42
43
|
end
|
43
44
|
|
44
45
|
def make_prose_directives_and_query(query)
|
45
46
|
lines = query.dup
|
46
47
|
prose_lines = []
|
47
48
|
lines.shift while lines.first.strip.empty?
|
48
|
-
prose_lines << lines.shift.sub(
|
49
|
+
prose_lines << lines.shift.sub(WHITESPACE_REGEX, ' ').sub(/^\s*$/, "\n\n") while lines.first && (lines.first =~ WHITESPACE_REGEX || lines.first.empty?)
|
49
50
|
directives, prose_lines = prose_lines.partition { |line| Directive.match(line) }
|
50
|
-
[prose_lines.join(''), process_directives(directives), lines.join
|
51
|
+
[prose_lines.join(''), process_directives(directives), lines.join]
|
51
52
|
end
|
52
53
|
|
53
54
|
def number
|
@@ -74,7 +75,6 @@ module SQLtorial
|
|
74
75
|
puts sql
|
75
76
|
puts $!.message
|
76
77
|
puts $!.backtrace.join("\n")
|
77
|
-
$stdin.gets
|
78
78
|
end
|
79
79
|
end
|
80
80
|
parts = []
|
@@ -101,7 +101,7 @@ module SQLtorial
|
|
101
101
|
end
|
102
102
|
|
103
103
|
def get_title_and_formatted_lines
|
104
|
-
all_lines = formatted.split("\n")
|
104
|
+
all_lines = formatted.split("\n").map { |l| l += "\n" }
|
105
105
|
title_line = all_lines.shift
|
106
106
|
[title_line, all_lines]
|
107
107
|
end
|
data/sqltorial.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqltorial
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Duryea
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.4.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: listen
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.0.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 3.0.0
|
97
111
|
description: Ingests a set of commented SQL statements, executes them, and dumps the
|
98
112
|
comments, queries, and results into a markdown file
|
99
113
|
email:
|