carrierwave-base64 2.3.2 → 2.3.3

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
  SHA1:
3
- metadata.gz: 6e27bf83c49c8234d534ff1d78fe7f46fc9dcdb2
4
- data.tar.gz: eae79370b4a5ff5b51373782e95a4938bf840c99
3
+ metadata.gz: 5bc1a39edc33de0936f042be74a0c6f93a2cac55
4
+ data.tar.gz: 9935e027ef2bed8357b96bf3bd564d0ed5539134
5
5
  SHA512:
6
- metadata.gz: fdda8a90b767e0ee2022302856d2d34da88f699d7effacb62654bab09fb49cccd924b3c290a155ea7c8acaa195d762f4d0083a8f53fcc3a276ab1666b2f5cd11
7
- data.tar.gz: b7586ed0b9387c68218ed153852c5577f2ad765ba84fa20bb5c138be4dc355cbbac7ce5d50847f09d5d891eb6e08ea2f3b0cd487a2e00a4f1fee304886d85b35
6
+ metadata.gz: 2916598308787dffa654be574d6f7d5cd3ef8685b5f3c4408aaa8867e14107f81c2ed6b25f2d0e8381d848f060e0140332810a2b5864dd59b922d275c3ce5307
7
+ data.tar.gz: cefdd00be933111e828805801830ece26bfe1263a1128b8dbcaf0ffd9acb8767442acd45292556ddd8f2731e6ba8433b4fd0a7a9949b73268e58fa767b4ac16b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # carrierwave-base64 changelog
2
2
 
3
+ ## 2.3.3
4
+
5
+ - Added proc support for the `:file_name` option for the `mount_base64_uploader` method. (credits to @hendricius)
6
+
3
7
  ## 2.3.0
4
8
 
5
9
  - Added `:file_name` option for `mount_base64_uploader` method. All base64 uploads for this attribute will use the given filename for the stored file. The `:file_name` option should not contain the file extention (it will be taken from the content type of base64 string). (@HarenBroog, thanks for the idea)
data/README.md CHANGED
@@ -42,6 +42,12 @@ To set the file name for the uploaded files, use the `:file_name` option (withou
42
42
  mount_base64_uploader :image, ImageUploader, file_name: 'userpic'
43
43
  ```
44
44
 
45
+ You can also pass a Proc for the file-name to allow dynamic filenames.
46
+
47
+ ```ruby
48
+ mount_base64_uploader :image, ImageUploader, file_name: -> { "file-#{DateTime.now.to_i}" }
49
+ ```
50
+
45
51
  ## Data format
46
52
 
47
53
  The string with the encoded data, should be prefixed with Data URI scheme format:
@@ -5,13 +5,13 @@ module Carrierwave
5
5
 
6
6
  attr_accessor :file_format, :file_name
7
7
 
8
- def initialize(encoded_file, file_name)
8
+ def initialize(encoded_file, file_name_method_or_string)
9
9
  description, encoded_bytes = encoded_file.split(',')
10
10
 
11
11
  raise ArgumentError unless encoded_bytes
12
12
  raise ArgumentError if encoded_bytes.eql?('(null)')
13
13
 
14
- @file_name = file_name
14
+ @file_name = extract_file_name(file_name_method_or_string)
15
15
  @file_format = get_file_format description
16
16
  bytes = ::Base64.decode64 encoded_bytes
17
17
 
@@ -28,6 +28,14 @@ module Carrierwave
28
28
  regex = /([a-z0-9]+);base64\z/
29
29
  regex.match(description).try(:[], 1)
30
30
  end
31
+
32
+ def extract_file_name(method_or_string)
33
+ if method_or_string.is_a?(Proc)
34
+ method_or_string.call
35
+ else
36
+ method_or_string
37
+ end
38
+ end
31
39
  end
32
40
  end
33
41
  end
@@ -1,5 +1,5 @@
1
1
  module Carrierwave
2
2
  module Base64
3
- VERSION = '2.3.2'.freeze
3
+ VERSION = '2.3.3'.freeze
4
4
  end
5
5
  end
@@ -16,6 +16,17 @@ RSpec.describe Carrierwave::Base64::Base64StringIO do
16
16
  it 'should respond to :original_filename' do
17
17
  expect(subject.original_filename).to eql("file.#{file_format}")
18
18
  end
19
+
20
+ it 'calls a function that returns the file_name' do
21
+ method = -> { 'file-name-through-method' }
22
+ model = described_class.new data, method
23
+ expect(model.file_name).to eql('file-name-through-method')
24
+ end
25
+
26
+ it 'accepts a string as the file name as well' do
27
+ model = described_class.new data, 'string-file-name'
28
+ expect(model.file_name).to eql('string-file-name')
29
+ end
19
30
  end
20
31
  end
21
32
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-base64
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
4
+ version: 2.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yury Lebedev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-30 00:00:00.000000000 Z
11
+ date: 2016-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  version: '0'
187
187
  requirements: []
188
188
  rubyforge_project:
189
- rubygems_version: 2.5.1
189
+ rubygems_version: 2.5.2
190
190
  signing_key:
191
191
  specification_version: 4
192
192
  summary: Upload images encoded as base64 to carrierwave.