epoxy 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/epoxy.rb +9 -9
- data/test/test_epoxy.rb +11 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.1
|
data/lib/epoxy.rb
CHANGED
@@ -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
|
-
|
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
|
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
|
#
|
data/test/test_epoxy.rb
CHANGED
@@ -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
|