each_sql 0.3.1 → 0.4.0

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/CHANGELOG.markdown CHANGED
@@ -1,10 +1,13 @@
1
+ ### 0.4.0 / 2013/05/15
2
+ * Returns an Enumerator instead of an Array when block is not given
3
+
1
4
  ### 0.3.1 / 2012/03/15
2
5
  * Bug fix: `begin transaction`
3
6
  * `EachSQL#clear`
4
7
 
5
8
  ### 0.3.0 / 2012/03/10
6
9
  * Internal implementation revised.
7
- * At first, I thought this would be trivial,
10
+ * At first, I thought this would be trivial,
8
11
  that I didn't need a real parser for just breaking SQL scripts
9
12
  into individual executable units.
10
13
  I couldn't be more wrong. Codes for handling a few exceptional cases
data/README.markdown CHANGED
@@ -1,7 +1,7 @@
1
1
  each_sql
2
2
  ========
3
3
 
4
- Enumerate executable blocks in the given SQL script.
4
+ Enumerate executable blocks in the given SQL script. (experimental)
5
5
 
6
6
  Installation
7
7
  ------------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.0
@@ -68,6 +68,8 @@ class EachSQL
68
68
  # @yield [String]
69
69
  # @return [NilClass]
70
70
  def each
71
+ return enum_for(:each) unless block_given?
72
+
71
73
  result = shift
72
74
  sqls = (result[:sqls] + result[:leftover]).
73
75
  map { |sql| strip_sql(sql) }.
@@ -19,7 +19,7 @@ module Parser
19
19
 
20
20
  Citrus.eval erb.result(binding)
21
21
 
22
- @@parser[[type, delimiter]] =
22
+ @@parser[[type, delimiter]] =
23
23
  case type
24
24
  when :default
25
25
  eval "EachSQL::Parser::Default#{suffix}"
data/lib/each_sql.rb CHANGED
@@ -9,10 +9,11 @@ require 'each_sql/parser'
9
9
  # @param[String] input Input script.
10
10
  # @param[Symbol] The type of the input SQL script. :default, :mysql, and :oracle (or :plsql)
11
11
  # @yield[String] Executable SQL statement or block.
12
- # @return[Array] Array of executable SQL statements and blocks.
12
+ # @return[Enumerator] Enumerator of executable SQL statements and blocks.
13
13
  def EachSQL input, type = :default
14
+ return enum_for(:EachSQL, input, type) unless block_given?
15
+
14
16
  esql = EachSQL.new(type)
15
- ret = []
16
17
  result = {}
17
18
 
18
19
  process = lambda {
@@ -20,11 +21,7 @@ def EachSQL input, type = :default
20
21
  result = esql.shift
21
22
  sqls = result[:sqls]
22
23
  sqls.each do |sql|
23
- if block_given?
24
- yield sql
25
- else
26
- ret << sql
27
- end
24
+ yield sql
28
25
  end
29
26
  }
30
27
 
@@ -50,13 +47,7 @@ def EachSQL input, type = :default
50
47
  end
51
48
 
52
49
  if sql = result[:leftover]
53
- if block_given?
54
- yield sql
55
- else
56
- ret << sql
57
- end
50
+ yield sql
58
51
  end
59
-
60
- ret
61
52
  end
62
53
 
@@ -43,7 +43,7 @@ class TestEachSql < Test::Unit::TestCase
43
43
  def test_parser_cache
44
44
  [:default, :mysql, :oracle, :postgres].each do |typ|
45
45
  %w[';', '$$', '//'].each do |delim|
46
- arr =
46
+ arr =
47
47
  10.times.map {
48
48
  EachSQL::Parser.parser_for typ, delim
49
49
  }
@@ -88,7 +88,8 @@ class TestEachSql < Test::Unit::TestCase
88
88
  end
89
89
  assert_equal data['each'].length, cnt
90
90
  assert_equal cnt, EachSQL(script, typ).to_a.length
91
- assert_equal EachSQL(script, typ).to_a, EachSQL(script, typ).map { |e| e }
91
+ assert_equal EachSQL(script, typ).to_a,
92
+ EachSQL(script, typ).each.each.take_while { true }.map { |e| e }
92
93
  end
93
94
  end
94
95
  end
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.3.1
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-15 00:00:00.000000000 Z
12
+ date: 2013-05-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: citrus
@@ -135,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  segments:
137
137
  - 0
138
- hash: 4467039074985070644
138
+ hash: 3224767987852485011
139
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  none: false
141
141
  requirements:
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  version: '0'
145
145
  requirements: []
146
146
  rubyforge_project:
147
- rubygems_version: 1.8.18
147
+ rubygems_version: 1.8.25
148
148
  signing_key:
149
149
  specification_version: 3
150
150
  summary: Enumerate each SQL statement in SQL scripts.