prawn-attachment 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/README.md +1 -1
- data/lib/prawn/attachment/version.rb +1 -1
- data/lib/prawn/attachment.rb +21 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c82ce1fc502c03d7348f8c72873ae174a82387f42b6f1619ee0405eccd75165b
|
4
|
+
data.tar.gz: 61646a398075b6757fd9682f47754041e12e4bb444956489fbb60bb2757ec059
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76721c29d6d7b918b4ef580b7465b651fc97c9d5579107a842084f8528994854c68d4b6e2a47d8b52325ce4ed74e7934e93ae3680c7ae9ceab22471e8cf99656
|
7
|
+
data.tar.gz: 5e349c0d2f29986ec24c74efbd7b2155b4a7e8623a069c4791da1d0162b361d7db37fb01bf0a86784f6d58390d3aa2d6bef790a3b964ff2c03e2aa83fa98a2e5
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
data/lib/prawn/attachment.rb
CHANGED
@@ -19,6 +19,13 @@ module Prawn
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
# Invalid data provided
|
23
|
+
class InvalidDataError < StandardError
|
24
|
+
def message
|
25
|
+
"Source data must be an IO object or string"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
22
29
|
# Attach a file's data to the document. File IO Objects are expected.
|
23
30
|
#
|
24
31
|
# Arguments:
|
@@ -42,9 +49,7 @@ module Prawn
|
|
42
49
|
# hidden, then nil is returned.
|
43
50
|
#
|
44
51
|
def attach(name, src, opts = {})
|
45
|
-
data = src
|
46
|
-
raise NoDataError if data.length.zero?
|
47
|
-
|
52
|
+
data = extract_data_from_source(src)
|
48
53
|
opts = prepare_options(name, opts)
|
49
54
|
|
50
55
|
# Prepare embeddable representation of the source data
|
@@ -58,6 +63,19 @@ module Prawn
|
|
58
63
|
|
59
64
|
private
|
60
65
|
|
66
|
+
def extract_data_from_source(src)
|
67
|
+
if src.respond_to?(:read)
|
68
|
+
data = src.read
|
69
|
+
elsif src.respond_to?(:b)
|
70
|
+
data = src.b
|
71
|
+
else
|
72
|
+
raise InvalidDataError
|
73
|
+
end
|
74
|
+
raise NoDataError if data.length.zero?
|
75
|
+
|
76
|
+
data
|
77
|
+
end
|
78
|
+
|
61
79
|
def prepare_options(name, opts)
|
62
80
|
{
|
63
81
|
name: name,
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prawn-attachment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Lilue
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-03-
|
12
|
+
date: 2022-03-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: prawn
|