each_sql 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,27 @@
1
- === 0.2.4 / 2011/08/04
1
+ ### 0.2.5 / 2011/09/01
2
+ * Can pass block directly to EachSQL(script)
3
+ ```ruby
4
+ EachSQL(script) do |sql|
5
+ # ...
6
+ end
7
+ ```
8
+
9
+ ### 0.2.4 / 2011/08/04
2
10
  * Bug fix: Strip semicolons at both ends
3
11
 
4
- === 0.2.3 / 2011/07/08
12
+ ### 0.2.3 / 2011/07/08
5
13
  * Bug fix: Two Oracle PL/SQL parsing errors fixed
6
14
 
7
- === 0.2.2 / 2011/06/21
15
+ ### 0.2.2 / 2011/06/21
8
16
  * Bug fix: Error on nil/empty input
9
17
 
10
- === 0.2.1 / 2011/06/20
18
+ ### 0.2.1 / 2011/06/20
11
19
  * Fixed invalid gem packaging
12
20
 
13
- === 0.2.0 / 2011/06/17
21
+ ### 0.2.0 / 2011/06/17
14
22
  * Second release. Handles more cases.
15
23
  * Ruby 1.8 compatible
16
24
 
17
- === 0.1.0 / 2011/06/15
25
+ ### 0.1.0 / 2011/06/15
18
26
  * Initial release. Turned out to be very flawed :p
19
27
 
data/Gemfile.lock CHANGED
@@ -2,13 +2,13 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  git (1.2.5)
5
- jeweler (1.6.2)
5
+ jeweler (1.6.4)
6
6
  bundler (~> 1.0)
7
7
  git (>= 1.2.5)
8
8
  rake
9
- rake (0.8.7)
10
- rcov (0.9.9)
11
- rcov (0.9.9-java)
9
+ rake (0.9.2)
10
+ rcov (0.9.10)
11
+ rcov (0.9.10-java)
12
12
 
13
13
  PLATFORMS
14
14
  java
@@ -1,39 +1,50 @@
1
- = each_sql
1
+ # each_sql
2
2
 
3
3
  Enumerate each SQL statement in the given SQL script.
4
4
 
5
- == Installation
6
- gem install 'each_sql'
7
-
8
- == Example
9
- === Basic
10
- require 'each_sql'
11
-
12
- EachSQL(sql_script).each do |sql|
13
- puts sql
14
- end
15
-
16
- sqls = EachSQL(sql_script).to_a
17
-
18
- === For scripts containing vendor-specific syntax
19
- # For MySQL script
20
- EachSQL(mysql_script, :mysql).each do |sql|
21
- # ...
22
- end
23
-
24
- # For Oracle PL/SQL scripts
25
- EachSQL(plsql_script, :oracle).each do |sql|
26
- # ...
27
- end
28
-
29
- == TODO
5
+ ## Installation
6
+ ```
7
+ gem install 'each_sql'
8
+ ```
9
+
10
+ ## Example
11
+ ### Basic
12
+ ```ruby
13
+ require 'each_sql'
14
+
15
+ EachSQL(sql_script).each do |sql|
16
+ puts sql
17
+ end
18
+
19
+ # .each can be omitted
20
+ EachSQL(sql_script) do |sql|
21
+ puts sql
22
+ end
23
+
24
+ sqls = EachSQL(sql_script).to_a
25
+ ```
26
+
27
+ ### For scripts containing vendor-specific syntax
28
+ ```ruby
29
+ # For MySQL script
30
+ EachSQL(mysql_script, :mysql).each do |sql|
31
+ # ...
32
+ end
33
+
34
+ # For Oracle PL/SQL scripts
35
+ EachSQL(plsql_script, :oracle).each do |sql|
36
+ # ...
37
+ end
38
+ ```
39
+
40
+ ## TODO
30
41
  - More/better tests.
31
42
  - pgplsql support.
32
43
 
33
- == Warning
44
+ ## Warning
34
45
  Stored procedure handling is at best incomplete. Use it at your own risk.
35
46
 
36
- == Contributing to each_sql
47
+ ## Contributing to each_sql
37
48
 
38
49
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
39
50
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
@@ -43,7 +54,7 @@ Stored procedure handling is at best incomplete. Use it at your own risk.
43
54
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
44
55
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
45
56
 
46
- == Copyright
57
+ ## Copyright
47
58
 
48
59
  Copyright (c) 2011 Junegunn Choi. See LICENSE.txt for
49
60
  further details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.2.5
@@ -3,171 +3,171 @@
3
3
 
4
4
  # Enumerable EachSQL object.
5
5
  class EachSQL
6
- include Enumerable
7
-
8
- def initialize input, options
9
- raise NotImplementedError.new if options.nil?
10
- # immutables
11
- @org_input = input && input.sub(/\A#{[65279].pack('U*')}/, '') # BOM
12
- @options = options
13
- @blocks = @options[:blocks]
14
- @nblocks = @options[:nesting_blocks]
15
- @all_blocks = @blocks.merge @nblocks
16
- end
17
-
18
- def each
19
- return nil if @org_input.nil? || @org_input.empty?
20
- @input = @org_input.dup
21
-
22
- # Zero out comments and string literals to simplify subsequent parsing
23
- @input_c = zero_out @org_input
24
-
25
- @delimiter = @options[:delimiter]
26
- while @input && @input.length > 0
27
- # Extract a statement
28
- statement = next_statement
29
-
30
- # When a non-empty statement is found
31
- statement = @options[:strip_delimiter].call self, statement if @options[:strip_delimiter]
32
- if statement.length > 0
33
- # Apply replacements
34
- @options[:replace].each do |k, v|
35
- statement.gsub!(k, v)
36
- end
37
- statement.strip!
38
-
39
- # Process callbacks
40
- @options[:callbacks].each do |pattern, callback|
41
- #md = statement.match pattern
42
- md = zero_out(statement).strip.match pattern
43
- callback.call self, statement, md if md
44
- end
45
-
46
- # Ignore
47
- if (@options[:ignore] || []).all? { |ipat| statement !~ ipat } && statement.empty? == false
48
- yield statement
49
- @prev_statement = statement
50
- end
51
- end
52
- end
53
- nil
54
- end
55
-
56
- # To change delimiter while parsing the input
57
- attr_accessor :delimiter, :delimiter_string
58
-
59
- private
60
- def zero_out input
61
- output = input.dup
62
- idx = 0
63
- # Look for the closest block
64
- while true
65
- block_start, opener_length, opener, closer = @blocks.map { |opener, closer|
66
- md = match output, opener, idx
67
- [md && md[:begin], md && md[:length], opener, closer]
68
- }.reject { |e| e.first.nil? }.min_by(&:first)
69
- break if block_start.nil?
70
-
71
- md = match output, closer, block_start + opener_length
72
- idx = block_end = md ? md[:end] : (output.length-1)
73
-
74
- output[block_start...block_end] = ' ' * (block_end - block_start)
75
- end
76
- output
77
- end
78
-
79
- def next_statement
80
- @cur = 0
81
-
82
- while process_next_block != :done
83
- end
84
-
85
- ret = @input[0...@cur].strip
86
- @input = @input[@cur..-1]
87
- @input_c = @input_c[@cur..-1]
88
- return ret
89
- end
90
-
91
- def process_next_block expect = nil
92
- # Look for the closest delimiter
93
- md = match @input_c, @delimiter, @cur
94
- delim_start = md ? md[:begin] : @input.length
95
- delim_end = md ? md[:end] : @input.length
96
-
97
- # Look for the closest block depending on the current context
98
- target_blocks =
99
- if @options[:nesting_context].any? {|pat| @input_c.match pat }
100
- @all_blocks
101
- else
102
- @blocks
103
- end
104
-
105
- block_start, body_start, opener, closer = target_blocks.map { |opener, closer|
106
- closer = closer[:closer] if closer.is_a? Hash
107
- md = match @input_c, opener, @cur
108
- [md && md[:begin], md && md[:end], opener, closer]
109
- }.reject { |e| e.first.nil? }.min_by(&:first)
110
-
111
- # If we're nested, look for the parent's closer as well
112
- if expect && (md = match @input_c, expect, @cur) &&
113
- (block_start.nil? || md[:begin] < block_start)
114
-
115
- @cur = md[:end]
116
- return :nest_closer
117
- end
118
-
119
- # No block until the next delimiter
120
- if block_start.nil? || block_start > delim_start
121
- @cur = delim_end
122
- return :done
123
- end
124
-
125
- # We found a block. Look for the end of it
126
- @cur = body_start
127
-
128
- # If nesting block, we go deeper
129
- if @nblocks.keys.include? opener
130
- while true
131
- ret = process_next_block(closer)
132
- break if ret == :nest_closer
133
- throw_exception(closer) if @cur >= @input.length - 1
134
- end
135
- return :done if @nblocks[opener].is_a?(Hash) && @nblocks[opener][:pop]
136
-
137
- # If non-nesting block, just skip through it
138
- else
139
- skip_through_block closer
140
- end
141
-
142
- return :continue
143
- end
144
-
145
- # For Ruby 1.8 compatibility
146
- def match str, pat, idx
147
- md = str[idx..-1].match(pat)
148
- return nil if md.nil?
149
-
150
- result = {
151
- :begin => md && (md.begin(0) + idx),
152
- :length => md && md[0].length,
153
- :end => md && (md.end(0) + idx)
154
- }
155
- result
156
- end
157
-
158
- def skip_through_block closer
159
- md = match @input_c, closer, @cur
160
- throw_exception(closer) if md.nil?
161
-
162
- @cur = md[:end]
163
- end
164
-
165
- def throw_exception closer
166
- raise ArgumentError.new(
167
- "Unclosed block: was expecting #{closer.inspect} " +
168
- "while processing #{(@input[0, 60] + ' ... ').inspect}" +
169
- (@prev_statement ?
170
- " after #{@prev_statement.inspect}" : ""))
171
- end
6
+ include Enumerable
7
+
8
+ def initialize input, options
9
+ raise NotImplementedError.new if options.nil?
10
+ # immutables
11
+ @org_input = input && input.sub(/\A#{[65279].pack('U*')}/, '') # BOM
12
+ @options = options
13
+ @blocks = @options[:blocks]
14
+ @nblocks = @options[:nesting_blocks]
15
+ @all_blocks = @blocks.merge @nblocks
16
+ end
17
+
18
+ def each
19
+ return nil if @org_input.nil? || @org_input.empty?
20
+ @input = @org_input.dup
21
+
22
+ # Zero out comments and string literals to simplify subsequent parsing
23
+ @input_c = zero_out @org_input
24
+
25
+ @delimiter = @options[:delimiter]
26
+ while @input && @input.length > 0
27
+ # Extract a statement
28
+ statement = next_statement
29
+
30
+ # When a non-empty statement is found
31
+ statement = @options[:strip_delimiter].call self, statement if @options[:strip_delimiter]
32
+ if statement.length > 0
33
+ # Apply replacements
34
+ @options[:replace].each do |k, v|
35
+ statement.gsub!(k, v)
36
+ end
37
+ statement.strip!
38
+
39
+ # Process callbacks
40
+ @options[:callbacks].each do |pattern, callback|
41
+ #md = statement.match pattern
42
+ md = zero_out(statement).strip.match pattern
43
+ callback.call self, statement, md if md
44
+ end
45
+
46
+ # Ignore
47
+ if (@options[:ignore] || []).all? { |ipat| statement !~ ipat } && statement.empty? == false
48
+ yield statement
49
+ @prev_statement = statement
50
+ end
51
+ end
52
+ end
53
+ nil
54
+ end
55
+
56
+ # To change delimiter while parsing the input
57
+ attr_accessor :delimiter, :delimiter_string
58
+
59
+ private
60
+ def zero_out input
61
+ output = input.dup
62
+ idx = 0
63
+ # Look for the closest block
64
+ while true
65
+ block_start, opener_length, opener, closer = @blocks.map { |opener, closer|
66
+ md = match output, opener, idx
67
+ [md && md[:begin], md && md[:length], opener, closer]
68
+ }.reject { |e| e.first.nil? }.min_by(&:first)
69
+ break if block_start.nil?
70
+
71
+ md = match output, closer, block_start + opener_length
72
+ idx = block_end = md ? md[:end] : (output.length-1)
73
+
74
+ output[block_start...block_end] = ' ' * (block_end - block_start)
75
+ end
76
+ output
77
+ end
78
+
79
+ def next_statement
80
+ @cur = 0
81
+
82
+ while process_next_block != :done
83
+ end
84
+
85
+ ret = @input[0...@cur].strip
86
+ @input = @input[@cur..-1]
87
+ @input_c = @input_c[@cur..-1]
88
+ return ret
89
+ end
90
+
91
+ def process_next_block expect = nil
92
+ # Look for the closest delimiter
93
+ md = match @input_c, @delimiter, @cur
94
+ delim_start = md ? md[:begin] : @input.length
95
+ delim_end = md ? md[:end] : @input.length
96
+
97
+ # Look for the closest block depending on the current context
98
+ target_blocks =
99
+ if @options[:nesting_context].any? {|pat| @input_c.match pat }
100
+ @all_blocks
101
+ else
102
+ @blocks
103
+ end
104
+
105
+ block_start, body_start, opener, closer = target_blocks.map { |opener, closer|
106
+ closer = closer[:closer] if closer.is_a? Hash
107
+ md = match @input_c, opener, @cur
108
+ [md && md[:begin], md && md[:end], opener, closer]
109
+ }.reject { |e| e.first.nil? }.min_by(&:first)
110
+
111
+ # If we're nested, look for the parent's closer as well
112
+ if expect && (md = match @input_c, expect, @cur) &&
113
+ (block_start.nil? || md[:begin] < block_start)
114
+
115
+ @cur = md[:end]
116
+ return :nest_closer
117
+ end
118
+
119
+ # No block until the next delimiter
120
+ if block_start.nil? || block_start > delim_start
121
+ @cur = delim_end
122
+ return :done
123
+ end
124
+
125
+ # We found a block. Look for the end of it
126
+ @cur = body_start
127
+
128
+ # If nesting block, we go deeper
129
+ if @nblocks.keys.include? opener
130
+ while true
131
+ ret = process_next_block(closer)
132
+ break if ret == :nest_closer
133
+ throw_exception(closer) if @cur >= @input.length - 1
134
+ end
135
+ return :done if @nblocks[opener].is_a?(Hash) && @nblocks[opener][:pop]
136
+
137
+ # If non-nesting block, just skip through it
138
+ else
139
+ skip_through_block closer
140
+ end
141
+
142
+ return :continue
143
+ end
144
+
145
+ # For Ruby 1.8 compatibility
146
+ def match str, pat, idx
147
+ md = str[idx..-1].match(pat)
148
+ return nil if md.nil?
149
+
150
+ result = {
151
+ :begin => md && (md.begin(0) + idx),
152
+ :length => md && md[0].length,
153
+ :end => md && (md.end(0) + idx)
154
+ }
155
+ result
156
+ end
157
+
158
+ def skip_through_block closer
159
+ md = match @input_c, closer, @cur
160
+ throw_exception(closer) if md.nil?
161
+
162
+ @cur = md[:end]
163
+ end
164
+
165
+ def throw_exception closer
166
+ raise ArgumentError.new(
167
+ "Unclosed block: was expecting #{closer.inspect} " +
168
+ "while processing #{(@input[0, 60] + ' ... ').inspect}" +
169
+ (@prev_statement ?
170
+ " after #{@prev_statement.inspect}" : ""))
171
+ end
172
172
  end#EachSQL
173
173
 
data/lib/each_sql.rb CHANGED
@@ -8,111 +8,119 @@ require 'each_sql/each_sql'
8
8
  # @param[Symbol] The type of the input SQL script. :default, :mysql, and :oracle (or :plsql)
9
9
  # @return[EachSQL] Enumerable
10
10
  def EachSQL input, type = :default
11
- EachSQL.new(input, EachSQL::Defaults[type])
11
+ esql = EachSQL.new(input, EachSQL::Defaults[type])
12
+
13
+ if block_given?
14
+ esql.each do |sql|
15
+ yield sql
16
+ end
17
+ else
18
+ esql
19
+ end
12
20
  end
13
21
 
14
22
  class EachSQL
15
- # EachSQL::Default Hash is a set of pre-defined parsing rules
16
- # - :default: Default parsing rules for vendor-independent SQL scripts
17
- # - :mysql: Parsing rules for MySQL scripts. Understands `delimiter' statements.
18
- # - :oracle: Parsing rules for Oracle scripts. Removes trailing slashes after begin-end blocks.
19
- Defaults = {
20
- :default => {
21
- :delimiter => /;+/,
22
- :blocks => {
23
- /`/ => /`/,
24
- /"/ => /"/,
25
- /'/ => /'/,
26
- /\/\*[^+]/ => /\*\//,
27
- /--+/ => $/,
28
- },
29
- :nesting_blocks => {
30
- /\bdeclare.*?;\s*?begin\b/im => /;\s*?end\b/i,
31
- /\bbegin\b/i => /;\s*?end\b/i,
32
- },
33
- :nesting_context => [
34
- /\A\s*(begin|declare|create\b[^;]+?\b(procedure|function|trigger|package))\b/im
35
- ],
36
- :callbacks => {},
37
- :ignore => [],
38
- :replace => {},
39
- # Let's assume we don't change delimiters within usual sql scripts
40
- :strip_delimiter => lambda { |obj, stmt| stmt.sub(/\A;+/, '').sub(/;+\Z/, '') }
41
- },
23
+ # EachSQL::Default Hash is a set of pre-defined parsing rules
24
+ # - :default: Default parsing rules for vendor-independent SQL scripts
25
+ # - :mysql: Parsing rules for MySQL scripts. Understands `delimiter' statements.
26
+ # - :oracle: Parsing rules for Oracle scripts. Removes trailing slashes after begin-end blocks.
27
+ Defaults = {
28
+ :default => {
29
+ :delimiter => /;+/,
30
+ :blocks => {
31
+ /`/ => /`/,
32
+ /"/ => /"/,
33
+ /'/ => /'/,
34
+ /\/\*[^+]/ => /\*\//,
35
+ /--+/ => $/,
36
+ },
37
+ :nesting_blocks => {
38
+ /\bdeclare.*?;\s*?begin\b/im => /;\s*?end\b/i,
39
+ /\bbegin\b/i => /;\s*?end\b/i,
40
+ },
41
+ :nesting_context => [
42
+ /\A\s*(begin|declare|create\b[^;]+?\b(procedure|function|trigger|package))\b/im
43
+ ],
44
+ :callbacks => {},
45
+ :ignore => [],
46
+ :replace => {},
47
+ # Let's assume we don't change delimiters within usual sql scripts
48
+ :strip_delimiter => lambda { |obj, stmt| stmt.sub(/\A;+/, '').sub(/;+\Z/, '') }
49
+ },
42
50
 
43
- :mysql => {
44
- :delimiter => /;+|delimiter\s+\S+/i,
45
- :blocks => {
46
- /`/ => /`/,
47
- /"/ => /"/,
48
- /'/ => /'/,
49
- /\/\*[^+]/ => /\*\//,
50
- /--+/ => $/,
51
- },
52
- :nesting_blocks => {
53
- /\bbegin\b/i => /\bend\b/i
54
- },
55
- :nesting_context => [
56
- /\A\s*(begin|create\b[^;]+?\b(procedure|function|trigger))\b/im
57
- ],
58
- # We need to change delimiter on `delimiter' command
59
- :callbacks => {
60
- /^\s*delimiter\s+(\S+)/i => lambda { |obj, stmt, md|
61
- new_delimiter = Regexp.new(Regexp.escape md[1])
62
- obj.delimiter = /(#{new_delimiter})+|delimiter\s+\S+/i
63
- obj.delimiter_string = md[1]
64
- }
65
- },
66
- :ignore => [
67
- /^delimiter\s+\S+$/i
68
- ],
69
- :replace => {},
70
- :strip_delimiter => lambda { |obj, stmt|
71
- stmt.gsub(/(#{Regexp.escape(obj.delimiter_string || ';')})+\Z/, '')
72
- }
73
- },
51
+ :mysql => {
52
+ :delimiter => /;+|delimiter\s+\S+/i,
53
+ :blocks => {
54
+ /`/ => /`/,
55
+ /"/ => /"/,
56
+ /'/ => /'/,
57
+ /\/\*[^+]/ => /\*\//,
58
+ /--+/ => $/,
59
+ },
60
+ :nesting_blocks => {
61
+ /\bbegin\b/i => /\bend\b/i
62
+ },
63
+ :nesting_context => [
64
+ /\A\s*(begin|create\b[^;]+?\b(procedure|function|trigger))\b/im
65
+ ],
66
+ # We need to change delimiter on `delimiter' command
67
+ :callbacks => {
68
+ /^\s*delimiter\s+(\S+)/i => lambda { |obj, stmt, md|
69
+ new_delimiter = Regexp.new(Regexp.escape md[1])
70
+ obj.delimiter = /(#{new_delimiter})+|delimiter\s+\S+/i
71
+ obj.delimiter_string = md[1]
72
+ }
73
+ },
74
+ :ignore => [
75
+ /^delimiter\s+\S+$/i
76
+ ],
77
+ :replace => {},
78
+ :strip_delimiter => lambda { |obj, stmt|
79
+ stmt.gsub(/(#{Regexp.escape(obj.delimiter_string || ';')})+\Z/, '')
80
+ }
81
+ },
74
82
 
75
- :oracle => {
76
- :delimiter => /;+/,
77
- :blocks => {
78
- /`/ => /`/,
79
- /"/ => /"/,
80
- /'/ => /'/,
81
- /\/\*[^+]/ => /\*\//,
82
- /--+/ => $/,
83
- },
84
- :nesting_blocks => {
85
- /\bbegin\b/i => /\bend\b/i,
86
- /\bdeclare.*?;\s*?begin\b/im => {
87
- :closer => %r{;\s*/}m,
88
- # Stops immediately
89
- :pop => true
90
- },
91
- /\bcreate[^;]+?\b(procedure|function|trigger|package)\b/im => {
92
- :closer => %r{;\s*/}m,
93
- # Stops immediately
94
- :pop => true
95
- }
96
- },
97
- :nesting_context => [
98
- /\A\s*(\/\s*)*(begin|declare|create\b[^;]+?\b(procedure|function|trigger|package))\b/im
99
- ],
100
- :callbacks => {
101
- /\Abegin\b/ => lambda { |obj, stmt, md|
102
- # Oracle needs this
103
- stmt << ';' if stmt !~ /;\Z/
104
- }
105
- },
106
- :ignore => [],
107
- :replace => { %r[\A/] => '' },
108
- :strip_delimiter => lambda { |obj, stmt|
109
- stmt.gsub(/(#{stmt =~ /;\s*\// ? '/' : ';'})+\Z/, '')
110
- }
111
- }
112
- }
113
- Defaults[:plsql] = Defaults[:oracle] # alias
83
+ :oracle => {
84
+ :delimiter => /;+/,
85
+ :blocks => {
86
+ /`/ => /`/,
87
+ /"/ => /"/,
88
+ /'/ => /'/,
89
+ /\/\*[^+]/ => /\*\//,
90
+ /--+/ => $/,
91
+ },
92
+ :nesting_blocks => {
93
+ /\bbegin\b/i => /\bend\b/i,
94
+ /\bdeclare.*?;\s*?begin\b/im => {
95
+ :closer => %r{;\s*/}m,
96
+ # Stops immediately
97
+ :pop => true
98
+ },
99
+ /\bcreate[^;]+?\b(procedure|function|trigger|package)\b/im => {
100
+ :closer => %r{;\s*/}m,
101
+ # Stops immediately
102
+ :pop => true
103
+ }
104
+ },
105
+ :nesting_context => [
106
+ /\A\s*(\/\s*)*(begin|declare|create\b[^;]+?\b(procedure|function|trigger|package))\b/im
107
+ ],
108
+ :callbacks => {
109
+ /\Abegin\b/ => lambda { |obj, stmt, md|
110
+ # Oracle needs this
111
+ stmt << ';' if stmt !~ /;\Z/
112
+ }
113
+ },
114
+ :ignore => [],
115
+ :replace => { %r[\A/] => '' },
116
+ :strip_delimiter => lambda { |obj, stmt|
117
+ stmt.gsub(/(#{stmt =~ /;\s*\// ? '/' : ';'})+\Z/, '')
118
+ }
119
+ }
120
+ }
121
+ Defaults[:plsql] = Defaults[:oracle] # alias
114
122
 
115
- # Freeze the Hash
116
- Defaults.freeze
123
+ # Freeze the Hash
124
+ Defaults.freeze
117
125
  end
118
126
 
@@ -251,6 +251,15 @@ select
251
251
  EachSQL(input).each do |sql|
252
252
  assert false, 'Should not enumerate'
253
253
  end
254
+
255
+ EachSQL(input) do |sql|
256
+ assert false, 'Should not enumerate'
257
+ end
258
+
259
+ # Directly pass block
260
+ EachSQL(input) do |sql|
261
+ assert false, 'Should not enumerate'
262
+ end
254
263
  assert true, 'No error expected'
255
264
  end
256
265
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: each_sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-04 00:00:00.000000000Z
12
+ date: 2011-09-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &2154603460 !ruby/object:Gem::Requirement
16
+ requirement: &2158654040 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2154603460
24
+ version_requirements: *2158654040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: jeweler
27
- requirement: &2154602960 !ruby/object:Gem::Requirement
27
+ requirement: &2158648740 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.6.2
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2154602960
35
+ version_requirements: *2158648740
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rcov
38
- requirement: &2154602480 !ruby/object:Gem::Requirement
38
+ requirement: &2158647840 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,21 +43,21 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2154602480
46
+ version_requirements: *2158647840
47
47
  description: Enumerate each SQL statement in SQL scripts.
48
48
  email: junegunn.c@gmail.com
49
49
  executables: []
50
50
  extensions: []
51
51
  extra_rdoc_files:
52
52
  - LICENSE.txt
53
- - README.rdoc
53
+ - README.markdown
54
54
  files:
55
55
  - .document
56
- - CHANGELOG.rdoc
56
+ - CHANGELOG.markdown
57
57
  - Gemfile
58
58
  - Gemfile.lock
59
59
  - LICENSE.txt
60
- - README.rdoc
60
+ - README.markdown
61
61
  - Rakefile
62
62
  - VERSION
63
63
  - each_sql.gemspec
@@ -81,7 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
81
  version: '0'
82
82
  segments:
83
83
  - 0
84
- hash: -2701967104175695105
84
+ hash: -794086544638494383
85
85
  required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  none: false
87
87
  requirements:
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  version: '0'
91
91
  requirements: []
92
92
  rubyforge_project:
93
- rubygems_version: 1.8.5
93
+ rubygems_version: 1.8.6
94
94
  signing_key:
95
95
  specification_version: 3
96
96
  summary: Enumerate each SQL statement in SQL scripts.