uploadcare-rails 3.4.3 → 3.4.4

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: 2138498faa17ca9479a74350760f49ac47057937a5863015aa15c9232f4fb7cc
4
- data.tar.gz: cec22cbf947bf7fb913f1a8d682e6b88e6523854e6df7240482b9bbaaf6e6bc6
3
+ metadata.gz: 84a1955833b6989dafad0bcd3bbfd9186c84f619f75949aa972e007f480b7483
4
+ data.tar.gz: e2a813f07691e21d11877e6cc5926dbd03b8ddeca5d7bc6e86445316ba71fe12
5
5
  SHA512:
6
- metadata.gz: be25b79f736dcd797f40a366f703cb62b78fa314ccd2352f4a5eb8a8660396f1b1253c638ec4f5a3be750ef26326148f65ffefee6755d054db04484fb5dbc597
7
- data.tar.gz: 47762243287e5bf267f645b67f69b89d9083560d3c9ae55899c918487df5994be0725c7a1168634bc96072a21db13ce485b4ea1f344c7421b1003e504da5822d
6
+ metadata.gz: 5e4192606fb0d70db16c9ac22da5bf44bd42fc2b2b597fbb8445e4f8e9479d03aa523474ef456e48530192807c548c556ad7137d4e0e652d79981dd1173b857c
7
+ data.tar.gz: d9d15fd8e45b9dcc557a216fcba5947b7b33f2b3adbdb7e4009f06a1056b86eb15c1bd0a6e9f9911a86da031eb4844d4f59e0cb1e1edd3ef4d5fee4e35f7c73c
data/CHANGELOG.md CHANGED
@@ -4,14 +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
+
7
17
  ## 3.4.3 — 2024-06-01
8
18
 
9
19
  ### Added
20
+
10
21
  * For `Uploadcare::ConversionApi` added `get_document_conversion_formats_info` method to get the possible document conversion formats.
11
22
 
12
23
  ## 3.4.2 — 2024-05-11
13
24
 
14
25
  ### Added
26
+
15
27
  * Added API support for `AWS Rekognition Moderation` Add-On.
16
28
 
17
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:
@@ -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.3'
5
+ VERSION = '3.4.4'
6
6
  end
7
7
  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.3
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-06-02 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
@@ -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