mdb 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/README.md +3 -2
- data/lib/mdb/database.rb +10 -23
- data/lib/mdb/version.rb +1 -1
- data/mdb.gemspec +1 -0
- data/test/data/Example2000.mdb +0 -0
- data/test/data/Example2003.mdb +0 -0
- data/test/data/Protected.mdb +0 -0
- data/test/database_test.rb +17 -0
- data/test/test_helper.rb +1 -0
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e145baf40a7c85a8b744fe0473673c9107f2286
|
4
|
+
data.tar.gz: 121f225d8c3c3fb584c3b0531571a6afa1cb89c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f08fe3139630d3d2dbe76a82123de4c2eec51df9457ffbb44af0b86005f47a6a9a62523e5b8510edc4be39c6ec93e98af0cf1f01c0461496a44153a42e1ff88
|
7
|
+
data.tar.gz: a13524dd57c47525ec1bddd5dfad2dd2e0a5045e87182b07f239930f493a093d26578a21e021bc486ce8f50f467c04efb324bece87213746e2c3103aadb2f872
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.1
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# Mdb
|
2
2
|
|
3
|
-
[![
|
4
|
-
[![Code Climate](https://codeclimate.com/github/
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/mdb.svg)](https://rubygems.org/gems/mdb)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/cph/mdb.svg)](https://codeclimate.com/github/cph/mdb)
|
5
|
+
[![Build Status](https://travis-ci.org/cph/mdb.svg)](https://travis-ci.org/cph/mdb)
|
5
6
|
|
6
7
|
Wraps [mdb-tools](https://github.com/brianb/mdbtools) for reading Microsoft Access databases
|
7
8
|
|
data/lib/mdb/database.rb
CHANGED
@@ -30,21 +30,16 @@ module Mdb
|
|
30
30
|
|
31
31
|
def columns(table)
|
32
32
|
open_csv(table) do |csv|
|
33
|
-
|
34
|
-
unless line || tables.member?(table.to_s)
|
35
|
-
raise TableDoesNotExistError, "#{table.inspect} does not exist in #{file_name.inspect}"
|
36
|
-
end
|
37
|
-
|
38
|
-
(line || []).map(&:to_sym)
|
33
|
+
(csv.readline || []).map(&:to_sym)
|
39
34
|
end
|
40
35
|
end
|
41
36
|
|
42
37
|
|
43
38
|
|
44
|
-
def read_csv(table)
|
45
|
-
|
46
|
-
|
47
|
-
|
39
|
+
def read_csv(table, &block)
|
40
|
+
table = table.to_s
|
41
|
+
raise TableDoesNotExistError, "#{table.inspect} does not exist in #{file_name.inspect}" unless tables.member?(table)
|
42
|
+
execute "mdb-export -D '%F %T' -d #{Shellwords.escape(delimiter)} #{file_name} #{Shellwords.escape(table)}", &block
|
48
43
|
end
|
49
44
|
|
50
45
|
|
@@ -89,21 +84,11 @@ module Mdb
|
|
89
84
|
end
|
90
85
|
end
|
91
86
|
|
92
|
-
empty_table!(table) if count == 0
|
93
|
-
|
94
87
|
count
|
95
88
|
end
|
96
89
|
|
97
90
|
|
98
91
|
|
99
|
-
def empty_table!(table)
|
100
|
-
raise MdbToolsNotInstalledError unless system("which mdb-export")
|
101
|
-
raise TableDoesNotExistError, "#{table.inspect} does not exist in #{file_name.inspect}" if !tables.member?(table.to_s)
|
102
|
-
raise Error, "An error occurred when reading #{table.inspect} in #{file_name.inspect}"
|
103
|
-
end
|
104
|
-
|
105
|
-
|
106
|
-
|
107
92
|
def file_name
|
108
93
|
Shellwords.escape(file)
|
109
94
|
end
|
@@ -111,8 +96,7 @@ module Mdb
|
|
111
96
|
|
112
97
|
|
113
98
|
def open_csv(table)
|
114
|
-
|
115
|
-
execute(command) do |file|
|
99
|
+
read_csv(table) do |file|
|
116
100
|
yield CSV.new(file, col_sep: delimiter)
|
117
101
|
end
|
118
102
|
end
|
@@ -121,7 +105,10 @@ module Mdb
|
|
121
105
|
|
122
106
|
def execute(command)
|
123
107
|
file = Tempfile.new("mdb")
|
124
|
-
system "#{command} > #{file.path} 2> /dev/null"
|
108
|
+
unless system "#{command} > #{file.path} 2> /dev/null"
|
109
|
+
raise MdbToolsNotInstalledError if $?.exitstatus == 127
|
110
|
+
raise Error, "#{command[/^\S+/]} exited with status #{$?.exitstatus}"
|
111
|
+
end
|
125
112
|
return file.read unless block_given?
|
126
113
|
yield file
|
127
114
|
ensure
|
data/lib/mdb/version.rb
CHANGED
data/mdb.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "rails", ">= 3.2.0", "< 4.1.0"
|
24
|
+
spec.add_development_dependency "shoulda-context"
|
24
25
|
spec.add_development_dependency "turn"
|
25
26
|
spec.add_development_dependency "pry"
|
26
27
|
end
|
data/test/data/Example2000.mdb
CHANGED
File without changes
|
data/test/data/Example2003.mdb
CHANGED
File without changes
|
Binary file
|
data/test/database_test.rb
CHANGED
@@ -41,6 +41,23 @@ class MdbTest < ActiveSupport::TestCase
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
context "without permission to read the file" do
|
45
|
+
setup do
|
46
|
+
system "chmod u-r #{File.dirname(__FILE__)}/data/Protected.mdb"
|
47
|
+
end
|
48
|
+
|
49
|
+
teardown do
|
50
|
+
system "chmod u+r #{File.dirname(__FILE__)}/data/Protected.mdb"
|
51
|
+
end
|
52
|
+
|
53
|
+
should "raise an exception if mdb-tools fails for other reasons" do
|
54
|
+
assert_raises(Mdb::Error) do
|
55
|
+
database = Mdb.open "#{File.dirname(__FILE__)}/data/Protected.mdb"
|
56
|
+
database.read :Actors
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
44
61
|
test "should raise an exception if a table is not found" do
|
45
62
|
database = Mdb.open "#{File.dirname(__FILE__)}/data/Example2000.mdb"
|
46
63
|
assert_raises(Mdb::TableDoesNotExistError) do
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Lail
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,6 +58,20 @@ dependencies:
|
|
58
58
|
- - "<"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: 4.1.0
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: shoulda-context
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
76
|
name: turn
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +108,7 @@ extensions: []
|
|
94
108
|
extra_rdoc_files: []
|
95
109
|
files:
|
96
110
|
- ".gitignore"
|
111
|
+
- ".ruby-version"
|
97
112
|
- ".travis.yml"
|
98
113
|
- Gemfile
|
99
114
|
- LICENSE.txt
|
@@ -105,6 +120,7 @@ files:
|
|
105
120
|
- mdb.gemspec
|
106
121
|
- test/data/Example2000.mdb
|
107
122
|
- test/data/Example2003.mdb
|
123
|
+
- test/data/Protected.mdb
|
108
124
|
- test/database_test.rb
|
109
125
|
- test/test_helper.rb
|
110
126
|
homepage: ''
|
@@ -127,12 +143,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
143
|
version: '0'
|
128
144
|
requirements: []
|
129
145
|
rubyforge_project:
|
130
|
-
rubygems_version: 2.
|
146
|
+
rubygems_version: 2.5.1
|
131
147
|
signing_key:
|
132
148
|
specification_version: 4
|
133
149
|
summary: Wraps mdb-tools for reading and Microsoft Access databases (MDB)
|
134
150
|
test_files:
|
135
151
|
- test/data/Example2000.mdb
|
136
152
|
- test/data/Example2003.mdb
|
153
|
+
- test/data/Protected.mdb
|
137
154
|
- test/database_test.rb
|
138
155
|
- test/test_helper.rb
|