Skip to content

Commit 1bcd49f

Browse files
author
Jon Yurek
committed
Refactor DataUriAdapter a little
1 parent 38a6b4d commit 1bcd49f

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

lib/paperclip/io_adapters/data_uri_adapter.rb

+5-11
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ class DataUriAdapter < StringioAdapter
33

44
REGEXP = /^data:([-\w]+\/[-\w\+]+);base64,(.*)/
55

6-
def initialize(target)
7-
@data_uri_parts = target.match(REGEXP) || []
8-
deserialize
6+
def initialize(target_uri)
7+
@target_uri = target_uri
98
cache_current_values
109
@tempfile = copy_to_tempfile
1110
end
@@ -14,17 +13,12 @@ def initialize(target)
1413

1514
def cache_current_values
1615
self.original_filename = 'base64.txt'
17-
18-
@content_type = @data_uri_parts[1]
19-
@content_type ||= 'text/plain'
20-
16+
data_uri_parts ||= @target_uri.match(REGEXP) || []
17+
@content_type = data_uri_parts[1] || 'text/plain'
18+
@target = StringIO.new(Base64.decode64(data_uri_parts[2] || ''))
2119
@size = @target.size
2220
end
2321

24-
def deserialize
25-
@target = StringIO.new(Base64.decode64(@data_uri_parts[2]))
26-
end
27-
2822
end
2923
end
3024

0 commit comments

Comments
 (0)