resizing 0.4.0 → 0.4.1
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 +4 -4
- data/lib/resizing/carrier_wave.rb +8 -3
- data/lib/resizing/carrier_wave/storage/file.rb +1 -1
- data/lib/resizing/client.rb +11 -2
- data/lib/resizing/version.rb +1 -1
- data/test/resizing/carrier_wave_test.rb +12 -0
- data/test/resizing/client_test.rb +1 -0
- data/test/test_helper.rb +21 -1
- data/test/vcr/client/post.yml +1 -1
- 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: 04cca28d70c6c4c7a361ae5714aadb8e0983a77827b7099ca3dcb18d60e41052
|
4
|
+
data.tar.gz: 653e75727cbeb23d3b9f799b9547df92010410b7f409d671bfaea529325060db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f6395295e817926af6f50fdf66817c97beac4b9e4efbd9ffede1cfb597567ca43a56615a777ae333a96e841aac62f20b4804918f542dc8cf42a57c59c8e8433
|
7
|
+
data.tar.gz: b7368beeae3086929f303100059122f9310e18b9bbe6c2503d5d8cb11994272d5e95e480870a4a6a513162db5a87a247ccc785d1dec21dac731bd462ce7881c2
|
@@ -32,7 +32,7 @@ module Resizing
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def url(*args)
|
35
|
-
return
|
35
|
+
return default_url unless read_column.present?
|
36
36
|
|
37
37
|
transforms = args.map do |version|
|
38
38
|
version = version.intern
|
@@ -40,17 +40,22 @@ module Resizing
|
|
40
40
|
versions[version].transform_string
|
41
41
|
end.compact
|
42
42
|
|
43
|
-
"#{
|
43
|
+
"#{build_url}/#{transforms.join('/')}"
|
44
44
|
end
|
45
45
|
|
46
46
|
def read_column
|
47
47
|
model.read_attribute(serialization_column)
|
48
48
|
end
|
49
49
|
|
50
|
-
def
|
50
|
+
def build_url
|
51
51
|
"#{Resizing.configure.host}#{model.read_attribute(serialization_column)}"
|
52
52
|
end
|
53
53
|
|
54
|
+
# need override this. if you want to return some url when target_column is nil
|
55
|
+
def default_url
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
|
54
59
|
def transform_string
|
55
60
|
transforms = processors.map do |processor|
|
56
61
|
transform_string_from processor
|
@@ -96,7 +96,7 @@ module Resizing
|
|
96
96
|
@public_id.image_id
|
97
97
|
end
|
98
98
|
|
99
|
-
@response = Resizing.put(image_id, new_file.read, { content_type: @content_type })
|
99
|
+
@response = Resizing.put(image_id, new_file.read, { content_type: @content_type, filename: new_file.original_filename })
|
100
100
|
@public_id = Resizing::PublicId.new(@response['public_id'])
|
101
101
|
|
102
102
|
# force update column
|
data/lib/resizing/client.rb
CHANGED
@@ -50,9 +50,11 @@ module Resizing
|
|
50
50
|
|
51
51
|
url = build_post_url
|
52
52
|
|
53
|
+
filename = gather_filename file_or_binary, options
|
54
|
+
|
53
55
|
body = to_io(file_or_binary)
|
54
56
|
params = {
|
55
|
-
image: Faraday::UploadIO.new(body, options[:content_type])
|
57
|
+
image: Faraday::UploadIO.new(body, options[:content_type], filename)
|
56
58
|
}
|
57
59
|
|
58
60
|
response = http_client.post(url, params) do |request|
|
@@ -68,9 +70,11 @@ module Resizing
|
|
68
70
|
|
69
71
|
url = build_put_url(image_id)
|
70
72
|
|
73
|
+
filename = gather_filename file_or_binary, options
|
74
|
+
|
71
75
|
body = to_io(file_or_binary)
|
72
76
|
params = {
|
73
|
-
image: Faraday::UploadIO.new(body, options[:content_type])
|
77
|
+
image: Faraday::UploadIO.new(body, options[:content_type], filename)
|
74
78
|
}
|
75
79
|
|
76
80
|
response = http_client.put(url, params) do |request|
|
@@ -113,6 +117,11 @@ module Resizing
|
|
113
117
|
"#{config.host}/projects/#{config.project_id}/upload/images/"
|
114
118
|
end
|
115
119
|
|
120
|
+
def gather_filename file_or_binary, options
|
121
|
+
filename = options[:filename]
|
122
|
+
filename ||= file_or_binary.respond_to?(:path) ? File.basename(file_or_binary.path) : nil
|
123
|
+
end
|
124
|
+
|
116
125
|
def build_put_url(image_id)
|
117
126
|
"#{config.host}/projects/#{config.project_id}/upload/images/#{image_id}"
|
118
127
|
end
|
data/lib/resizing/version.rb
CHANGED
@@ -70,6 +70,18 @@ module Resizing
|
|
70
70
|
assert_equal('jpg', model.resizing_picture.format)
|
71
71
|
end
|
72
72
|
|
73
|
+
def test_url_is_return_default_url
|
74
|
+
model = TestModel.new
|
75
|
+
model.save!
|
76
|
+
assert_nil model.resizing_picture_url
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_url_is_return_default_url
|
80
|
+
model = TestModelWithDefaultURL.new
|
81
|
+
model.save!
|
82
|
+
assert_equal('http://example.com/test.jpg', model.resizing_picture_url)
|
83
|
+
end
|
84
|
+
|
73
85
|
def expect_url
|
74
86
|
'http://192.168.56.101:5000/projects/098a2a0d-c387-4135-a071-1254d6d7e70a/'+
|
75
87
|
'upload/images/28c49144-c00d-4cb5-8619-98ce95977b9c/v1Id850__tqNsnoGWWUibtIBZ5NgjV45M'
|
@@ -49,6 +49,7 @@ module Resizing
|
|
49
49
|
assert(!r['created_at'].nil?)
|
50
50
|
assert(!r['updated_at'].nil?)
|
51
51
|
assert_equal(r['public_id'], '/projects/098a2a0d-c387-4135-a071-1254d6d7e70a/upload/images/bfdaf2b3-7ec5-41f4-9caa-d53247dd9666/vAyWaxx96gLaAzB9Bq.VbX1_pxfXJ0Jcq')
|
52
|
+
assert_equal(r['filename'], 'sample1.jpg')
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
data/test/test_helper.rb
CHANGED
@@ -33,7 +33,7 @@ ActiveRecord::Base.establish_connection(
|
|
33
33
|
ActiveRecord::Schema.define do
|
34
34
|
self.verbose = false
|
35
35
|
|
36
|
-
%i(test_models test_jpg_models).each do |model_name|
|
36
|
+
%i(test_models test_jpg_models test_model_with_default_urls).each do |model_name|
|
37
37
|
connection.execute "drop table if exists #{model_name}"
|
38
38
|
|
39
39
|
create_table model_name do |t|
|
@@ -61,6 +61,20 @@ class ResizingJPGUploader < CarrierWave::Uploader::Base
|
|
61
61
|
def default_format
|
62
62
|
'jpg'
|
63
63
|
end
|
64
|
+
|
65
|
+
def default_url
|
66
|
+
'http://example.com/test.jpg'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class ResizingUploaderWithDefaultURL < CarrierWave::Uploader::Base
|
71
|
+
include Resizing::CarrierWave
|
72
|
+
|
73
|
+
process resize_to_limit: [1000]
|
74
|
+
|
75
|
+
def default_url
|
76
|
+
'http://example.com/test.jpg'
|
77
|
+
end
|
64
78
|
end
|
65
79
|
|
66
80
|
class TestModel < ::ActiveRecord::Base
|
@@ -74,3 +88,9 @@ class TestJPGModel < ::ActiveRecord::Base
|
|
74
88
|
|
75
89
|
mount_uploader :resizing_picture, ResizingJPGUploader
|
76
90
|
end
|
91
|
+
|
92
|
+
class TestModelWithDefaultURL < ::ActiveRecord::Base
|
93
|
+
extend CarrierWave::Mount
|
94
|
+
|
95
|
+
mount_uploader :resizing_picture, ResizingUploaderWithDefaultURL
|
96
|
+
end
|
data/test/vcr/client/post.yml
CHANGED
@@ -49,6 +49,6 @@ http_interactions:
|
|
49
49
|
- chunked
|
50
50
|
body:
|
51
51
|
encoding: UTF-8
|
52
|
-
string: '{"id":"bfdaf2b3-7ec5-41f4-9caa-d53247dd9666","project_id":"098a2a0d-c387-4135-a071-1254d6d7e70a","content_type":"image/jpeg","latest_version_id":"AyWaxx96gLaAzB9Bq.VbX1_pxfXJ0Jcq","latest_etag":"\"190143614e6c342637584f46f18f8c58\"","created_at":"2020-05-29T03:22:55.241Z","updated_at":"2020-05-29T03:22:55.241Z","public_id":"/projects/098a2a0d-c387-4135-a071-1254d6d7e70a/upload/images/bfdaf2b3-7ec5-41f4-9caa-d53247dd9666/vAyWaxx96gLaAzB9Bq.VbX1_pxfXJ0Jcq"}'
|
52
|
+
string: '{"id":"bfdaf2b3-7ec5-41f4-9caa-d53247dd9666","project_id":"098a2a0d-c387-4135-a071-1254d6d7e70a","content_type":"image/jpeg","latest_version_id":"AyWaxx96gLaAzB9Bq.VbX1_pxfXJ0Jcq","latest_etag":"\"190143614e6c342637584f46f18f8c58\"","created_at":"2020-05-29T03:22:55.241Z","updated_at":"2020-05-29T03:22:55.241Z","public_id":"/projects/098a2a0d-c387-4135-a071-1254d6d7e70a/upload/images/bfdaf2b3-7ec5-41f4-9caa-d53247dd9666/vAyWaxx96gLaAzB9Bq.VbX1_pxfXJ0Jcq","filename":"sample1.jpg"}'
|
53
53
|
recorded_at: Fri, 29 May 2020 03:22:55 GMT
|
54
54
|
recorded_with: VCR 6.0.0
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resizing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Junichiro Kasuya
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|