turntables 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3b7cb827f0bb39e3cc31e2ead6a8d271e3068bf
4
- data.tar.gz: bd4970ab7927b33a741e17b331056d03b81e388d
3
+ metadata.gz: 98ee4536b7ea7b58f5416c33fa8bdb4cde1e8eaa
4
+ data.tar.gz: 097c92953b752ab4996cf0a8ed5a12e72a7ba6fb
5
5
  SHA512:
6
- metadata.gz: 09104fc43b8e05ca2a45798b0d3742c3f70189e95cfcbfa4779e2dd8ed42b18b49b4a2e9ffe03055133523b53dff4b9d81f258048ad15eadd8986753fd72725e
7
- data.tar.gz: 32404ef39e95bb8dd4a61e1f1faa5add76b315b9a9607c146615e29b78a9fb8adb525f795e3145d793dd9916ff6fc7d030236e39afbcffb3d4f2d3af0aa619ad
6
+ metadata.gz: ef7a8a25ade7dc70efbd2fdcf466df097702d4a758ad0fbe21a739c70b1f1d9f24fb6db8ba01aac93f26732257a81c823392977df9b0cc9b3e83d69d1508cd13
7
+ data.tar.gz: acfc9fc10852499677a733e5265ec4dd6de00871dbcc84d4c1588b0ac81d57ab902081fe7baac356fac0995abb8248522244310758908ee2867d69e73933d7a5
@@ -1,3 +1,9 @@
1
+ === 1.0.1 / Oct 11 2013
2
+
3
+ * Small fixes
4
+ * Output to stderr on errors
5
+ * Output the location of the malformed dir, if there are problems
6
+
1
7
  === 1.0.0 / 2013-07-03
2
8
 
3
9
  * Initial release:
@@ -6,9 +6,15 @@
6
6
 
7
7
  == Description
8
8
 
9
- This is not really ready, but putting it out there because I actually need it
10
- for something else I'm working on. If you can give a hand it will be very
11
- appreciated (contact me).
9
+ You can use this in order to manage your (simple) sqlite3 databases. I wanted
10
+ something light and simple in order to help on some development I'm doing on
11
+ my own. I found myself repeating a pattern most of this time, and decided to
12
+ bring an end to it by writing this gem.
13
+
14
+ The concept is inspired by the Rails migrations, and something else I've seen
15
+ in some Bukkit code. Ultimately the functionality of this library can be
16
+ further abstracted, and made more modular in the future, as well as translated
17
+ in other languages. But alas our mortal time is limited.
12
18
 
13
19
  == Features
14
20
 
@@ -115,6 +121,10 @@ The monolithic transactions should be a combinations of all the versions, up to
115
121
  the one it denotes. In other words, version 4 would be the combination of all
116
122
  previous ones including itself {1.sql, 2.sql, 3.sql, 4.sql}.
117
123
 
124
+ If you require it, you can also query the version histories in your
125
+ application. To do so, you just need to use the VersionHistory active record,
126
+ in the turntables gem.
127
+
118
128
  == Requirements
119
129
 
120
130
  * I've tested this with Ruby Versions = {2.0, 1.9.3}, though you should not
@@ -15,8 +15,7 @@ class DbRegistry
15
15
  # TODO we need to be able to set this somehow differently - applications
16
16
  # might require to name their database with their own specific name.
17
17
  def initialize(dbname="default.db")
18
- @handle = SQLite3::Database.new(dbname)
19
- @name = dbname
18
+ @name = dbname
20
19
  end
21
20
 
22
21
  # Execute (any sort) of sql
@@ -28,12 +27,9 @@ class DbRegistry
28
27
  # DbRegistry.instance.execute(sql,"jon","doe")
29
28
  # @return sql data
30
29
  def execute(*sql)
31
- @handle.execute(*sql)
30
+ get_handle.execute(*sql)
32
31
  rescue => ex
33
- puts ex.message
34
- puts ex.backtrace
35
- puts "Offending sql: "
36
- puts sql
32
+ print_exception ex
37
33
  end
38
34
 
39
35
  # For special queries that may contain multiple statements. For example a
@@ -42,19 +38,16 @@ class DbRegistry
42
38
  # tables in sequence.
43
39
  # @param sql is the sql that contains multiple statements
44
40
  def execute_batch(sql)
45
- @handle.execute_batch(sql)
41
+ get_handle.execute_batch(sql)
46
42
  rescue => ex
47
- puts ex.message
48
- puts ex.backtrace
49
- puts "Offending sql: "
50
- puts sql
43
+ print_exception ex
51
44
  end
52
45
 
53
46
  # Check if a table exists in the database
54
47
  # @param name is the name of the table to check if exists
55
48
  # @return true if table exists, false if not
56
49
  def table_exists?(name)
57
- val = @handle.execute(ExistsSql, "table", name)
50
+ val = get_handle.execute(ExistsSql, "table", name)
58
51
  1 == val.flatten[0]
59
52
  end
60
53
 
@@ -62,14 +55,14 @@ class DbRegistry
62
55
  # @warn This is mainly here for the rspec testing, and should not be used
63
56
  # unless you really know what you're doing.
64
57
  def close!
65
- @handle.close unless @handle.closed?
58
+ get_handle.close unless get_handle.closed?
66
59
  end
67
60
 
68
61
  # Open the database, with the name given previously
69
62
  # @warn This is mainly here for the rspec testing, and should not be used
70
63
  # unless you really know what you're doing.
71
64
  def open!
72
- @handle = SQLite3::Database.new(@name) if @handle.closed?
65
+ @handle = SQLite3::Database.new(@name) if get_handle.closed?
73
66
  end
74
67
 
75
68
  # The database name
@@ -78,6 +71,18 @@ class DbRegistry
78
71
  private
79
72
  # Other classes should not use the database handle directly
80
73
  attr :handle
74
+
75
+ def get_handle
76
+ @handle = SQLite3::Database.new(@name) if @handle.nil?
77
+ @handle end
78
+
79
+ def print_exception(ex)
80
+ $stderr.puts ex.message
81
+ $stderr.puts ex.backtrace
82
+ $stderr.puts "Offending sql: "
83
+ $stderr.puts sql
84
+ end
85
+
81
86
  end
82
87
  end
83
88
 
@@ -20,8 +20,8 @@ class Turntable
20
20
 
21
21
  # Make the repository at a specific location instead of default.
22
22
  def make_at!(location)
23
- DbRegistry.instance.close!
24
23
  DbRegistry.instance.name = location
24
+ DbRegistry.instance.close!
25
25
  DbRegistry.instance.open!
26
26
  make!
27
27
  end
@@ -29,7 +29,8 @@ class Turntable
29
29
  # Create the tables by going through each revision
30
30
  def make!
31
31
  if @repository.malformed?
32
- raise TurntableException, "The directory structure is malformed."
32
+ raise TurntableException,
33
+ "The directory structure at #{@repository.relative_dir} is malformed."
33
34
  else
34
35
  @repository.make!
35
36
  end
@@ -1,4 +1,4 @@
1
1
  module Turntables
2
2
  # turntables version
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.3"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turntables
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - psyomn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-26 00:00:00.000000000 Z
11
+ date: 2013-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler