epoxy 0.1.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/epoxy.rb +9 -9
  3. data/test/test_epoxy.rb +11 -0
  4. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.1
@@ -22,14 +22,10 @@ class Epoxy
22
22
  #
23
23
  # Probably not the easiest thing to deal with by itself. Use the standard
24
24
  # methods plox.
25
- def self.parse_tokens(query)
25
+ def self.parse_tokens(query, comment_chars)
26
26
  query.scan(%r{
27
27
  (
28
- -- .* (?# matches "--" style comments to the end of line or string )
29
- | - (?# matches single "-" )
30
- |
31
- /[*] .*? [*]/ (?# matches C-style comments )
32
- | / (?# matches single slash )
28
+ #{comment_chars}.* (?# matches "--" style comments to the end of line or string )
33
29
  |
34
30
  ' ( [^'\\] | '' | \\. )* ' (?# match strings surrounded by apostophes )
35
31
  |
@@ -49,18 +45,22 @@ class Epoxy
49
45
  attr_reader :tokens
50
46
  # the original query, before quoting.
51
47
  attr_reader :query
48
+ # leader comment characters - defaults to SQL "--"
49
+ attr_reader :comment_chars
52
50
 
53
51
  #
54
- # Takes a query as a string. The binding rules are as follows:
52
+ # Takes a query as a string and an optional regexp defining
53
+ # beginning-of-line comments. The binding rules are as follows:
55
54
  #
56
55
  # * ? for numbered binds (named binds coming soon!)
57
56
  # * ?? for a *real* question mark
58
57
  # * '?' for a *real* question mark
59
58
  # * comments, weird quoting styles are unaffected.
60
59
  #
61
- def initialize(query)
60
+ def initialize(query, comment_chars=%r{--|//})
61
+ @comment_chars = comment_chars
62
62
  @query = query
63
- @tokens = self.class.parse_tokens(query)
63
+ @tokens = self.class.parse_tokens(query, @comment_chars)
64
64
  end
65
65
 
66
66
  #
@@ -127,5 +127,16 @@ class TestEpoxy < Test::Unit::TestCase
127
127
  -- a comment!
128
128
  select * from foo where bar='foo'
129
129
  }.strip, ep.quote { |x| "'foo'" })
130
+
131
+ ep = Epoxy.new(%Q{
132
+ # a comment!
133
+ select * from foo where bar=?
134
+ }.strip, %r{#})
135
+
136
+ assert_equal(%Q{
137
+ # a comment!
138
+ select * from foo where bar='foo'
139
+ }.strip, ep.quote { |x| "'foo'" })
140
+
130
141
  end
131
142
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 2
7
8
  - 1
8
- - 1
9
- version: 0.1.1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Erik Hollensbe