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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82602edd7ada1606c4d57b9295082549d459f219
4
- data.tar.gz: 127987efbe6ea8b8b35c29cff1ee19e79fcf3343
3
+ metadata.gz: ce29f4c933417b28a33a4741dd68a5272fa826a5
4
+ data.tar.gz: 16b6f10369799d91d44b1826718c971f13963201
5
5
  SHA512:
6
- metadata.gz: 0202059f7b57dba2b6fa56278cf534748f191c46454d43634619e8e6653dd19fa518caf1c11d929bfc8f435804763f77f4f21539f4ea6ebc20ed7e36322137b7
7
- data.tar.gz: 5902bb40c3f183f693434ee7c0789812456ec19ce40e08b82d76f9010be2b4ab432e0e042ef4d2f805bac3c3a077da9494ae5c9b89a87d3ffbc348e4bdcf5c2f
6
+ metadata.gz: 5bfc48d11fe07b44a55111afdd05beed8adb2d3ce8d7ef99afee150ef0ced242123bf669f0fc1a30e39bb2c18d3ce968fadd2e7b7ce28c5da5a0fa625175bfbb
7
+ data.tar.gz: aec9536a228153c16622d22c1fbe675b2551f00208ccd4337b972950f7938c8550ee6baeee5fbf4234c3f9c9561e10b95bb342277a8a7ce09f98574d0a5546f9
data/.rubocop.yml CHANGED
@@ -12,6 +12,3 @@ StructInheritance:
12
12
  # `module_function` introduces by not copying private methods to the class.
13
13
  Style/ModuleFunction:
14
14
  Enabled: false
15
-
16
- Style/TrivialAccessors:
17
- Enabled: false
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 = template.render(data)
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
- def initialize(input)
10
- @input = input
9
+ # This is used to indicate when a source file is malformed.
10
+ class FormatError < StandardError
11
11
  end
12
12
 
13
- def variable_names
14
- extract_variable_names(ast).uniq
13
+ def initialize(input, verbose)
14
+ @input = input
15
+ @verbose = verbose
15
16
  end
16
17
 
17
18
  def render(hash)
18
- Mustache.render(input, hash)
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
- # See Mustache::Generator#compile! for reference code
24
- def extract_variable_names(tree)
25
- return unless tree.is_a?(Array)
26
- if tree[1] == :fetch
27
- tree.last.first
28
- else
29
- tree.map { |token| extract_variable_names(token) }.flatten.compact
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
@@ -1,4 +1,4 @@
1
1
  # http://semver.org/
2
2
  module HSQL
3
- VERSION = '0.3.5'
3
+ VERSION = '0.3.6'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hsql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Danger Canty