marc_alephsequential 1.0.0 → 2.0.0

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: 8df9c89123e3491792191102ca213b18deb648b3
4
- data.tar.gz: 03cfc3c63a3912d03069ac095e195ac972dc2843
3
+ metadata.gz: c21cb8f33a3b2a1275e1c1fe4cbab9124105532e
4
+ data.tar.gz: 1679f8be5ceb7c577c9323a542237c533627ccd5
5
5
  SHA512:
6
- metadata.gz: ba633b8560bb40c40983f7b1ca6b43631d2a342371837b4bcf0b4306c390a81de2abf3ae0b86414c15c9bbd4085833144be659e7eb860538ae47231d6cee6562
7
- data.tar.gz: ac88f0374ec7e4270f345fc7134f32c0adaf9034971a50038233f16ebf26d570b5d861660f78be3ea2d5cb5bc019dcb972cb2ff49baefdb664fb24699d3d0604
6
+ metadata.gz: 9507f291bea0e23e0edf170c8aa1d9a7656da0bc8e74206d7182d52854b6420ab6058d45e7622b56f53723f097e988c1572eef5369c15612d77f143bb7cbf194
7
+ data.tar.gz: eca9f90589c7f5caef2fd23837d2f2af390a56fdc3d26b57c030477a10f6047e9f97034197ca75744ea0b603c0c820bf2ba183c988b65976a737ee5ab1bc25d3
@@ -1,3 +1,18 @@
1
+ ### 2.0.0 /
2
+
3
+ Change the way MARC::AlephSequential::Reader deals with errors when
4
+ producing a record for `#each`. Instead of throwing an error (and aborting
5
+ the loop whether you wanted to or not, since there's no way to catch
6
+ the error in a provided block), it will now return a
7
+ MARC::AlephSequential::ErrorRecord `er` with a method `er.error` holding
8
+ the error.
9
+
10
+ This should affect almost no one.
11
+
12
+ ### 1.0.0
13
+
14
+ First 1.0 release. No major changes.
15
+
1
16
  ### 0.1.1 / 2013-10-23
2
17
 
3
18
  * Fixed bad call to respond_to in intializer
data/README.md CHANGED
@@ -20,16 +20,14 @@ A [ruby-marc](https://github.com/ruby-marc/ruby-marc) reader for MARC files in t
20
20
  reader = MARC::AlephSequential::Reader.new('myfile.seq.gz') # automatically notice the .gz and behave!
21
21
 
22
22
  reader.log = log # optional. Set up a logger; otherwise, a default logger will be used
23
-
24
- begin
25
- reader.each do |r|
26
- # do stuff with the record
27
- end
28
- rescue MARC::AlephSequential::Error => e
29
- log.error "Error while parsing record #{e.record_id} at/near #{e.line_number}: #{e.message}"
30
- retry # may or may not work the way you'd hope/expect
31
- rescue => e
32
- log.error "Other error of some sort. quitting. #{e.message}"
23
+
24
+ reader.each do |r|
25
+ if MARC::AlephSequential::ErrorRecord === r
26
+ e = r.error
27
+ log.error "Error while parsing record #{e.record_id} at/near #{e.line_number}: #{e.message}"
28
+ next
29
+ end
30
+ doStuffWithTheRecord(r)
33
31
  end
34
32
 
35
33
  ```
@@ -7,6 +7,22 @@ require 'marc_alephsequential/log'
7
7
  module MARC
8
8
  module AlephSequential
9
9
 
10
+ # We need an empty record to signal an error condition that might
11
+ # occur within #each (e.g, the record has no leader). Raising the
12
+ # error will abort any #each loop without giving the user a chance
13
+ # to catch is (because by the time the block is run, the error has
14
+ # already been thrown). See a simplified example of this problem at
15
+ # https://gist.github.com/billdueber/6d501f730c79f6a74498
16
+
17
+
18
+ class ErrorRecord < MARC::Record
19
+ attr_accessor :error
20
+ def initialize(error)
21
+ super()
22
+ self.error = error
23
+ end
24
+ end
25
+
10
26
  class Reader
11
27
 
12
28
  include Enumerable
@@ -30,7 +46,11 @@ module MARC
30
46
  while @areader.has_next?
31
47
  nextid = @areader.peek.id
32
48
  if nextid != @current_id && @areader.peek.valid_id?
33
- yield agroup.to_record unless agroup.empty?
49
+ begin
50
+ yield agroup.to_record unless agroup.empty?
51
+ rescue RuntimeError => e
52
+ yield ErrorRecord.new(e)
53
+ end
34
54
  agroup = ASLineGroup.new
35
55
  @current_id = nextid
36
56
  else
@@ -38,7 +58,12 @@ module MARC
38
58
  end
39
59
  end
40
60
  # yield whatever is left, unless there's nothing left
41
- yield agroup.to_record unless agroup.empty?
61
+ begin
62
+ yield agroup.to_record unless agroup.empty?
63
+ rescue RuntimeError => e
64
+ yield ErrorRecord.new(e)
65
+ end
66
+
42
67
  end
43
68
  end
44
69
  end
@@ -1,5 +1,5 @@
1
1
  module MarcAlephsequential
2
2
  # marc_alephsequential version
3
- VERSION = "1.0.0"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
 
@@ -33,13 +33,11 @@ describe 'Reader' do
33
33
 
34
34
  it "yells when there's no leader" do
35
35
  error = nil
36
- begin
37
- r = MARC::AlephSequential::Reader.new(@noleader).first
38
- rescue MARC::AlephSequential::Error => e
39
- error = e
40
- end
41
- error.wont_be_nil
42
- error.message.must_match /leader/
36
+ r = MARC::AlephSequential::Reader.new(@noleader).first
37
+ r.must_be_kind_of MARC::AlephSequential::ErrorRecord
38
+ r.must_respond_to :error
39
+ r.error.wont_be_nil
40
+ r.error.message.must_match /leader/
43
41
  end
44
42
 
45
43
  it "deals ok with embedded newline" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marc_alephsequential
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bill Dueber
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-05 00:00:00.000000000 Z
11
+ date: 2015-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: marc