dbf 3.0.4 → 3.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a9691bee280ae2d7df25c7f2fb328a8ac15d9dd
4
- data.tar.gz: c93cc164e9b0749baa2b700a4f322d4ae7c0242a
3
+ metadata.gz: 064632eced72b296864cd94cecd0fe3dfee7cd6a
4
+ data.tar.gz: 2a6a8328c5d2bef35025cf4543c021ed4e6fb997
5
5
  SHA512:
6
- metadata.gz: f0870b61e88a071d6d0d5cb8cec8036fad9566f00820ae5186298507598c6f4cd1f563dcd0d56f46e501fa392b8f33225915008cd0a9a0ba5eace029e9092926
7
- data.tar.gz: aa88664313b12814de6590430b129f4414a9b967119b21a40537ed9a1b53698f2d04c0a5083ed7c50c1ce35fc8d8995cc055c9da46523197192e35375332134e
6
+ metadata.gz: 53f5f9819d2136a296f9677f6806d7d63ebc1794fd0dd7230da96db1035f7c9fa8ea5bd70674a029974a120f9e55997ccec17a42991b3ef911f4823d7a92f6d9
7
+ data.tar.gz: 1909fefeba3bd3dc38a3b8fc96c6bb1a75ac54e750e9b764b6b3bd90eaa43a8bdd138629df3168485553c7932aac09a28e7215a9fb403d45bec0efaf746f6e15
@@ -1,7 +1,9 @@
1
+ # 3.0.5
2
+ - Override table name for schema output
3
+
1
4
  # 3.0.4
2
5
  - Adds -v command-line option to print version
3
6
  - Adds -r command-line option to create Sequel migration
4
- -
5
7
 
6
8
  # 3.0.3
7
9
  - Uninitialized (N)umbers should return nil
@@ -1,13 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dbf (3.0.1)
5
- bindata
6
4
 
7
5
  GEM
8
6
  remote: https://rubygems.org/
9
7
  specs:
10
- bindata (2.1.0)
11
8
  byebug (8.2.0)
12
9
  coderay (1.1.0)
13
10
  diff-lcs (1.2.5)
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2006-2015 Keith Morrison <keithm@infused.org>
1
+ Copyright (c) 2006-2016 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
@@ -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 ruby:
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-2015 Keith Morrison <<keithm@infused.org>>
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
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'dbf'
4
+ require 'dbf/version'
4
5
  require 'optparse'
5
6
 
6
7
  params = ARGV.getopts('h', 's', 'a', 'c', 'r', 'v')
7
8
 
8
- if params['v'] then
9
+ if params['v']
9
10
  puts "dbf version: #{DBF::VERSION}"
10
11
 
11
12
  elsif params['h'] then
@@ -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 \"#{File.basename(@data.path, '.*')}\" do |t|\n"
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(:#{File.basename(@data.path, '.*')}) do\n"
49
+ s << " create_table(:#{name}) do\n"
50
50
  columns.each do |column|
51
51
  s << " column #{column.sequel_schema_definition}"
52
52
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module DBF
2
- VERSION = '3.0.4'
2
+ VERSION = '3.0.5'
3
3
  end
@@ -49,10 +49,25 @@ RSpec.describe DBF::Table do
49
49
  end
50
50
 
51
51
  describe '#schema' do
52
- let(:control_schema) { File.read(fixture('dbase_83_schema.txt')) }
52
+ describe 'when data is IO' do
53
+ let(:control_schema) { File.read(fixture('dbase_83_schema.txt')) }
53
54
 
54
- it 'matches the test schema fixture' do
55
- expect(table.schema).to eq control_schema
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
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-01-22 00:00:00.000000000 Z
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.