hsql 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -3
- data/lib/hsql/file.rb +1 -27
- data/lib/hsql/template.rb +21 -13
- data/lib/hsql/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce29f4c933417b28a33a4741dd68a5272fa826a5
|
4
|
+
data.tar.gz: 16b6f10369799d91d44b1826718c971f13963201
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bfc48d11fe07b44a55111afdd05beed8adb2d3ce8d7ef99afee150ef0ced242123bf669f0fc1a30e39bb2c18d3ce968fadd2e7b7ce28c5da5a0fa625175bfbb
|
7
|
+
data.tar.gz: aec9536a228153c16622d22c1fbe675b2551f00208ccd4337b972950f7938c8550ee6baeee5fbf4234c3f9c9561e10b95bb342277a8a7ce09f98574d0a5546f9
|
data/.rubocop.yml
CHANGED
data/lib/hsql/file.rb
CHANGED
@@ -10,10 +10,6 @@ module HSQL
|
|
10
10
|
class File
|
11
11
|
attr_reader :string, :timestamp, :environment
|
12
12
|
|
13
|
-
# This is used to indicate when a source file is malformed.
|
14
|
-
class FormatError < StandardError
|
15
|
-
end
|
16
|
-
|
17
13
|
def initialize(string, options)
|
18
14
|
@string = string
|
19
15
|
@timestamp = options.fetch(:timestamp, Time.current)
|
@@ -56,10 +52,6 @@ module HSQL
|
|
56
52
|
|
57
53
|
private
|
58
54
|
|
59
|
-
def verbose?
|
60
|
-
@verbose
|
61
|
-
end
|
62
|
-
|
63
55
|
def split!
|
64
56
|
@split ||= begin
|
65
57
|
top_half, divider, rest = string.partition(/^---$/)
|
@@ -81,27 +73,9 @@ module HSQL
|
|
81
73
|
end
|
82
74
|
end
|
83
75
|
|
84
|
-
def template
|
85
|
-
template = Template.new(@sql)
|
86
|
-
template.variable_names.each do |name|
|
87
|
-
next if data.key?(name)
|
88
|
-
if environment
|
89
|
-
fail FormatError, "#{name.inspect} is not set in #{environment.inspect} environment"
|
90
|
-
else
|
91
|
-
fail FormatError, "#{name.inspect} is not set! Did you provide the right environment argument?"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
template
|
95
|
-
end
|
96
|
-
|
97
76
|
def interpolate_data!
|
98
77
|
# Insert the `data:` section of YAML for the given environment into our SQL queries.
|
99
|
-
@rendered_sql =
|
100
|
-
if verbose?
|
101
|
-
STDERR.puts '-- Rendered SQL:'
|
102
|
-
STDERR.puts @rendered_sql
|
103
|
-
end
|
104
|
-
@rendered_sql
|
78
|
+
@rendered_sql = Template.new(@sql, @verbose).render(data)
|
105
79
|
end
|
106
80
|
end
|
107
81
|
end
|
data/lib/hsql/template.rb
CHANGED
@@ -6,28 +6,36 @@ module HSQL
|
|
6
6
|
class Template
|
7
7
|
attr_reader :input
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
# This is used to indicate when a source file is malformed.
|
10
|
+
class FormatError < StandardError
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
|
13
|
+
def initialize(input, verbose)
|
14
|
+
@input = input
|
15
|
+
@verbose = verbose
|
15
16
|
end
|
16
17
|
|
17
18
|
def render(hash)
|
18
|
-
Mustache.
|
19
|
+
Mustache.raise_on_context_miss = true
|
20
|
+
output = Mustache.render(input, hash)
|
21
|
+
if @verbose
|
22
|
+
STDERR.puts '-- Rendered SQL:'
|
23
|
+
STDERR.puts output
|
24
|
+
end
|
25
|
+
output
|
26
|
+
rescue Mustache::ContextMiss => e
|
27
|
+
fail_with(e.message, hash.keys.sort)
|
19
28
|
end
|
20
29
|
|
21
30
|
private
|
22
31
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
32
|
+
def fail_with(message, keys)
|
33
|
+
# Pull the missing template tag out of the message
|
34
|
+
tag = message.scan(/Can't find (\w+) in /).flatten.first
|
35
|
+
message = "Missing variable {{{ #{tag} }}}. At this point in the template the available variables are:"
|
36
|
+
message += "\n"
|
37
|
+
message += keys.join(', ')
|
38
|
+
fail FormatError, message
|
31
39
|
end
|
32
40
|
|
33
41
|
def ast
|
data/lib/hsql/version.rb
CHANGED