uploadcare-rails 3.4.2 → 3.4.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c3752eab2d238aab90af10d0bea8e9c7a14c3aba55909529a27c9c1e20cfb60d
4
- data.tar.gz: a49e6107cb976f4c38fe5f7dc7f92a637e25e1c3ef14fb794aa3ecd730fef1e9
3
+ metadata.gz: 84a1955833b6989dafad0bcd3bbfd9186c84f619f75949aa972e007f480b7483
4
+ data.tar.gz: e2a813f07691e21d11877e6cc5926dbd03b8ddeca5d7bc6e86445316ba71fe12
5
5
  SHA512:
6
- metadata.gz: '09a704803fdf183ed4a0656ad2e33f18b6586cba8cd8112041c3cd35ee1d8220afe04d870d18faafa32fed468c3593e8a34f0a1f6cc1c788b96556589c7c83e1'
7
- data.tar.gz: 79f55a729a8989feff52dca3db695edf6f410f23a60df6dbeff883b7d17a8b705c948e8427deb2a32f698df936c540f946125971b357320c9c657623a76fb5d3
6
+ metadata.gz: 5e4192606fb0d70db16c9ac22da5bf44bd42fc2b2b597fbb8445e4f8e9479d03aa523474ef456e48530192807c548c556ad7137d4e0e652d79981dd1173b857c
7
+ data.tar.gz: d9d15fd8e45b9dcc557a216fcba5947b7b33f2b3adbdb7e4009f06a1056b86eb15c1bd0a6e9f9911a86da031eb4844d4f59e0cb1e1edd3ef4d5fee4e35f7c73c
data/CHANGELOG.md CHANGED
@@ -4,9 +4,26 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based now on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## 3.4.4 — 2024-11-07
8
+
9
+ ### Added
10
+
11
+ * Add mongoid support for `mount_uploadcare_file` and `mount_uploadcare_file_group` methods.
12
+
13
+ ### Breaking Changes
14
+
15
+ * Drop support for Rails 6.1x in line with the currently supported Rails versions: https://rubyonrails.org/maintenance
16
+
17
+ ## 3.4.3 — 2024-06-01
18
+
19
+ ### Added
20
+
21
+ * For `Uploadcare::ConversionApi` added `get_document_conversion_formats_info` method to get the possible document conversion formats.
22
+
7
23
  ## 3.4.2 — 2024-05-11
8
24
 
9
25
  ### Added
26
+
10
27
  * Added API support for `AWS Rekognition Moderation` Add-On.
11
28
 
12
29
  ## 3.4.1 — 2024-03-24
data/Gemfile CHANGED
@@ -7,8 +7,12 @@ gemspec
7
7
 
8
8
  gem 'http-parser', '~> 1.2', '>= 1.2.3'
9
9
  gem 'rake', '~> 13.0.6'
10
- gem 'rspec', '~> 3.12'
11
- gem 'rspec-rails', '>= 5.1'
12
- gem 'rubocop', '~> 1.48'
13
- gem 'vcr', '~> 6.1'
14
- gem 'webmock', '~> 3.18'
10
+
11
+ group :test do
12
+ gem 'mongoid', '~> 9', require: false
13
+ gem 'rspec', '~> 3.12'
14
+ gem 'rspec-rails', '>= 5.1'
15
+ gem 'rubocop', '~> 1.48'
16
+ gem 'vcr', '~> 6.1'
17
+ gem 'webmock', '~> 3.18'
18
+ end
data/README.md CHANGED
@@ -333,6 +333,8 @@ document.addEventListener('turbo:before-cache', function() {
333
333
  When you mount either Uploadcare File or Group to an attribute, this attribute is getting wrapped with
334
334
  a Uploadcare object. This feature adds some useful methods to the attribute.
335
335
 
336
+ Note: Supports ActiveRecord, ActiveModel and Mongoid models.
337
+
336
338
  #### Uploadcare File
337
339
 
338
340
  Say, you have such model in your Rails app:
@@ -21,6 +21,12 @@ module Uploadcare
21
21
  Uploadcare::VideoConverter.status(token)
22
22
  end
23
23
 
24
+ # Conversion formats info
25
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Conversion/operation/documentConvertInfo
26
+ def get_document_conversion_formats_info(uuid)
27
+ Uploadcare::DocumentConverter.info(uuid)
28
+ end
29
+
24
30
  # Converts documents
25
31
  # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/documentConvert
26
32
  def convert_document(document_params, options = {})
@@ -20,6 +20,13 @@ module Uploadcare
20
20
  require 'uploadcare/rails/active_record/mount_uploadcare_file'
21
21
  require 'uploadcare/rails/active_record/mount_uploadcare_file_group'
22
22
  end
23
+
24
+ # Load extensions for mongoid
25
+ # Extend mongoid with mount_uploadcare_file and mount_uploadcare_file_group methods
26
+ ActiveSupport.on_load :mongoid do
27
+ require 'uploadcare/rails/mongoid/mount_uploadcare_file'
28
+ require 'uploadcare/rails/mongoid/mount_uploadcare_file_group'
29
+ end
23
30
  end
24
31
  end
25
32
  end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mongoid'
4
+ require 'active_support/concern'
5
+ require 'uploadcare/rails/services/id_extractor'
6
+ require 'uploadcare/rails/jobs/delete_file_job'
7
+ require 'uploadcare/rails/jobs/store_file_job'
8
+ require 'uploadcare/rails/objects/file'
9
+
10
+ module Uploadcare
11
+ module Rails
12
+ module Mongoid
13
+ # A module containing Mongoid extension. Allows using uploadcare file methods in Mongoid models
14
+ module MountUploadcareFile
15
+ extend ActiveSupport::Concern
16
+
17
+ def build_uploadcare_file(attribute)
18
+ cdn_url = read_attribute(attribute).to_s
19
+ return if cdn_url.empty?
20
+
21
+ uuid = IdExtractor.call(cdn_url)
22
+ cache_key = File.build_cache_key(cdn_url)
23
+ default_attributes = { cdn_url: cdn_url, uuid: uuid.presence }
24
+ file_attributes = ::Rails.cache.read(cache_key).presence || default_attributes
25
+ Uploadcare::Rails::File.new(file_attributes)
26
+ end
27
+
28
+ class_methods do
29
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
30
+ def mount_uploadcare_file(attribute)
31
+ define_method attribute do
32
+ build_uploadcare_file(attribute)
33
+ end
34
+
35
+ define_method "uploadcare_store_#{attribute}!" do |store_job = StoreFileJob|
36
+ file_uuid = public_send(attribute)&.uuid
37
+ return unless file_uuid
38
+ return store_job.perform_later(file_uuid) if Uploadcare::Rails.configuration.store_files_async
39
+
40
+ Uploadcare::FileApi.store_file(file_uuid)
41
+ end
42
+
43
+ define_method "uploadcare_delete_#{attribute}!" do |delete_job = DeleteFileJob|
44
+ file_uuid = public_send(attribute)&.uuid
45
+ return unless file_uuid
46
+ return delete_job.perform_later(file_uuid) if Uploadcare::Rails.configuration.delete_files_async
47
+
48
+ Uploadcare::FileApi.delete_file(file_uuid)
49
+ end
50
+
51
+ unless Uploadcare::Rails.configuration.do_not_store
52
+ set_callback(:save, :after, :"uploadcare_store_#{attribute}!", if: :"#{attribute}_changed?")
53
+ end
54
+
55
+ return unless Uploadcare::Rails.configuration.delete_files_after_destroy
56
+
57
+ set_callback(:destroy, :after, :"uploadcare_delete_#{attribute}!")
58
+ end
59
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ Mongoid::Document.include Uploadcare::Rails::Mongoid::MountUploadcareFile
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mongoid'
4
+ require 'active_support/concern'
5
+ require 'uploadcare/rails/services/id_extractor'
6
+ require 'uploadcare/rails/services/files_count_extractor'
7
+ require 'uploadcare/rails/jobs/store_group_job'
8
+ require 'uploadcare/rails/objects/group'
9
+
10
+ module Uploadcare
11
+ module Rails
12
+ module Mongoid
13
+ # A module containing Mongoid extension. Allows to use uploadcare group methods in Rails models
14
+ module MountUploadcareFileGroup
15
+ extend ActiveSupport::Concern
16
+
17
+ GROUP_ID_REGEX = /\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b~\d+/.freeze
18
+
19
+ def build_uploadcare_file_group(attribute)
20
+ cdn_url = read_attribute(attribute).to_s
21
+ return if cdn_url.empty?
22
+
23
+ group_id = IdExtractor.call(cdn_url, GROUP_ID_REGEX).presence
24
+ cache_key = Group.build_cache_key(cdn_url)
25
+ files_count = FilesCountExtractor.call(group_id)
26
+ default_attributes = { cdn_url: cdn_url, id: group_id, files_count: files_count }
27
+ file_attributes = ::Rails.cache.read(cache_key).presence || default_attributes
28
+ Uploadcare::Rails::Group.new(file_attributes)
29
+ end
30
+
31
+ class_methods do
32
+ # rubocop:disable Metrics/MethodLength
33
+ def mount_uploadcare_file_group(attribute)
34
+ define_singleton_method "has_uploadcare_file_group_for_#{attribute}?" do
35
+ true
36
+ end
37
+
38
+ define_method attribute do
39
+ build_uploadcare_file_group attribute
40
+ end
41
+
42
+ define_method "uploadcare_store_#{attribute}!" do |store_job = StoreGroupJob|
43
+ group_id = public_send(attribute)&.id
44
+ return unless group_id
45
+ return store_job.perform_later(group_id) if Uploadcare::Rails.configuration.store_files_async
46
+
47
+ Uploadcare::GroupApi.store_group(group_id)
48
+ end
49
+
50
+ return if Uploadcare::Rails.configuration.do_not_store
51
+
52
+ set_callback :save, :after, :"uploadcare_store_#{attribute}!"
53
+ end
54
+ # rubocop:enable Metrics/MethodLength
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ Mongoid::Document.include Uploadcare::Rails::Mongoid::MountUploadcareFileGroup
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_record'
3
+ require 'active_model'
4
4
 
5
5
  module Uploadcare
6
6
  module Rails
@@ -8,7 +8,7 @@ module Uploadcare
8
8
  # A module that contains methods for attribute assignation and caching
9
9
  module Loadable
10
10
  extend ActiveSupport::Concern
11
- include ::ActiveRecord::AttributeAssignment
11
+ include ActiveModel::AttributeAssignment
12
12
 
13
13
  class_methods do
14
14
  def build_cache_key(key)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Uploadcare
4
4
  module Rails
5
- VERSION = '3.4.2'
5
+ VERSION = '3.4.4'
6
6
  end
7
7
  end
@@ -44,5 +44,5 @@ Gem::Specification.new do |gem|
44
44
 
45
45
  gem.version = Uploadcare::Rails::VERSION
46
46
  gem.add_dependency 'rails', '>= 6'
47
- gem.add_dependency 'uploadcare-ruby', '>= 4.4.1'
47
+ gem.add_dependency 'uploadcare-ruby', '>= 4.4.2'
48
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uploadcare-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.2
4
+ version: 3.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - "@dmitrijivanchenko (Dmitrij Ivanchenko), @T0mbery (Andrey Aksenov)"
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-05-19 00:00:00.000000000 Z
12
+ date: 2024-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 4.4.1
34
+ version: 4.4.2
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: 4.4.1
41
+ version: 4.4.2
42
42
  description: |
43
43
  Rails API client (based on uploadcare-ruby) that handles uploads
44
44
  and further operations with files by wrapping Uploadcare Upload and REST APIs.
@@ -79,6 +79,8 @@ files:
79
79
  - lib/uploadcare/rails/jobs/delete_file_job.rb
80
80
  - lib/uploadcare/rails/jobs/store_file_job.rb
81
81
  - lib/uploadcare/rails/jobs/store_group_job.rb
82
+ - lib/uploadcare/rails/mongoid/mount_uploadcare_file.rb
83
+ - lib/uploadcare/rails/mongoid/mount_uploadcare_file_group.rb
82
84
  - lib/uploadcare/rails/objects/concerns/loadable.rb
83
85
  - lib/uploadcare/rails/objects/file.rb
84
86
  - lib/uploadcare/rails/objects/group.rb