Dex 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,59 @@
1
+
2
+
3
+ module Kernel
4
+
5
+ private
6
+
7
+ def current_dex
8
+ dex = if instance_variable_defined?(:@dex)
9
+ @dex
10
+ end
11
+ dex || Dex
12
+ end
13
+
14
+ def rollback sequel = nil
15
+ (sequel || current_dex ).db.transaction(:rollback=>:always) {
16
+ yield
17
+ }
18
+ end
19
+
20
+ def rollback! sequel = nil
21
+ (sequel || current_dex ).table.delete
22
+ yield
23
+ end
24
+
25
+ def new_dex db = nil
26
+ @new_dex ||= Class.new { include Dex::DSL }
27
+ dex = @new_dex.new
28
+
29
+ if db
30
+ dex.db(db[':'] ? db : File.join("/tmp", db) )
31
+ end
32
+
33
+ dex
34
+ end
35
+
36
+ def new_exception name = nil
37
+ @excep_counter ||= 0
38
+ name ||= "Error: #{(@excep_counter+=1)}"
39
+ err = nil
40
+ begin
41
+ raise ArgumentError, name
42
+ rescue Object => e
43
+ err = e
44
+ end
45
+ err
46
+ end
47
+
48
+ def insert_exceptions n
49
+ rollback! {
50
+ ids = []
51
+ errs = [0,1,2].map { |i|
52
+ ids << current_dex.insert(e=except)
53
+ e
54
+ }
55
+ yield ids, errs
56
+ }
57
+ end
58
+
59
+ end # === Kernel
@@ -1,3 +1,3 @@
1
1
  class Dex
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -19,45 +19,16 @@ require 'Bacon_Colored'
19
19
  require 'pry'
20
20
  require 'Exit_0'
21
21
  require 'Dex'
22
+ require 'Dex/testing'
22
23
 
23
24
  Dex.db "/tmp/dex.db"
24
25
 
25
26
  def dex
26
- Dex
27
- end
28
-
29
- def new_dex db = nil
30
- @t ||= Class.new { include Dex::DSL }
31
- dex = @t.new
32
- if db
33
- dex.db(db[':'] ? db : File.join("/tmp", db) )
34
- end
35
-
36
- dex
27
+ @dex ||= Dex
37
28
  end
38
29
 
39
30
  def except name = nil
40
- @counter ||= 0
41
- name ||= "Error: #{(@counter+=1)}"
42
- err = nil
43
- begin
44
- raise ArgumentError, name
45
- rescue Object => e
46
- err = e
47
- end
48
- err
49
- end
50
-
51
- def rollback sequel = nil
52
- (sequel || dex).db.transaction(:rollback=>:always) {
53
- yield
54
- }
55
- end
56
-
57
- def rollback!
58
- # Dex.db.rollback(:rollback=>:always) {
59
- dex.table.delete
60
- yield
31
+ new_exception name
61
32
  end
62
33
 
63
34
  def bin cmd = ""
@@ -72,15 +43,8 @@ def bin cmd = ""
72
43
  o
73
44
  end
74
45
 
75
- def insert_excepts n
76
- rollback! {
77
- ids = []
78
- errs = [0,1,2].map { |i|
79
- ids << Dex.insert(e=except)
80
- e
81
- }
82
- yield ids, errs
83
- }
46
+ def insert_excepts n, &blok
47
+ insert_exceptions( n, &blok )
84
48
  end
85
49
 
86
50
  def last dex
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Dex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -219,6 +219,7 @@ files:
219
219
  - bin/Dex
220
220
  - db.db
221
221
  - lib/Dex.rb
222
+ - lib/Dex/testing.rb
222
223
  - lib/Dex/version.rb
223
224
  - spec/Dex.rb
224
225
  - spec/bin.rb