resizing 0.8.3.pre → 1.1.0.pre

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
  SHA256:
3
- metadata.gz: 8351713d4b33f84d7bff196edaa7a842ba34cb157a56aa652067b003cc459b3d
4
- data.tar.gz: d40a7f4d588283bc1535ed5f31f94f592e86430a8fb7724554b9ec502067071a
3
+ metadata.gz: 2d601d6b8f87f6440de0c1c4d4dcbb74e7bc386dd3e217b66b8ac259d35939f0
4
+ data.tar.gz: 3f2ce39dcb8879dee7a9717142bfa794e6cad5671e19cdd01afbb5f7dacc6787
5
5
  SHA512:
6
- metadata.gz: 2d015cf9ce5e436630618fa540523b3fe8449060844938eaf3d3ea5b455c1cede10a0993a80c2b90c967da2e3399e79837001ca4f315fee3694db0e657c8ebf0
7
- data.tar.gz: 4fdefce63e3f9cdc5c6629fdf769928a6ca030b2715398df4a0ddb1ac09ca1492dd25a414f2b8e7750d591e92b86fa66c2394433dbcd4ba69dfaa8d33a573600
6
+ metadata.gz: c221c9290ccf562d804bb9f5dca6657568c891ce4c14d825fb8a19627feec1982c09773bfb55304cd5a13b8c4bb786a57d1abe3589684da312fd0167ecfc9a28
7
+ data.tar.gz: ee2dde3b29accd86dae059daf0e164fef634476886fb254b2145e3be33764d3a81308d9eea382a557817951714cbc8d4e98b02318417042a38590a4109334630
@@ -0,0 +1,56 @@
1
+ name: test
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - master
8
+
9
+ permissions:
10
+ id-token: write # This is required for requesting the JWT
11
+ contents: read # This is required for actions/checkout
12
+
13
+ jobs:
14
+ test:
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ ruby: ['2.7.6', '3.1', '3.2','3.3']
19
+
20
+ runs-on: ubuntu-22.04
21
+
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+
25
+ - uses: mirromutth/mysql-action@v1.1
26
+ with:
27
+ host port: 3306
28
+ container port: 3306
29
+ character set server: 'utf8mb4'
30
+ collation server: 'utf8mb4_general_ci'
31
+ mysql version: '5.7'
32
+ mysql database: 'resizing_gem_test'
33
+ mysql root password: secret
34
+
35
+ - name: "Install ruby dependencies"
36
+ run: |
37
+ sudo apt update
38
+ sudo apt install -y libyaml-dev curl libmysqlclient-dev
39
+
40
+ - uses: ruby/setup-ruby@v1
41
+ with:
42
+ ruby-version: ${{ matrix.ruby }}
43
+ bundler-cache: false
44
+
45
+ - name: bundle install
46
+ run: |
47
+ bundle install
48
+
49
+ - name: Run test
50
+ run: |
51
+ bundle exec rake test
52
+
53
+ - name: Upload coverage reports to Codecov
54
+ uses: codecov/codecov-action@v3
55
+ env:
56
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
@@ -6,15 +6,16 @@ module Resizing
6
6
  class File
7
7
  include ::CarrierWave::Utilities::Uri
8
8
 
9
+ attr_reader :public_id
10
+
9
11
  def initialize(uploader, identifier = nil)
10
12
  @uploader = uploader
11
- @file = nil
12
13
  @content_type = nil
13
- @public_id = Resizing::PublicId.new identifier
14
+ @public_id = Resizing::PublicId.new(identifier)
15
+ @file = nil
16
+ @metadata = nil
14
17
  end
15
18
 
16
- attr_reader :public_id
17
-
18
19
  def attributes
19
20
  file.attributes
20
21
  end
@@ -112,6 +113,7 @@ module Resizing
112
113
 
113
114
  @response = Resizing.post(content, { content_type: @content_type, filename: original_filename })
114
115
  @public_id = Resizing::PublicId.new(@response['public_id'])
116
+ @content_type = @response['content_type']
115
117
 
116
118
  # force update column
117
119
  # model_class
@@ -133,6 +135,9 @@ module Resizing
133
135
  # CarrierWave::Storage::Fog::File.new(@uploader, @base, new_path)
134
136
  # end
135
137
 
138
+ def retrieve(identifier)
139
+ @public_id = Resizing::PublicId.new(identifier)
140
+ end
136
141
  private
137
142
 
138
143
  attr_reader :uploader
@@ -190,14 +195,6 @@ module Resizing
190
195
  parameters.count == 2 && parameters[1].include?(:options)
191
196
  end
192
197
 
193
- def retrieve!(identifier)
194
- raise NotImplementedError, "retrieve! #{identifier}"
195
- end
196
-
197
- # def cache!(new_file)
198
- # raise NotImplementedError,
199
- # "Need to implement #cache! if you want to use #{self.class.name} as a cache storage."
200
- # end
201
198
 
202
199
  # def retrieve_from_cache!(identifier)
203
200
  # raise NotImplementedError,
@@ -9,20 +9,18 @@ module Resizing
9
9
  def store!(file)
10
10
  f = Resizing::CarrierWave::Storage::File.new(uploader)
11
11
  f.store(file)
12
- @filename = f.public_id.to_s
13
12
  f
14
13
  end
15
14
 
16
15
  def remove!(file)
17
16
  f = Resizing::CarrierWave::Storage::File.new(uploader)
18
17
  f.delete(file)
19
- @filename = f.public_id.to_s
20
18
  f
21
19
  end
22
20
 
23
- def retrieve!(identifier)
24
- Resizing::CarrierWave::Storage::File.new(uploader, identifier)
25
- end
21
+ # def retrieve!(identifier)
22
+ # super
23
+ # end
26
24
 
27
25
  def cache!(new_file)
28
26
  f = Resizing::CarrierWave::Storage::File.new(uploader)
@@ -31,6 +31,15 @@ module Resizing
31
31
  super
32
32
  end
33
33
 
34
+ def file
35
+ return if identifier.nil?
36
+ return @file unless defined? @file
37
+
38
+ @file ||= Resizing::CarrierWave::Storage::File.new(self)
39
+ @file.retrieve(identifier)
40
+ @file
41
+ end
42
+
34
43
  def url(*args)
35
44
  return default_url unless read_column.present?
36
45
 
@@ -39,14 +39,11 @@ module Resizing
39
39
 
40
40
  def post(file_or_binary, options = {})
41
41
  ensure_content_type(options)
42
-
43
- url = build_post_url
44
-
45
42
  filename = gather_filename file_or_binary, options
46
43
 
47
- body = to_io(file_or_binary)
44
+ url = build_post_url
48
45
  params = {
49
- image: Faraday::UploadIO.new(body, options[:content_type], filename)
46
+ image: Faraday::Multipart::FilePart.new(file_or_binary, options[:content_type], filename)
50
47
  }
51
48
 
52
49
  response = handle_faraday_error do
@@ -61,14 +58,11 @@ module Resizing
61
58
 
62
59
  def put(image_id, file_or_binary, options)
63
60
  ensure_content_type(options)
64
-
65
- url = build_put_url(image_id)
66
-
67
61
  filename = gather_filename file_or_binary, options
68
62
 
69
- body = to_io(file_or_binary)
63
+ url = build_put_url(image_id)
70
64
  params = {
71
- image: Faraday::UploadIO.new(body, options[:content_type], filename)
65
+ image: Faraday::Multipart::FilePart.new(file_or_binary, options[:content_type], filename)
72
66
  }
73
67
 
74
68
  response = handle_faraday_error do
@@ -103,7 +97,7 @@ module Resizing
103
97
  end
104
98
  end
105
99
 
106
- result = handle_metadata_response(response)
100
+ result = handle_metadata_response(response, options)
107
101
  result
108
102
  end
109
103
 
@@ -134,24 +128,12 @@ module Resizing
134
128
  "#{config.image_host}/projects/#{config.project_id}/upload/images/#{image_id}/metadata"
135
129
  end
136
130
 
137
-
138
- def to_io(data)
139
- return data.to_io if data.respond_to? :to_io
140
-
141
- case data
142
- when String
143
- StringIO.new(data)
144
- else
145
- raise ArgumentError, "file_or_binary is required IO class or String:#{data.class}"
146
- end
147
- end
148
-
149
131
  def ensure_content_type(options)
150
132
  raise ArgumentError, "need options[:content_type] for #{options.inspect}" unless options[:content_type]
151
133
  end
152
134
 
153
135
  def handle_create_response(response)
154
- raise APIError, "no response is returned" if response.nil?
136
+ raise APIError, "No response is returned" if response.nil?
155
137
 
156
138
  case response.status
157
139
  when HTTP_STATUS_OK, HTTP_STATUS_CREATED
@@ -162,7 +144,7 @@ module Resizing
162
144
  end
163
145
 
164
146
  def handle_delete_response(response)
165
- raise APIError, "no response is returned" if response.nil?
147
+ raise APIError, "No response is returned" if response.nil?
166
148
 
167
149
  case response.status
168
150
  when HTTP_STATUS_OK, HTTP_STATUS_NOT_FOUND
@@ -172,12 +154,17 @@ module Resizing
172
154
  end
173
155
  end
174
156
 
175
- def handle_metadata_response(response)
176
- raise APIError, "no response is returned" if response.nil?
157
+ def handle_metadata_response(response, options = {})
158
+ when_not_found = options[:when_not_found] || nil
159
+
160
+ raise APIError, "No response is returned" if response.nil?
177
161
 
178
162
  case response.status
179
163
  when HTTP_STATUS_OK, HTTP_STATUS_NOT_FOUND
180
164
  JSON.parse(response.body)
165
+ when HTTP_STATUS_NOT_FOUND
166
+ raise decode_error_from(response) if when_not_found == :raise
167
+ nil
181
168
  else
182
169
  raise decode_error_from(response)
183
170
  end
@@ -103,8 +103,12 @@ module Resizing
103
103
  end
104
104
 
105
105
  def initialize_by_hash(attr)
106
- # @host = attr[:host].dup.freeze || DEFAULT_HOST
107
106
  @image_host = attr[:image_host].dup.freeze || DEFAULT_IMAGE_HOST
107
+ if attr[:host].present?
108
+ Kernel.warn "[DEPRECATED] The host on configration is deprecated. Use image_host, video_host" if attr[:host].present?
109
+ @image_host ||= attr[:host].dup.freeze || DEFAULT_HOST # for backward compatible
110
+ end
111
+
108
112
  @video_host = attr[:video_host].dup.freeze || DEFAULT_VIDEO_HOST
109
113
  @project_id = attr[:project_id].dup.freeze
110
114
  @secret_token = attr[:secret_token].dup.freeze
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Resizing
4
- VERSION = '0.8.3.pre'
4
+ VERSION = '1.1.0.pre'
5
5
  end
data/lib/resizing.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'resizing/version'
4
4
  require 'faraday'
5
+ require 'faraday/multipart'
5
6
  require 'json'
6
7
 
7
8
  module Resizing
data/resizing.gemspec CHANGED
@@ -28,13 +28,17 @@ Gem::Specification.new do |spec|
28
28
  spec.bindir = 'exe'
29
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ['lib']
31
- spec.add_runtime_dependency 'faraday', '>= 1.0.1', '< 1.4.0'
32
- spec.add_development_dependency 'carrierwave', '~> 2.2.0'
31
+ spec.add_runtime_dependency 'faraday', '~> 2.3'
32
+ spec.add_runtime_dependency 'faraday-multipart'
33
+ spec.add_development_dependency 'rails', '~> 6.0'
34
+ spec.add_development_dependency 'carrierwave', '~> 2.2.5'
33
35
  spec.add_development_dependency 'fog-aws'
34
36
  spec.add_development_dependency 'minitest'
35
37
  spec.add_development_dependency 'minitest-ci'
36
- spec.add_development_dependency 'rails', '~> 5.2.3'
37
38
  spec.add_development_dependency 'rubocop'
38
39
  spec.add_development_dependency 'timecop'
39
40
  spec.add_development_dependency 'vcr'
41
+ spec.add_development_dependency 'mysql2'
42
+ spec.add_development_dependency 'simplecov'
43
+ spec.add_development_dependency 'simplecov-cobertura'
40
44
  end
data/test/test_helper.rb CHANGED
@@ -1,4 +1,22 @@
1
1
  # frozen_string_literal: true
2
+ require 'simplecov'
3
+ require 'simplecov-cobertura'
4
+
5
+ SimpleCov.start do
6
+ add_filter "/test/"
7
+
8
+ if ENV['CI']
9
+ formatter SimpleCov::Formatter::CoberturaFormatter
10
+ else
11
+ formatter SimpleCov::Formatter::MultiFormatter.new([
12
+ SimpleCov::Formatter::SimpleFormatter,
13
+ SimpleCov::Formatter::HTMLFormatter
14
+ ])
15
+ end
16
+
17
+ enable_coverage :branch
18
+ primary_coverage :branch
19
+ end
2
20
 
3
21
  $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
22
  require 'time'
metadata CHANGED
@@ -1,49 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resizing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3.pre
4
+ version: 1.1.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Junichiro Kasuya
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-08 00:00:00.000000000 Z
11
+ date: 2024-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
18
25
  - !ruby/object:Gem::Version
19
- version: 1.0.1
20
- - - "<"
26
+ version: '2.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday-multipart
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
21
32
  - !ruby/object:Gem::Version
22
- version: 1.4.0
33
+ version: '0'
23
34
  type: :runtime
24
35
  prerelease: false
25
36
  version_requirements: !ruby/object:Gem::Requirement
26
37
  requirements:
27
38
  - - ">="
28
39
  - !ruby/object:Gem::Version
29
- version: 1.0.1
30
- - - "<"
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '6.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
31
53
  - !ruby/object:Gem::Version
32
- version: 1.4.0
54
+ version: '6.0'
33
55
  - !ruby/object:Gem::Dependency
34
56
  name: carrierwave
35
57
  requirement: !ruby/object:Gem::Requirement
36
58
  requirements:
37
59
  - - "~>"
38
60
  - !ruby/object:Gem::Version
39
- version: 2.2.0
61
+ version: 2.2.5
40
62
  type: :development
41
63
  prerelease: false
42
64
  version_requirements: !ruby/object:Gem::Requirement
43
65
  requirements:
44
66
  - - "~>"
45
67
  - !ruby/object:Gem::Version
46
- version: 2.2.0
68
+ version: 2.2.5
47
69
  - !ruby/object:Gem::Dependency
48
70
  name: fog-aws
49
71
  requirement: !ruby/object:Gem::Requirement
@@ -87,21 +109,21 @@ dependencies:
87
109
  - !ruby/object:Gem::Version
88
110
  version: '0'
89
111
  - !ruby/object:Gem::Dependency
90
- name: rails
112
+ name: rubocop
91
113
  requirement: !ruby/object:Gem::Requirement
92
114
  requirements:
93
- - - "~>"
115
+ - - ">="
94
116
  - !ruby/object:Gem::Version
95
- version: 5.2.3
117
+ version: '0'
96
118
  type: :development
97
119
  prerelease: false
98
120
  version_requirements: !ruby/object:Gem::Requirement
99
121
  requirements:
100
- - - "~>"
122
+ - - ">="
101
123
  - !ruby/object:Gem::Version
102
- version: 5.2.3
124
+ version: '0'
103
125
  - !ruby/object:Gem::Dependency
104
- name: rubocop
126
+ name: timecop
105
127
  requirement: !ruby/object:Gem::Requirement
106
128
  requirements:
107
129
  - - ">="
@@ -115,7 +137,7 @@ dependencies:
115
137
  - !ruby/object:Gem::Version
116
138
  version: '0'
117
139
  - !ruby/object:Gem::Dependency
118
- name: timecop
140
+ name: vcr
119
141
  requirement: !ruby/object:Gem::Requirement
120
142
  requirements:
121
143
  - - ">="
@@ -129,7 +151,35 @@ dependencies:
129
151
  - !ruby/object:Gem::Version
130
152
  version: '0'
131
153
  - !ruby/object:Gem::Dependency
132
- name: vcr
154
+ name: mysql2
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: simplecov-cobertura
133
183
  requirement: !ruby/object:Gem::Requirement
134
184
  requirements:
135
185
  - - ">="
@@ -145,11 +195,14 @@ dependencies:
145
195
  description: 'Client and utilities for Resizing '
146
196
  email:
147
197
  - junichiro.kasuya@gmail.com
148
- executables: []
198
+ executables:
199
+ - console
200
+ - generate-changelog
201
+ - setup
149
202
  extensions: []
150
203
  extra_rdoc_files: []
151
204
  files:
152
- - ".circleci/config.yml"
205
+ - ".github/workflows/test.yml"
153
206
  - ".gitignore"
154
207
  - ".rubocop.yml"
155
208
  - CHANGELOG.md
@@ -157,10 +210,10 @@ files:
157
210
  - LICENSE.txt
158
211
  - README.md
159
212
  - Rakefile
160
- - bin/console
161
- - bin/generate-changelog
162
- - bin/setup
163
213
  - docker-compose.yml
214
+ - exe/console
215
+ - exe/generate-changelog
216
+ - exe/setup
164
217
  - lib/resizing.rb
165
218
  - lib/resizing/active_storage/service/resizing_service.rb
166
219
  - lib/resizing/carrier_wave.rb
@@ -220,7 +273,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
273
  - !ruby/object:Gem::Version
221
274
  version: 1.3.1
222
275
  requirements: []
223
- rubygems_version: 3.0.3
276
+ rubygems_version: 3.1.6
224
277
  signing_key:
225
278
  specification_version: 4
226
279
  summary: Client and utilities for Resizing
data/.circleci/config.yml DELETED
@@ -1,71 +0,0 @@
1
- version: 2
2
-
3
- jobs:
4
- build:
5
- docker:
6
- - image: circleci/ruby:2.6.2-node
7
- environment:
8
- BUNDLE_JOBS: 4
9
- BUNDLE_RETRY: 3
10
- BUNDLE_PATH: vendor/bundle
11
- BUNDLE_APP_CONFIG: "./.bundle"
12
- TZ: /usr/share/zoneinfo/Asia/Tokyo
13
- LANG: ja_JP.UTF8
14
- - image: circleci/mysql:5.7
15
- environment:
16
- MYSQL_ROOT_PASSWORD: secret
17
- MYSQL_DATABASE: resizing_gem_test
18
- MYSQL_USER: resizing_gem
19
- MYSQL_PASSWORD: secret
20
- TZ: /usr/share/zoneinfo/Asia/Tokyo
21
- LANG: ja_JP.UTF8
22
- command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_bin
23
-
24
- steps:
25
- - checkout
26
- - run:
27
- name: Which bundler?
28
- command: |
29
- bundle -v
30
- bundle config
31
-
32
- - restore_cache:
33
- keys:
34
- - v2-{{ .Environment.CACHE_KEY }}-gem-cache-{{ arch }}-{{ .Branch }}
35
- - v2-{{ .Environment.CACHE_KEY }}-gem-cache
36
-
37
- - run:
38
- name: reinstall rake && bundle install
39
- command: |
40
- sudo gem install bundler
41
- sudo gem uninstall -x rake
42
- echo "install: --no-document" >> ~/.gemrc
43
- bundle check --path vendor/bundle || bundle install --path vendor/bundle --clean
44
-
45
- - save_cache:
46
- key: v2-{{ .Environment.CACHE_KEY }}-gem-cache-{{ arch }}-{{ .Branch }}
47
- paths:
48
- - vendor/bundle
49
-
50
- - run:
51
- name: connectable MySQL?
52
- command: |
53
- dockerize -wait tcp://127.0.0.1:3306 -timeout 1m
54
-
55
- # - run:
56
- # name: rubocop
57
- # command: bundle exec rubocop --parallel
58
- # - run:
59
- # name: brakeman
60
- # command: bundle exec brakeman --no-exit-on-error -w 1 -z
61
- - run:
62
- command: bundle exec rake test
63
- when: always
64
- - store_test_results:
65
- path: test/reports
66
-
67
- workflows:
68
- version: 2
69
- build-deploy:
70
- jobs:
71
- - build
File without changes
File without changes
/data/{bin → exe}/setup RENAMED
File without changes