dbf 3.0.4 → 3.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -1
- data/Gemfile.lock +0 -3
- data/LICENSE +1 -1
- data/README.md +33 -6
- data/bin/dbf +2 -1
- data/lib/dbf/schema.rb +2 -2
- data/lib/dbf/table.rb +7 -1
- data/lib/dbf/version.rb +1 -1
- data/spec/dbf/table_spec.rb +48 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 064632eced72b296864cd94cecd0fe3dfee7cd6a
|
4
|
+
data.tar.gz: 2a6a8328c5d2bef35025cf4543c021ed4e6fb997
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53f5f9819d2136a296f9677f6806d7d63ebc1794fd0dd7230da96db1035f7c9fa8ea5bd70674a029974a120f9e55997ccec17a42991b3ef911f4823d7a92f6d9
|
7
|
+
data.tar.gz: 1909fefeba3bd3dc38a3b8fc96c6bb1a75ac54e750e9b764b6b3bd90eaa43a8bdd138629df3168485553c7932aac09a28e7215a9fb403d45bec0efaf746f6e15
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -20,9 +20,9 @@ NOTE: beginning with version 3 we have dropped support for Ruby 1.8 and 1.9. If
|
|
20
20
|
|
21
21
|
## Compatibility
|
22
22
|
|
23
|
-
DBF is tested to work with the following versions of
|
23
|
+
DBF is tested to work with the following versions of Ruby:
|
24
24
|
|
25
|
-
* MRI Ruby 2.0.x, 2.1.x, 2.2.x
|
25
|
+
* MRI Ruby 2.0.x, 2.1.x, 2.2.x, 2.3.x
|
26
26
|
* JRuby head
|
27
27
|
|
28
28
|
## Installation
|
@@ -41,13 +41,26 @@ gem 'dbf'
|
|
41
41
|
|
42
42
|
## Basic Usage
|
43
43
|
|
44
|
-
Open a DBF file:
|
44
|
+
Open a DBF file using a path:
|
45
45
|
|
46
46
|
```ruby
|
47
47
|
require 'dbf'
|
48
48
|
widgets = DBF::Table.new("widgets.dbf")
|
49
49
|
```
|
50
50
|
|
51
|
+
Open a DBF file using an IO object:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
data = File.open('widgets.dbf')
|
55
|
+
widgets = DBF::Table.new(data)
|
56
|
+
```
|
57
|
+
|
58
|
+
Open a DBF by passing in raw data (wrap the raw data with a StringIO):
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
widgets = DBF::Table.new(StringIO.new('raw binary data'))
|
62
|
+
```
|
63
|
+
|
51
64
|
Enumerate all records
|
52
65
|
|
53
66
|
```ruby
|
@@ -166,6 +179,13 @@ class CreateBooks < ActiveRecord::Migration
|
|
166
179
|
end
|
167
180
|
```
|
168
181
|
|
182
|
+
If you have initalized the DBF::Table with raw data, you will need to set the
|
183
|
+
table name manually with:
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
table.name = 'my_table_name'
|
187
|
+
```
|
188
|
+
|
169
189
|
## Migrating to Sequel
|
170
190
|
|
171
191
|
An example of migrating a DBF book table to Sequel using a migration:
|
@@ -179,19 +199,26 @@ Sequel.migration do
|
|
179
199
|
up do
|
180
200
|
table = DBF::Table.new('db/dbf/books.dbf')
|
181
201
|
eval(table.schema(:sequel, true)) # passing true to limit output to create_table() only
|
182
|
-
|
202
|
+
|
183
203
|
Book.reset_column_information
|
184
204
|
table.each do |record|
|
185
205
|
Book.create(title: record.title, author: record.author)
|
186
206
|
end
|
187
207
|
end
|
188
|
-
|
208
|
+
|
189
209
|
down do
|
190
210
|
drop_table(:books)
|
191
211
|
end
|
192
212
|
end
|
193
213
|
```
|
194
214
|
|
215
|
+
If you have initalized the DBF::Table with raw data, you will need to set the
|
216
|
+
table name manually with:
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
table.name = 'my_table_name'
|
220
|
+
```
|
221
|
+
|
195
222
|
## Command-line utility
|
196
223
|
|
197
224
|
A small command-line utility called dbf is installed along with the gem.
|
@@ -249,7 +276,7 @@ for a full list of supported column types.
|
|
249
276
|
|
250
277
|
## License
|
251
278
|
|
252
|
-
Copyright (c) 2006-
|
279
|
+
Copyright (c) 2006-2016 Keith Morrison <<keithm@infused.org>>
|
253
280
|
|
254
281
|
Permission is hereby granted, free of charge, to any person
|
255
282
|
obtaining a copy of this software and associated documentation
|
data/bin/dbf
CHANGED
data/lib/dbf/schema.rb
CHANGED
@@ -34,7 +34,7 @@ module DBF
|
|
34
34
|
|
35
35
|
def activerecord_schema(_table_only = false)
|
36
36
|
s = "ActiveRecord::Schema.define do\n"
|
37
|
-
s << " create_table \"#{
|
37
|
+
s << " create_table \"#{name}\" do |t|\n"
|
38
38
|
columns.each do |column|
|
39
39
|
s << " t.column #{column.schema_definition}"
|
40
40
|
end
|
@@ -46,7 +46,7 @@ module DBF
|
|
46
46
|
s = ''
|
47
47
|
s << "Sequel.migration do\n" unless table_only
|
48
48
|
s << " change do\n " unless table_only
|
49
|
-
s << " create_table(:#{
|
49
|
+
s << " create_table(:#{name}) do\n"
|
50
50
|
columns.each do |column|
|
51
51
|
s << " column #{column.sequel_schema_definition}"
|
52
52
|
end
|
data/lib/dbf/table.rb
CHANGED
@@ -39,6 +39,7 @@ module DBF
|
|
39
39
|
|
40
40
|
attr_reader :header
|
41
41
|
attr_accessor :encoding
|
42
|
+
attr_writer :name
|
42
43
|
|
43
44
|
# Opens a DBF::Table
|
44
45
|
# Examples:
|
@@ -96,7 +97,12 @@ module DBF
|
|
96
97
|
|
97
98
|
# @return String
|
98
99
|
def filename
|
99
|
-
File.basename @data.path
|
100
|
+
File.basename @data.path if @data.respond_to?(:path)
|
101
|
+
end
|
102
|
+
|
103
|
+
# @return String
|
104
|
+
def name
|
105
|
+
@name ||= filename && File.basename(filename, ".*")
|
100
106
|
end
|
101
107
|
|
102
108
|
# Calls block once for each record in the table. The record may be nil
|
data/lib/dbf/version.rb
CHANGED
data/spec/dbf/table_spec.rb
CHANGED
@@ -49,10 +49,25 @@ RSpec.describe DBF::Table do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
describe '#schema' do
|
52
|
-
|
52
|
+
describe 'when data is IO' do
|
53
|
+
let(:control_schema) { File.read(fixture('dbase_83_schema.txt')) }
|
53
54
|
|
54
|
-
|
55
|
-
|
55
|
+
it 'matches the test schema fixture' do
|
56
|
+
expect(table.schema).to eq control_schema
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'when data is StringIO' do
|
61
|
+
let(:data) { StringIO.new File.read(dbf_path) }
|
62
|
+
let(:memo) { StringIO.new File.read(memo_path) }
|
63
|
+
let(:table) { DBF::Table.new data }
|
64
|
+
|
65
|
+
let(:control_schema) { File.read(fixture('dbase_83_schema.txt')) }
|
66
|
+
|
67
|
+
it 'matches the test schema fixture' do
|
68
|
+
table.name = 'dbase_83'
|
69
|
+
expect(table.schema).to eq control_schema
|
70
|
+
end
|
56
71
|
end
|
57
72
|
end
|
58
73
|
|
@@ -82,7 +97,7 @@ Sequel.migration do
|
|
82
97
|
end
|
83
98
|
SCHEMA
|
84
99
|
end
|
85
|
-
|
100
|
+
|
86
101
|
it 'should return a limited Sequel migration when passed true' do
|
87
102
|
expect(table.sequel_schema(true)).to eq <<-SCHEMA
|
88
103
|
create_table(:dbase_83) do
|
@@ -104,7 +119,7 @@ SCHEMA
|
|
104
119
|
end
|
105
120
|
SCHEMA
|
106
121
|
end
|
107
|
-
|
122
|
+
|
108
123
|
end
|
109
124
|
|
110
125
|
describe '#json_schema' do
|
@@ -248,6 +263,34 @@ SCHEMA
|
|
248
263
|
end
|
249
264
|
end
|
250
265
|
|
266
|
+
describe '#name' do
|
267
|
+
describe 'when data is an IO' do
|
268
|
+
it 'defaults to the filename less extension' do
|
269
|
+
expect(table.name).to eq 'dbase_83'
|
270
|
+
end
|
271
|
+
|
272
|
+
it 'is mutable' do
|
273
|
+
table.name = 'database_83'
|
274
|
+
expect(table.name).to eq 'database_83'
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
describe 'when data is a StringIO' do
|
279
|
+
let(:data) { StringIO.new File.read(dbf_path) }
|
280
|
+
let(:memo) { StringIO.new File.read(memo_path) }
|
281
|
+
let(:table) { DBF::Table.new data }
|
282
|
+
|
283
|
+
it 'is nil' do
|
284
|
+
expect(table.name).to be_nil
|
285
|
+
end
|
286
|
+
|
287
|
+
it 'is mutable' do
|
288
|
+
table.name = 'database_83'
|
289
|
+
expect(table.name).to eq 'database_83'
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
251
294
|
describe '#has_memo_file?' do
|
252
295
|
describe 'without a memo file' do
|
253
296
|
let(:table) { DBF::Table.new fixture('dbase_03.dbf') }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keith Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A small fast library for reading dBase, xBase, Clipper and FoxPro database
|
14
14
|
files.
|