i_dig_sql 0.1.1 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ae4c695ed603413f388c21a16a29f566900b39b
4
- data.tar.gz: 25cb2010433d132f33a3139a33d0e37469dd121a
3
+ metadata.gz: 5c3f4ef668f82b48eec51d0df59388fd5e8fa98d
4
+ data.tar.gz: 25e21fb88208f4d9fdadf7a7cead463d2a0fb17a
5
5
  SHA512:
6
- metadata.gz: 7461f1a40db3b2ade971005bf6295efa1957c5c955aced4574d0854cf36fdbb56da6456c0bbfa658b61ded80c15ef57c3d665642590cd0dd1273d71eb18095b5
7
- data.tar.gz: ba10c377579ed13fd6d9e4a525f8b324f824b23e5e6120e4a166afa9ef5943833e6e096f088e896d9ae6401b9b68c69e8c650b00a19bb9b552571418981dfe49
6
+ metadata.gz: e889e9ec8ccb723c62f3cd8cecbe2450bc228336763c6eb27b13ae8acb4c8bb788cbf5a4cbf7fbd00654c14dfdd073aeb84aa2453a839479f613c1f464e5a3ef
7
+ data.tar.gz: 76929d84b06a279b22572a0f0a056c6ebb509eb5224000ead47d60b27303d6393241d2c27d10f76be19cd9dd462f57bac3fc54d60f0536f5f21aa8d79863b55e
data/README.md CHANGED
@@ -1,23 +1,55 @@
1
1
  # I\_Dig\_Sql
2
2
 
3
- My way of generating SQL using Ruby.
3
+ My way of managing SQL fragments using Ruby.
4
4
 
5
5
  # Warning:
6
6
 
7
- Don't use this. Instead, use [Arel](http://github.com/rails/arel).
7
+ You will hate using this.
8
+ Instead, use:
8
9
 
9
- # Another warning:
10
+ * [Arel](http://github.com/rails/arel).
11
+ * K'bam [https://github.com/vilnius-leopold/kbam](https://github.com/vilnius-leopold/kbam)
10
12
 
11
- This is not yet usable.
13
+ # History
12
14
 
13
- ## Usage
15
+ I had trouble maintaining BIG sql queries.
14
16
 
15
- Not coming anytime soon.
17
+ I tried many things.
16
18
 
19
+ The best way (within my preferences)
20
+ was to use sub-queries, CTEs, avoid joins as much as possible,
21
+ and this gem to manage SQL fragments and CTEs.
17
22
 
18
- ## Alternatives:
23
+ Naturally, you would want to use prepared statements, compiled wat-cha-me-call-its,
24
+ functions, views, thing-ma-jig-ers, and other tools available in your RDBMS.
19
25
 
20
- * K'bam [https://github.com/vilnius-leopold/kbam](https://github.com/vilnius-leopold/kbam)
26
+ So this gem is for lazy, stupid people like me.
27
+
28
+ # Usage
29
+
30
+ Please note that none of this is ready yet.
31
+
32
+ ```ruby
33
+
34
+ require 'i_dig_sql'
35
+
36
+ sql = I_Dig_Sql.new
37
+ sql[:HEROES] = "SELECT id FROM hero WHERE id = :PERSON_ID"
38
+ sql[:VILLIANS] = "SELECT id FROM villian WHERE id = :PERSON_ID"
39
+ sql << %^
40
+ SELECT *
41
+ FROM people
42
+ WHERE
43
+ id IN ( {{{ HEROES }}} AND status = :ALIVE)
44
+ OR
45
+ id IN (SELECT ID FROM {{ HEROES }} AND status = :ALIVE)
46
+ OR
47
+ id IN ( {{ * HEROES }} )
48
+ OR
49
+ id IN ( {{ ! VILLIANS }} )
50
+ ^
21
51
 
52
+ sql.to_sql
53
+ ```
22
54
 
23
55
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 1.0.0
data/bin/test CHANGED
@@ -5,6 +5,6 @@
5
5
  set -u -e -o pipefail
6
6
 
7
7
 
8
- bundle exec bacon specs/*
8
+ bundle exec bacon -rpry -ri_dig_sql specs/i_dig_sql.rb "$@"
9
9
 
10
10
 
@@ -0,0 +1,95 @@
1
+
2
+ require 'pry'
3
+ require 'sequel'
4
+ DB = Sequel.mock
5
+
6
+ class Englishy_Sql
7
+
8
+ Duplicate = Class.new RuntimeError
9
+
10
+ def initialize
11
+ @sql = {}
12
+ @vals = {}
13
+ instance_eval(&(Proc.new))
14
+ end # === def initialize
15
+
16
+ def val name, v
17
+ if @vals.has_key?(name) && @vals[name] != v
18
+ fail Duplicate, "Already set w/different value: #{name.inspect}"
19
+ end
20
+ end
21
+
22
+ def screen_name name
23
+ val :SCREEN_NAME, name.to_s.strip.upcase
24
+ sql(:SCREEN_NAME) {
25
+
26
+ any! {
27
+ owner_id.==(:AUDIENCE_ID)
28
+ all {
29
+ no_block
30
+ any! {
31
+ WORLD!
32
+ allowed
33
+ }
34
+ }
35
+ } # === any
36
+
37
+ one!
38
+ } # === sql
39
+ end
40
+
41
+ def post
42
+ @sql = @sql.where(:id=> DB[:post].select(:id) )
43
+ end # === def post
44
+
45
+ def comments
46
+ @sql = @sql.or(:parent_id=>DB[:comment].select(:id))
47
+ end
48
+
49
+ def sql *args
50
+ case
51
+ when args.empty?
52
+ @sql.sql
53
+
54
+ when args.size == 2
55
+ name, v = args
56
+ is_dup = @sql.has_key?(name) && @sql[name] != v
57
+ fail Duplicate, "Already set w/different value: #{name.inspect}" if is_dup
58
+
59
+ else
60
+ fail ArgumentError, "Unknown args: #{args.inspect}"
61
+
62
+ end # === case
63
+ end
64
+
65
+ end # === Englishy_Sql
66
+
67
+
68
+ puts(Englishy_Sql.new {
69
+ table(:computer) {
70
+ as(:comments)
71
+ any! {
72
+ is_owner
73
+ }
74
+ }
75
+ }.sql)
76
+
77
+ SELECT *
78
+ FROM screen_name
79
+ WHERE
80
+ owner_id = :AUDIENCE_ID
81
+ OR
82
+ (
83
+ :AUDIENCE_ID NOT IN (BLOCKED)
84
+ AND
85
+ ( privacy = :WORLD
86
+ OR
87
+ (
88
+ privacy = :PROTECTED
89
+ AND
90
+ :AUDIENCE_ID IN (
91
+ ALLOWED
92
+ )
93
+ )
94
+ )
95
+ )
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.license = "MIT"
18
18
 
19
19
  spec.files = `git ls-files -z`.split("\x0")
20
- spec.executables = spec.files.grep("bin/#{spec.name}")
20
+ spec.executables = spec.files.grep("bin/#{spec.name}") { |f| File.basename(f) }
21
21
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
22
  spec.require_paths = ["lib"]
23
23
 
@@ -1,136 +1,113 @@
1
1
 
2
2
  class I_Dig_Sql
3
3
 
4
- Only_One_Where = Class.new(RuntimeError)
4
+ include Enumerable
5
+
6
+ Duplicate = Class.new RuntimeError
5
7
 
6
8
  class << self
7
9
  end # === class self ===
8
10
 
9
- def initialize sql = nil, *args
10
- @withs = []
11
- @tags_for_withs = {}
12
- @select = nil
13
- @as = nil
14
- @unions = []
15
- @sql = sql
16
- @args = args
17
- yield self if block_given?
18
- end
19
-
20
- def args
21
- @args
22
- end
23
- protected :args
11
+ class H < Hash
24
12
 
25
- def AS o = :return
26
- if o == :return
27
- return @as if @as
28
- raise "@as not set"
13
+ def [] name
14
+ fail ArgumentError, "Unknown key: #{k.inspect}" unless has_key?(name)
15
+ super
29
16
  end
30
17
 
31
- @as = o
32
- self
33
- end
18
+ def []= name, val
19
+ if has_key?(name) && self[name] != val
20
+ fail ArgumentError, "Key already set: #{name.inspect}"
21
+ end
34
22
 
35
- def WITH o, *args
36
- @withs << o
37
- @tags_for_withs[o] = []
38
- @args.concat(o.args) if o.is_a?(I_Dig_Sql)
39
- @args.concat args
40
- self
41
- end
23
+ super
24
+ end
42
25
 
43
- alias_method :comma, :WITH
26
+ def merge_these *args
27
+ args.each { |h|
28
+ h.each { |k,v|
29
+ self[k] = v
30
+ }
31
+ }
32
+ self
33
+ end
44
34
 
45
- def tag_as name
46
- list = @tags_for_withs[@withs.last]
47
- raise "Last query was not a WITH/cte query" unless list
48
- list.push name
49
- self
50
- end
35
+ end # === class H
51
36
 
52
- def find_tagged name
53
- @tags_for_withs.inject([]) { |memo, (k,v)|
54
- if v.include?(name)
55
- memo << k
56
- end
57
- memo
37
+ attr_reader :sqls, :vars
38
+ def initialize *args
39
+ @digs = args.select { |a|
40
+ a.is_a? I_Dig_Sql
58
41
  }
59
- end
60
42
 
61
- def SELECT str, *args
62
- @select = {:select=>str, :args=>args, :from=>nil, :where=>nil}
43
+ @sqls = H.new
44
+ @vars = H.new
63
45
 
64
- self
65
- end
66
-
67
- def FROM o
68
- @select[:from] = o
46
+ @sqls.merge_these *(@digs.map(&:sqls))
47
+ @vars.merge_these *(@digs.map(&:vars))
69
48
 
70
- self
49
+ @string = args.select { |s| s.is_a? String }.join("\n")
71
50
  end
72
51
 
73
- def WHERE o, *args
52
+ def [] name
53
+ @sqls[name]
54
+ end
74
55
 
75
- if @select[:where]
76
- raise Only_One_Where.new("Multiple use of WHERE: #{@select[:where]} |--| #{o}")
77
- end
56
+ def []= name, val
57
+ @sqls[name] = val
58
+ end
78
59
 
79
- if args.size == 1 && args.first.is_a?(I_Dig_Sql)
80
- sql = args.first.to_sql
81
- o = "#{o} ( #{sql[:sql]} )"
82
- @args.concat sql[:args]
60
+ def each
61
+ if block_given?
62
+ @sqls.each { |k, v| yield k, v }
83
63
  else
84
- @args.concat args
64
+ @sqls.each
85
65
  end
86
-
87
- @select[:where] = o
88
- self
89
66
  end
90
67
 
91
- def UNION o
92
- @unions << o
68
+ def << str
69
+ @string << (
70
+ if @string.empty?
71
+ str
72
+ else
73
+ "\n" << str
74
+ end
75
+ )
76
+ end
93
77
 
94
- self
78
+ def to_pair
79
+ [to_sql, vars]
95
80
  end
96
81
 
97
82
  def to_sql
98
-
99
- if @sql
100
- s = "\n "
101
- s << @sql
102
- else
103
-
104
- s = ""
105
- unless @withs.empty?
106
- s << "\n WITH"
107
- s << @withs.map { |w|
108
- case w
109
- when String
110
- " #{w} "
111
- else
112
- " #{w.AS} AS (#{w.to_sql[:sql]}) "
113
- end
114
- }.join("\n,\n")
115
- end
116
-
117
- s << "\n"
118
-
119
- if @select
120
- s << "\n SELECT #{@select[:select]}"
121
- s << "\n FROM #{@select[:from]}" if @select[:from]
122
- s << "\n WHERE #{@select[:where]}" if @select[:where]
83
+ s = @string.dup
84
+ ctes = []
85
+
86
+ s.gsub!(/\{\{\s?(\!|\*)?\s?([a-zA-Z0-9\_]+)\s?\}\}/) do |match|
87
+ key = $2.to_sym
88
+ case $1
89
+ when "!"
90
+ self[key]
91
+ when "*"
92
+ ctes << key
93
+ "SELECT * FROM #{key}"
94
+ else
95
+ ctes << key
96
+ key
123
97
  end
124
-
125
- end # === if @sql
126
-
127
- if not @unions.empty?
128
- s << "\n UNION #{@unions.map { |sql| sql.to_sql[:sql] }.join "\nUNION\n" }"
129
98
  end
130
99
 
131
- s << "\n"
132
-
133
- {:sql=>s, :args=>@args}
100
+ return s if ctes.empty?
101
+
102
+ %^
103
+ WITH
104
+ #{ctes.map { |k| "#{k} AS (
105
+ #{self[k]}
106
+ )" }.join "
107
+ ,
108
+ "}
109
+ #{s}
110
+ ^
134
111
  end
135
112
 
136
113
  end # === class I_Dig_Sql ===
@@ -1,14 +1,11 @@
1
1
 
2
- require "pry"
3
2
  require "Bacon_Colored"
4
- require "i_dig_sql"
5
- require "i_dig_sql/String"
6
3
 
7
4
  def sql o
8
5
  if o.is_a? String
9
6
  return o.split.join(" ")
10
7
  else
11
- sql(o.to_sql[:sql])
8
+ sql(o.to_sql)
12
9
  end
13
10
  end
14
11
 
@@ -16,218 +13,143 @@ def args o
16
13
  o.to_sql[:args]
17
14
  end
18
15
 
19
- describe ".new" do
20
-
21
- it "returns a I_Dig_Sql if passed a String" do
22
- o = I_Dig_Sql.new("SELECT * FROM some_table")
23
- o.class.should == I_Dig_Sql
24
- end
25
-
26
- end # === describe it runs ===
27
-
28
- describe "#WITH()" do
29
-
30
- it "includes passed String" do
31
- o = I_Dig_Sql.new
32
- o.WITH("some_table AS (SELECT * FROM other_table)")
33
- sql(o).should == sql("WITH some_table AS (SELECT * FROM other_table)")
34
- end
35
-
36
- it "accepts another I_Dig_Sql object" do
37
- other = I_Dig_Sql.new("SELECT * FROM main_table")
38
- .AS('cte1')
39
-
40
- o = I_Dig_Sql.new
41
- .WITH(other)
42
- sql(o).should == sql(%^
43
- WITH cte1 AS ( SELECT * FROM main_table )
16
+ describe :I_Dig_Sql do
17
+
18
+ it "runs the code from README.md" do
19
+ readme = File.read(File.expand_path(File.dirname(__FILE__) + '/../README.md'))
20
+ code = readme[/```ruby([^`]+)```/] && $1
21
+ line = 0
22
+ readme.split("\n").detect { |l| line = line + 1; l['```ruby'] }
23
+ result = eval(code, nil, 'README.md', line)
24
+ sql(result)['WITH HEROES'].should == 'WITH HEROES'
25
+ end # === it
26
+
27
+ it "adds WITH: {{MY_NAME}}" do
28
+ sql = I_Dig_Sql.new
29
+ sql[:MY_HERO] = "SELECT * FROM hero"
30
+ sql[:MY_NAME] = "SELECT * FROM name"
31
+ sql << %^
32
+ {{MY_HERO}}
33
+ {{MY_NAME}}
34
+ ^
35
+ sql(sql).should == sql(%^
36
+ WITH
37
+ MY_HERO AS (
38
+ SELECT * FROM hero
39
+ )
40
+ ,
41
+ MY_NAME AS (
42
+ SELECT * FROM name
43
+ )
44
+ MY_HERO
45
+ MY_NAME
44
46
  ^)
45
47
  end
46
48
 
47
- it "accepts args" do
48
- o = I_Dig_Sql.new
49
- .WITH(" some_table AS (SELECT * FROM other_table WHERE id = ?) ", 1)
50
- args(o).should == [1]
51
- end
52
-
53
- it "merges args from other I_Dig_Sql objects" do
54
- other = I_Dig_Sql.new("SELECT * FROM main_table WHERE i = ?", 1).AS('cte1')
55
-
56
- o = I_Dig_Sql.new
57
- .WITH(other)
58
- args(o).should == [1] end
59
-
60
- end # === describe #WITH() ===
61
-
62
- describe "#comma" do
63
-
64
- it "acts like a WITH statement" do
65
- o = I_Dig_Sql.new
66
- .WITH('cte1 AS ( SELECT * FROM table_1 ) ')
67
- .comma('cte2 AS ( SELECT * FROM table_2 )')
68
-
69
- sql(o).should == sql(%^
70
- WITH
71
- cte1 AS ( SELECT * FROM table_1 )
72
- , cte2 AS ( SELECT * FROM table_2 )
73
- ^)
74
- end
75
-
76
- it "saves args" do
77
- o = I_Dig_Sql.new
78
- .WITH('cte1 AS ( SELECT * FROM table_1 ) ')
79
- .comma('cte2 AS ( SELECT * FROM table_2 WHERE id = ?)', 2)
80
-
81
- args(o).should == [2]
82
- end
83
-
84
- end # === describe #comma ===
85
-
86
- describe "#to_sql" do
87
-
88
- describe ":sql" do
89
-
90
- it "includes both WITH and SELECT statements" do
91
- o = I_Dig_Sql.new
92
- o.WITH("cte AS (SELECT * FROM other_table)")
93
- o.SELECT(" parent_id ")
94
- .FROM("main_table")
95
- sql(o).should == sql(%^
96
- WITH cte AS (SELECT * FROM other_table)
97
- SELECT parent_id
98
- FROM main_table
99
- ^)
100
- end
101
-
102
- end # === describe :sql ===
103
-
104
- describe ":args" do
105
-
106
- it "returns an array of arguments" do
107
- o = I_Dig_Sql.new
108
- .SELECT(" parent_id ")
109
- .FROM("main_table")
110
- .WHERE(" ? = ? AND b = ? ", 1, 2, 3)
111
- args(o).should == [1,2,3]
112
- end
113
-
114
- end # === describe :args ===
115
-
116
-
117
- end # === describe #to_sql ===
118
-
119
- describe "#WHERE" do
120
-
121
- it "merges sql into string if arg is a I_Dig_Sql" do
122
- other = I_Dig_Sql.new.SELECT("*").FROM("other")
123
-
124
- o = I_Dig_Sql.new.SELECT("parent_id")
125
- .FROM("main")
126
- .WHERE("id IN", other)
127
-
128
- sql(o).should == sql(%~
129
- SELECT parent_id
130
- FROM main
131
- WHERE id IN (
132
- SELECT * FROM other
49
+ it "adds WITH: {{ * MY_NAME }}" do
50
+ sql = I_Dig_Sql.new
51
+ sql[:MY_HERO] = "SELECT * FROM hero"
52
+ sql[:MY_NAME] = "SELECT * FROM name"
53
+ sql << %^
54
+ {{ * MY_NAME }}
55
+ {{ * MY_HERO }}
56
+ ^
57
+ sql(sql).should == sql(%^
58
+ WITH
59
+ MY_NAME AS (
60
+ SELECT * FROM name
61
+ ) ,
62
+ MY_HERO AS (
63
+ SELECT * FROM hero
133
64
  )
134
- ~)
135
- end
136
-
137
- it "merges args if arg is a I_Dig_Sql" do
138
- other = I_Dig_Sql.new.SELECT("*").FROM("other")
139
- .WHERE("id = ", 1)
140
-
141
- o = I_Dig_Sql.new.SELECT("parent_id")
142
- .FROM("main")
143
- .WHERE("id IN", other)
144
-
145
- args(o).should == [1]
146
- end
147
-
148
- it "raises exception if used more than once" do
149
- lambda {
150
- I_Dig_Sql.new
151
- .SELECT('*')
152
- .FROM('main')
153
- .WHERE("id = 1")
154
- .WHERE("id = 2")
155
- }.should.raise(I_Dig_Sql::Only_One_Where)
156
- .message.should.match(/Multiple use of WHERE:/)
157
- end
158
-
159
- end # === describe #WHERE ===
160
-
161
-
162
- describe "String#i_dig_sql" do
163
-
164
- it "returns an I_Dig_Sql instance set to String" do
165
- o = "SELECT id FROM my_table".i_dig_sql
166
- sql(o.to_sql[:sql]).should == sql(%^SELECT id FROM my_table^)
167
- end
168
-
169
- end # === describe String ===
170
-
171
-
172
- describe ".tag_as" do
173
-
174
- it "adds tag to tag list of last query" do
175
- o = "SELECT *".i_dig_sql
176
- o.WITH("cte1 AS (SELECT * FROM table_1)")
177
- .tag_as('group 1')
178
- o.WITH("cte2 AS (SELECT * FROM table_2)")
179
- .tag_as('group 1')
180
-
181
- list = o.find_tagged('group 1')
182
- list.size.should == 2
183
- sql(list.first).should == sql("cte1 AS (SELECT * FROM table_1)")
184
- sql(list.last).should == sql("cte2 AS (SELECT * FROM table_2)")
185
- end
186
-
187
- it "raises error if last query was not a WITH/cte" do
188
- o = "SELECT *".i_dig_sql
189
- should.raise(RuntimeError) {
190
- o.tag_as('group 1')
191
- }.message.should.match /Last query was not a WITH\/cte/i
192
- end
193
-
194
- end # === describe .tag_as ===
65
+ SELECT * FROM MY_NAME
66
+ SELECT * FROM MY_HERO
67
+ ^)
68
+ end # === it
69
+
70
+ it "replaces text with content: {{ ! MY_NAME }}" do
71
+ sql = I_Dig_Sql.new
72
+ sql[:MY_HERO] = "SELECT * FROM hero"
73
+ sql << %^
74
+ {{ ! MY_HERO }}
75
+ ^
76
+ sql(sql).should == "SELECT * FROM hero"
77
+ end # === it
78
+
79
+ end # === describe :I_Dig_Sql
80
+
81
+ describe '.new' do
82
+
83
+ it "merges sql values: .new(i_dig_sql)" do
84
+ first = I_Dig_Sql.new
85
+ first[:hero] = "SELECT * FROM hero"
86
+ second = I_Dig_Sql.new(first)
87
+ second[:name] = "SELECT * FROM name"
88
+ second << %^
89
+ {{ ! hero }}
90
+ {{ ! name }}
91
+ ^
92
+ sql(second).should == sql(%^
93
+ SELECT * FROM hero
94
+ SELECT * FROM name
95
+ ^)
96
+ end # === it
195
97
 
196
- describe ".find_tagged" do
98
+ it "combines all Strings" do
99
+ i = I_Dig_Sql.new "SELECT ", " * ", " FROM ", " NAME "
100
+ sql(i).should == sql("SELECT * FROM NAME")
101
+ end # === it
197
102
 
198
- it "returns all WITH/cte querys with tag" do
199
- o = "SELECT *".i_dig_sql
200
- o.WITH("cte1 AS (SELECT * FROM table_1)")
201
- .tag_as('group 1')
202
- o.WITH("cte2 AS (SELECT * FROM table_2)")
203
- .tag_as('group 1')
103
+ end # === describe '.new'
204
104
 
205
- list = o.find_tagged('group 1')
206
- list.size.should == 2
207
- sql(list.first).should == sql("cte1 AS (SELECT * FROM table_1)")
208
- sql(list.last).should == sql("cte2 AS (SELECT * FROM table_2)")
209
- end
210
105
 
211
- it "only returns WITH/cte querys with tags, and no others" do
212
- o = "SELECT *".i_dig_sql
213
- o.WITH("cte1 AS (SELECT * FROM table_1)").tag_as('group 1')
214
- o.WITH("cte2 AS (SELECT * FROM table_2)").tag_as('group 1')
215
- o.WITH("cte3 AS (SELECT * FROM table_3)").tag_as('group 2')
106
+ describe :vars do
216
107
 
217
- list = o.find_tagged('group 1')
218
- list.size.should == 2
219
- sql(list.first).should == sql("cte1 AS (SELECT * FROM table_1)")
220
- sql(list.last).should == sql("cte2 AS (SELECT * FROM table_2)")
221
- end
108
+ it "combines vars from other digs" do
109
+ one = I_Dig_Sql.new
110
+ one.vars[:one] = 1
222
111
 
223
- end # === describe find_tagged ===
112
+ two = I_Dig_Sql.new
113
+ one.vars[:two] = 2
224
114
 
115
+ three = I_Dig_Sql.new
116
+ one.vars[:three] = 3
225
117
 
118
+ dig = I_Dig_Sql.new one, two, three
119
+ dig.vars[:four] = 4
226
120
 
121
+ dig.vars.should == {
122
+ four: 4,
123
+ three: 3,
124
+ two: 2,
125
+ one: 1
126
+ }
127
+ end # === it
227
128
 
129
+ it "fails w/Duplicate if other digs have the same var name" do
130
+ should.raise(ArgumentError) {
131
+ one = I_Dig_Sql.new
132
+ one.vars[:two] = 2
228
133
 
134
+ i = I_Dig_Sql.new one
135
+ i.vars[:two] = 3
136
+ i.vars
137
+ }.message.should.match /Key already set: :two/
138
+ end # === it
229
139
 
140
+ end # === describe :vars
230
141
 
231
142
 
143
+ describe :to_pair do
232
144
 
145
+ it "returns an Array: [String, Hash]" do
146
+ i = I_Dig_Sql.new <<-EOF
147
+ SELECT * FROM new
148
+ EOF
149
+ i.vars[:one] = 2
150
+ sql, vars = i.to_pair
151
+ sql(sql).should == sql("SELECT * FROM new")
152
+ vars.should == {one: 2}
153
+ end # === it
233
154
 
155
+ end # === describe :to_pair
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i_dig_sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - da99
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-22 00:00:00.000000000 Z
11
+ date: 2015-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -82,6 +82,7 @@ files:
82
82
  - Rakefile
83
83
  - VERSION
84
84
  - bin/test
85
+ - englishy_sql.rb
85
86
  - i_dig_sql.gemspec
86
87
  - lib/i_dig_sql.rb
87
88
  - lib/i_dig_sql/String.rb