dbf 4.1.2 → 4.1.3

This diff has not been reviewed by any users.
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
  SHA256:
3
- metadata.gz: 9b6cdaff3283aa216120ba94a5301ccdb2bdcac4d48549a2c10677684e1b01a4
4
- data.tar.gz: e95965ac3b2415ce00db81f5e066e0dc5761cce1d35345f152b4c349d387f51e
3
+ metadata.gz: 4c2ff24f150ee6567de0532c773695f8b47c0db811660e0f5f3be3d53a7cc053
4
+ data.tar.gz: 7006275aff71326833452546657bb07520d53024b6846b0c982121a488cd8235
5
5
  SHA512:
6
- metadata.gz: dce2c6e83afa30f01e209175cf0b4391e24dd06e5738be754fbce53d4812c01b2357da125e00ab233703f7b8fbbcbddcabf4e0a9778d25884cc801b4850bd0f1
7
- data.tar.gz: 2ff59e987e773d92abc46b11130c2403c013eb3c0309be0a4bb995b85e61b8b61afc066140e055fdc6bb345107ad10940194569bebd886a838cfaca7441f1fe3
6
+ metadata.gz: b2d4bffa8201a8fa07abf642e721523e7ed59bb2b3e9a0fae31fe5ce6a4a3078f1520eb09e350d979dd88a68801c7c52d3236c402f83a41da1e5e6c4bca39911
7
+ data.tar.gz: fddf6622338b52b4bb6006513a92d9fd44c8f1e864738fd597d7e9f3fc21bcd86707f5e68e76216bd4c6d3be7dad9a48e5e19d55a6728691f6d90d86ec6db25e
@@ -1,3 +1,6 @@
1
+ # 4.1.3
2
+ - Raise DBF::NoColumnsDefined error when attempting to read records if no columns are defined
3
+
1
4
  # 4.1.1
2
5
  - Add required_ruby_version to gemspec
3
6
 
data/Gemfile CHANGED
@@ -4,11 +4,13 @@ source 'https://rubygems.org'
4
4
  group :development, :test do
5
5
  gem 'awesome_print'
6
6
  gem 'byebug'
7
+ gem 'e2mmap'
7
8
  gem 'guard'
8
9
  gem 'guard-rspec'
9
10
  gem 'irb'
10
11
  gem 'rake'
11
12
  gem 'rspec'
12
13
  gem 'rubocop'
14
+ gem 'rubocop-performance'
13
15
  gem 'rubocop-rspec'
14
16
  end
@@ -1,19 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dbf (4.1.1)
4
+ dbf (4.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ast (2.4.0)
10
10
  awesome_print (1.8.0)
11
- byebug (10.0.2)
11
+ byebug (11.0.1)
12
12
  coderay (1.1.2)
13
13
  diff-lcs (1.3)
14
- ffi (1.9.25)
14
+ e2mmap (0.1.0)
15
+ ffi (1.11.1)
15
16
  formatador (0.2.5)
16
- guard (2.14.2)
17
+ guard (2.15.0)
17
18
  formatador (>= 0.2.4)
18
19
  listen (>= 2.7, < 4.0)
19
20
  lumberjack (>= 1.0.12, < 2.0)
@@ -28,57 +29,57 @@ GEM
28
29
  guard-compat (~> 1.1)
29
30
  rspec (>= 2.99.0, < 4.0)
30
31
  irb (1.0.0)
31
- jaro_winkler (1.5.1)
32
+ jaro_winkler (1.5.3)
32
33
  listen (3.1.5)
33
34
  rb-fsevent (~> 0.9, >= 0.9.4)
34
35
  rb-inotify (~> 0.9, >= 0.9.7)
35
36
  ruby_dep (~> 1.2)
36
37
  lumberjack (1.0.13)
37
- method_source (0.9.0)
38
+ method_source (0.9.2)
38
39
  nenv (0.3.0)
39
40
  notiffany (0.1.1)
40
41
  nenv (~> 0.1)
41
42
  shellany (~> 0.0)
42
- parallel (1.12.1)
43
- parser (2.5.1.2)
43
+ parallel (1.17.0)
44
+ parser (2.6.3.0)
44
45
  ast (~> 2.4.0)
45
- powerpack (0.1.2)
46
- pry (0.11.3)
46
+ pry (0.12.2)
47
47
  coderay (~> 1.1.0)
48
48
  method_source (~> 0.9.0)
49
49
  rainbow (3.0.0)
50
- rake (12.3.1)
50
+ rake (12.3.2)
51
51
  rb-fsevent (0.10.3)
52
- rb-inotify (0.9.10)
53
- ffi (>= 0.5.0, < 2)
52
+ rb-inotify (0.10.0)
53
+ ffi (~> 1.0)
54
54
  rspec (3.8.0)
55
55
  rspec-core (~> 3.8.0)
56
56
  rspec-expectations (~> 3.8.0)
57
57
  rspec-mocks (~> 3.8.0)
58
- rspec-core (3.8.0)
58
+ rspec-core (3.8.2)
59
59
  rspec-support (~> 3.8.0)
60
- rspec-expectations (3.8.1)
60
+ rspec-expectations (3.8.4)
61
61
  diff-lcs (>= 1.2.0, < 2.0)
62
62
  rspec-support (~> 3.8.0)
63
- rspec-mocks (3.8.0)
63
+ rspec-mocks (3.8.1)
64
64
  diff-lcs (>= 1.2.0, < 2.0)
65
65
  rspec-support (~> 3.8.0)
66
- rspec-support (3.8.0)
67
- rubocop (0.59.2)
66
+ rspec-support (3.8.2)
67
+ rubocop (0.73.0)
68
68
  jaro_winkler (~> 1.5.1)
69
69
  parallel (~> 1.10)
70
- parser (>= 2.5, != 2.5.1.1)
71
- powerpack (~> 0.1)
70
+ parser (>= 2.6)
72
71
  rainbow (>= 2.2.2, < 4.0)
73
72
  ruby-progressbar (~> 1.7)
74
- unicode-display_width (~> 1.0, >= 1.0.1)
75
- rubocop-rspec (1.30.0)
76
- rubocop (>= 0.58.0)
77
- ruby-progressbar (1.10.0)
73
+ unicode-display_width (>= 1.4.0, < 1.7)
74
+ rubocop-performance (1.4.0)
75
+ rubocop (>= 0.71.0)
76
+ rubocop-rspec (1.33.0)
77
+ rubocop (>= 0.60.0)
78
+ ruby-progressbar (1.10.1)
78
79
  ruby_dep (1.5.0)
79
80
  shellany (0.0.1)
80
- thor (0.20.0)
81
- unicode-display_width (1.4.0)
81
+ thor (0.20.3)
82
+ unicode-display_width (1.6.0)
82
83
 
83
84
  PLATFORMS
84
85
  ruby
@@ -87,13 +88,15 @@ DEPENDENCIES
87
88
  awesome_print
88
89
  byebug
89
90
  dbf!
91
+ e2mmap
90
92
  guard
91
93
  guard-rspec
92
94
  irb
93
95
  rake
94
96
  rspec
95
97
  rubocop
98
+ rubocop-performance
96
99
  rubocop-rspec
97
100
 
98
101
  BUNDLED WITH
99
- 1.17.3
102
+ 2.1.4
data/Guardfile CHANGED
@@ -6,6 +6,6 @@ guard :rspec, cmd: 'bundle exec rspec' do
6
6
  # watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
7
  watch(%r{^lib/(.+)\.rb$}) { 'spec' }
8
8
  watch('spec/spec_helper.rb') { 'spec' }
9
- watch(/spec\/fixtures\/(.+)/) { 'spec' }
9
+ watch(%r{spec/fixtures/(.+)}) { 'spec' }
10
10
  watch('Guardfile') { 'spec' }
11
11
  end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2006-2019 Keith Morrison <keithm@infused.org>
1
+ Copyright (c) 2006-2020 Keith Morrison <keithm@infused.org>
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -16,15 +16,17 @@ database files
16
16
  subject line
17
17
  * Change log: <https://github.com/infused/dbf/blob/master/CHANGELOG.md>
18
18
 
19
- NOTE: Beginning with version 4 we have dropped support for Ruby 2.0, 2.1, 2.2, and 2.3. If you need support for these older Rubies, please use 3.0.x (https://github.com/infused.org/dbf/tree/3_stable)
19
+ NOTE: Beginning with version 4 we have dropped support for Ruby 2.0, 2.1, 2.2, and 2.3. If you need support for these older Rubies,
20
+ please use 3.0.x (https://github.com/infused.org/dbf/tree/3_stable)
20
21
 
21
- NOTE: Beginning with version 3 we have dropped support for Ruby 1.8 and 1.9. If you need support for older Rubies, please use 2.0.x (https://github.com/infused/dbf/tree/2_stable)
22
+ NOTE: Beginning with version 3 we have dropped support for Ruby 1.8 and 1.9. If you need support for older Rubies,
23
+ please use 2.0.x (https://github.com/infused/dbf/tree/2_stable)
22
24
 
23
25
  ## Compatibility
24
26
 
25
27
  DBF is tested to work with the following versions of Ruby:
26
28
 
27
- * Ruby 2.4.x, 2.5.x, 2.6.x
29
+ * Ruby 2.4.x, 2.5.x, 2.6.x, 2.7.x
28
30
 
29
31
  ## Installation
30
32
 
@@ -209,7 +211,7 @@ Sequel.migration do
209
211
  end
210
212
  ```
211
213
 
212
- If you have initalized the DBF::Table with raw data, you will need to set the
214
+ If you have initialized the DBF::Table with raw data, you will need to set the
213
215
  exported table name manually:
214
216
 
215
217
  ```ruby
@@ -227,7 +229,7 @@ A small command-line utility called dbf is installed along with the gem.
227
229
  -s = print summary information
228
230
  -a = create an ActiveRecord::Schema
229
231
  -r = create a Sequel Migration
230
- -c = dump data in CSV format
232
+ -c = export as CSV
231
233
 
232
234
  Create an executable ActiveRecord schema:
233
235
 
@@ -273,7 +275,7 @@ for a full list of supported column types.
273
275
 
274
276
  ## License
275
277
 
276
- Copyright (c) 2006-2019 Keith Morrison <<keithm@infused.org>>
278
+ Copyright (c) 2006-2020 Keith Morrison <<keithm@infused.org>>
277
279
 
278
280
  Permission is hereby granted, free of charge, to any person
279
281
  obtaining a copy of this software and associated documentation
data/bin/dbf CHANGED
@@ -16,7 +16,7 @@ elsif params['h']
16
16
  puts ' -s = print summary information'
17
17
  puts ' -a = create an ActiveRecord::Schema'
18
18
  puts ' -r = create a Sequel migration'
19
- puts ' -c = create a CSV file'
19
+ puts ' -c = export as CSV'
20
20
  else
21
21
 
22
22
  filename = ARGV.shift
@@ -1,11 +1,6 @@
1
1
  module DBF
2
2
  module ColumnType
3
3
  class Base
4
- ENCODING_ARGS = [
5
- Encoding.default_external,
6
- {undef: :replace, invalid: :replace}
7
- ].freeze
8
-
9
4
  attr_reader :decimal, :encoding
10
5
 
11
6
  def initialize(decimal, encoding)
@@ -79,7 +74,7 @@ module DBF
79
74
  class Memo < Base
80
75
  def type_cast(value)
81
76
  if encoding && !value.nil?
82
- value.force_encoding(@encoding).encode(*ENCODING_ARGS)
77
+ value.force_encoding(@encoding).encode(Encoding.default_external, undef: :replace, invalid: :replace)
83
78
  else
84
79
  value
85
80
  end
@@ -95,7 +90,7 @@ module DBF
95
90
  class String < Base
96
91
  def type_cast(value)
97
92
  value = value.strip
98
- @encoding ? value.force_encoding(@encoding).encode(*ENCODING_ARGS) : value
93
+ @encoding ? value.force_encoding(@encoding).encode(Encoding.default_external, undef: :replace, invalid: :replace) : value
99
94
  end
100
95
  end
101
96
  end
@@ -2,6 +2,9 @@ module DBF
2
2
  class FileNotFoundError < StandardError
3
3
  end
4
4
 
5
+ class NoColumnsDefined < StandardError
6
+ end
7
+
5
8
  # DBF::Table is the primary interface to a single DBF file and provides
6
9
  # methods for enumerating and searching the records.
7
10
  class Table
@@ -175,10 +178,13 @@ module DBF
175
178
  # @param [Integer] index
176
179
  # @return [DBF::Record, NilClass]
177
180
  def record(index)
181
+ raise DBF::NoColumnsDefined, 'The DBF file has no columns defined' if columns.empty?
182
+
178
183
  seek_to_record(index)
179
184
  return nil if deleted_record?
180
185
 
181
- DBF::Record.new(@data.read(record_length), columns, version, @memo)
186
+ record_data = @data.read(record_length)
187
+ DBF::Record.new(record_data, columns, version, @memo)
182
188
  end
183
189
 
184
190
  alias row record
@@ -1,3 +1,3 @@
1
1
  module DBF
2
- VERSION = '4.1.2'.freeze
2
+ VERSION = '4.1.3'.freeze
3
3
  end
@@ -52,14 +52,14 @@ RSpec.describe DBF::Column do
52
52
  end
53
53
  end
54
54
 
55
- context 'and 0 length' do
55
+ context 'with 0 length' do
56
56
  it 'returns nil' do
57
57
  column = DBF::Column.new table, 'ColumnName', 'N', 0, 0
58
58
  expect(column.type_cast('')).to be_nil
59
59
  end
60
60
  end
61
61
 
62
- context 'and 0 decimals' do
62
+ context 'with 0 decimals' do
63
63
  it 'casts value to Integer' do
64
64
  value = '135'
65
65
  column = DBF::Column.new table, 'ColumnName', 'N', 3, 0
@@ -73,7 +73,7 @@ RSpec.describe DBF::Column do
73
73
  end
74
74
  end
75
75
 
76
- context 'and more than 0 decimals' do
76
+ context 'with more than 0 decimals' do
77
77
  it 'casts value to Float' do
78
78
  value = '13.5'
79
79
  column = DBF::Column.new table, 'ColumnName', 'N', 2, 1
@@ -89,7 +89,7 @@ RSpec.describe DBF::Column do
89
89
  end
90
90
 
91
91
  context 'with type F (float)' do
92
- context 'and 0 length' do
92
+ context 'with 0 length' do
93
93
  it 'returns nil' do
94
94
  column = DBF::Column.new table, 'ColumnName', 'F', 0, 0
95
95
  expect(column.type_cast('')).to be_nil
@@ -132,7 +132,7 @@ RSpec.describe DBF::Column do
132
132
  end
133
133
 
134
134
  context 'with type I (integer)' do
135
- context 'and 0 length' do
135
+ context 'with 0 length' do
136
136
  it 'returns nil' do
137
137
  column = DBF::Column.new table, 'ColumnName', 'I', 0, 0
138
138
  expect(column.type_cast('')).to be_nil
@@ -167,7 +167,7 @@ RSpec.describe DBF::Column do
167
167
  expect(column.type_cast('n')).to be false
168
168
  end
169
169
 
170
- context 'and 0 length' do
170
+ context 'with 0 length' do
171
171
  it 'returns nil' do
172
172
  column = DBF::Column.new table, 'ColumnName', 'L', 0, 0
173
173
  expect(column.type_cast('')).to be_nil
@@ -232,7 +232,7 @@ RSpec.describe DBF::Column do
232
232
  expect(column.type_cast(nil)).to be_nil
233
233
  end
234
234
 
235
- context 'and 0 length' do
235
+ context 'with 0 length' do
236
236
  it 'returns nil' do
237
237
  column = DBF::Column.new table, 'ColumnName', 'M', 0, 0
238
238
  expect(column.type_cast('')).to be_nil
@@ -252,7 +252,7 @@ RSpec.describe DBF::Column do
252
252
  expect(column.type_cast(nil)).to be_nil
253
253
  end
254
254
 
255
- context 'and 0 length' do
255
+ context 'with 0 length' do
256
256
  it 'returns nil' do
257
257
  column = DBF::Column.new table, 'ColumnName', 'G', 0, 0
258
258
  expect(column.type_cast('')).to be_nil
@@ -276,7 +276,7 @@ RSpec.describe DBF::Column do
276
276
  expect(column.type_cast("pN'9\xFF\xFF\xFF\xFF")).to eq(-333_609.0)
277
277
  end
278
278
 
279
- context 'and 0 length' do
279
+ context 'with 0 length' do
280
280
  it 'returns nil' do
281
281
  column = DBF::Column.new table, 'ColumnName', 'Y', 0, 0
282
282
  expect(column.type_cast('')).to be_nil
@@ -284,7 +284,7 @@ RSpec.describe DBF::Column do
284
284
  end
285
285
  end
286
286
 
287
- context '#name' do
287
+ describe '#name' do
288
288
  it 'contains only ASCII characters' do
289
289
  column = DBF::Column.new table, "--\x1F-\x68\x65\x6C\x6C\x6F world-\x80--", 'N', 1, 0
290
290
  expect(column.name).to eq '---hello world---'
@@ -1,17 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.shared_examples_for 'DBF' do
4
- specify 'sum of column lengths should equal record length specified in header plus one' do
5
- header_record_length = table.instance_eval { @header.record_length }
6
- sum_of_column_lengths = table.columns.inject(1) { |sum, column| sum += column.length }
4
+ let(:header_record_length) { table.instance_eval { header.record_length } }
5
+ let(:sum_of_column_lengths) { table.columns.inject(1) { |sum, column| sum + column.length } }
7
6
 
7
+ specify 'sum of column lengths should equal record length specified in header plus one' do
8
8
  expect(header_record_length).to eq sum_of_column_lengths
9
9
  end
10
10
 
11
11
  specify 'records should be instances of DBF::Record' do
12
- table.each do |record|
13
- expect(record).to be_kind_of(DBF::Record)
14
- end
12
+ expect(table).to all be_kind_of(DBF::Record)
15
13
  end
16
14
 
17
15
  specify 'record count should be the same as reported in the header' do
@@ -44,13 +44,13 @@ RSpec.describe DBF::Record do
44
44
 
45
45
  describe 'when other does not have attributes' do
46
46
  it 'returns false' do
47
- expect((record == double('other'))).to be_falsey
47
+ expect((record == instance_double('DBF::Record'))).to be_falsey
48
48
  end
49
49
  end
50
50
 
51
51
  describe 'if other attributes match' do
52
52
  let(:attributes) { {x: 1, y: 2} }
53
- let(:other) { double('object', attributes: attributes) }
53
+ let(:other) { instance_double('DBF::Record', attributes: attributes) }
54
54
 
55
55
  before do
56
56
  allow(record).to receive(:attributes).and_return(attributes)
@@ -147,6 +147,14 @@ RSpec.describe DBF::Table do
147
147
  allow(table).to receive(:deleted_record?).and_return(true)
148
148
  expect(table.record(5)).to be_nil
149
149
  end
150
+
151
+ describe 'when dbf has no column definitions' do
152
+ let(:dbf_path) { fixture('polygon.dbf') }
153
+
154
+ it 'raises a DBF::NoColumnsDefined error' do
155
+ expect { DBF::Table.new(dbf_path).record(1) }.to raise_error(DBF::NoColumnsDefined, 'The DBF file has no columns defined')
156
+ end
157
+ end
150
158
  end
151
159
 
152
160
  describe '#current_record' do
Binary file
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: 4.1.2
4
+ version: 4.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Morrison
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-22 00:00:00.000000000 Z
11
+ date: 2020-08-29 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.
@@ -48,7 +48,7 @@ files:
48
48
  - lib/dbf/table.rb
49
49
  - lib/dbf/version.rb
50
50
  - spec/dbf/column_spec.rb
51
- - spec/dbf/database_spec.rb
51
+ - spec/dbf/database/foxpro_spec.rb
52
52
  - spec/dbf/file_formats_spec.rb
53
53
  - spec/dbf/record_spec.rb
54
54
  - spec/dbf/table_spec.rb
@@ -90,12 +90,13 @@ files:
90
90
  - spec/fixtures/foxprodb/setup.dbf
91
91
  - spec/fixtures/foxprodb/types.CDX
92
92
  - spec/fixtures/foxprodb/types.dbf
93
+ - spec/fixtures/polygon.dbf
93
94
  - spec/spec_helper.rb
94
95
  homepage: http://github.com/infused/dbf
95
96
  licenses:
96
97
  - MIT
97
98
  metadata: {}
98
- post_install_message:
99
+ post_install_message:
99
100
  rdoc_options:
100
101
  - "--charset=UTF-8"
101
102
  require_paths:
@@ -111,13 +112,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
112
  - !ruby/object:Gem::Version
112
113
  version: 1.3.0
113
114
  requirements: []
114
- rubygems_version: 3.0.2
115
- signing_key:
115
+ rubygems_version: 3.1.2
116
+ signing_key:
116
117
  specification_version: 4
117
118
  summary: Read xBase files
118
119
  test_files:
120
+ - spec/dbf/database/foxpro_spec.rb
119
121
  - spec/dbf/file_formats_spec.rb
120
- - spec/dbf/database_spec.rb
121
122
  - spec/dbf/column_spec.rb
122
123
  - spec/dbf/record_spec.rb
123
124
  - spec/dbf/table_spec.rb