disposable_db 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.authors = ['Keith Larrimore']
11
11
  s.homepage = 'https://github.com/klarrimore/disposable_db'
12
12
  s.date = Date.today.to_s
13
- s.summary = 'A utility that makes it easy to create "on-the-fly databases"'
13
+ s.summary = 'A utility that makes it easy to create "on-the-fly databases"'
14
14
  s.description = 'A utility that makes it easy to create "on-the-fly databases"'
15
15
 
16
16
  #s.rubyforge_project = "disposable_db"
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.files = `git ls-files`.split("\n")
19
19
  s.test_files = `git ls-files -- {test,spec,bench,features}/*`.split("\n")
20
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
- s.require_paths = ["lib"]
21
+ s.require_paths = ['lib']
22
22
 
23
23
  # specify any dependencies here; for example:
24
24
  s.add_development_dependency 'rspec', ['>= 2.9.0']
@@ -8,17 +8,25 @@ module DisposableDB
8
8
 
9
9
  def create_table!(table_template)
10
10
  @connection.create_table! table_template.name.to_sym do
11
+ primary_key table_template.primary_key if table_template.primary_key
11
12
  table_template.columns.each do |column|
12
13
  column column.name.to_sym, column.type
13
14
  end
15
+ table_template.indexes.each do |idx|
16
+ index idx.to_sym
17
+ end
14
18
  end
15
19
  end
16
20
 
17
21
  def create_table(table_template)
18
22
  @connection.create_table? table_template.name.to_sym do
23
+ primary_key table_template.primary_key if table_template.primary_key
19
24
  table_template.columns.each do |column|
20
25
  column column.name.to_sym, column.type
21
26
  end
27
+ table_template.indexes.each do |idx|
28
+ index idx.to_sym
29
+ end
22
30
  end
23
31
  end
24
32
 
@@ -27,4 +35,4 @@ module DisposableDB
27
35
  end
28
36
 
29
37
  end
30
- end
38
+ end
@@ -1,16 +1,25 @@
1
1
  module DisposableDB
2
2
  class TableTemplate
3
- attr_accessor :name, :columns
3
+ attr_accessor :name, :columns, :primary_key
4
4
 
5
5
  def initialize(name, columns = [])
6
6
  @name = name
7
7
  @columns = columns
8
+ @indexes = indexes
8
9
  end
9
10
 
10
11
  def add_column(column)
11
12
  @columns << column
12
13
  end
13
14
 
15
+ def set_primary_key(pk)
16
+ @primary_key = pk
17
+ end
18
+
19
+ def indexes
20
+ @columns.select{ |c| c.indexed == true }.collect{ |c| c.name }
21
+ end
22
+
14
23
  class Column
15
24
  attr_accessor :name, :type, :indexed
16
25
 
@@ -31,4 +40,4 @@ module DisposableDB
31
40
  end
32
41
 
33
42
  end
34
- end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module DisposableDB
2
- VERSION = '0.0.2' unless defined? DisposableDB::VERSION
2
+ VERSION = '0.0.3' unless defined? DisposableDB::VERSION
3
3
  end
@@ -20,5 +20,16 @@ describe Database do
20
20
  d.create_table tt
21
21
  d.table_exists?(tt.name).should be_true
22
22
  end
23
+
24
+ it "can create table with primary_key" do
25
+ tt = TableTemplate.new('foo2', [TableTemplate::Column.new('t1', Integer)])
26
+ tt.set_primary_key :id
27
+
28
+ d = Database.new
29
+ d.table_exists?(tt.name).should be_false
30
+ d.create_table tt
31
+ d.table_exists?(tt.name).should be_true
32
+ d.connection[:foo2].columns.include?(:id).should be_true
33
+ end
23
34
 
24
35
  end
@@ -19,5 +19,13 @@ describe TableTemplate do
19
19
 
20
20
  tt.columns.length.should == columns.length
21
21
  end
22
+
23
+ it "can set primary key" do
24
+ tt = TableTemplate.new('foo')
25
+
26
+ tt.set_primary_key :id
27
+
28
+ tt.primary_key == :id
29
+ end
22
30
 
23
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: disposable_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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: 2012-03-26 00:00:00.000000000Z
12
+ date: 2012-03-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &88875350 !ruby/object:Gem::Requirement
16
+ requirement: &7944580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.9.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *88875350
24
+ version_requirements: *7944580
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &88875080 !ruby/object:Gem::Requirement
27
+ requirement: &7943920 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *88875080
35
+ version_requirements: *7943920
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ffaker
38
- requirement: &88863790 !ruby/object:Gem::Requirement
38
+ requirement: &7943020 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.13.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *88863790
46
+ version_requirements: *7943020
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: ruby-prof
49
- requirement: &88863580 !ruby/object:Gem::Requirement
49
+ requirement: &7942140 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *88863580
57
+ version_requirements: *7942140
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sequel
60
- requirement: &88863280 !ruby/object:Gem::Requirement
60
+ requirement: &7940620 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - =
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 3.33.0
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *88863280
68
+ version_requirements: *7940620
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
- requirement: &88863030 !ruby/object:Gem::Requirement
71
+ requirement: &7939500 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *88863030
79
+ version_requirements: *7939500
80
80
  description: A utility that makes it easy to create "on-the-fly databases"
81
81
  email:
82
82
  - keithlarrimore@icehook.com
@@ -116,21 +116,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
116
  - - ! '>='
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
- segments:
120
- - 0
121
- hash: 36076115
122
119
  required_rubygems_version: !ruby/object:Gem::Requirement
123
120
  none: false
124
121
  requirements:
125
122
  - - ! '>='
126
123
  - !ruby/object:Gem::Version
127
124
  version: '0'
128
- segments:
129
- - 0
130
- hash: 36076115
131
125
  requirements: []
132
126
  rubyforge_project:
133
- rubygems_version: 1.8.10
127
+ rubygems_version: 1.8.17
134
128
  signing_key:
135
129
  specification_version: 3
136
130
  summary: A utility that makes it easy to create "on-the-fly databases"