lazy_blob_storage 2.0.0.pre.beta.8 → 2.0.0.pre.beta.9
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/app/models/lazy_attachment.rb +45 -4
- data/lib/lazy_blob_storage/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0fbc67607315036a01e23d1d5eee5393fdc1de62d2e28a754a866f766dc1817
|
4
|
+
data.tar.gz: 2199b435b39f20882660afbed3f0d16d1fa83a0841fcb1ef228989975c1073f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23789bf445266bb7d56bb09602401cd6478ebfd74edbedf01a60c0d87b1395f7ec4a857065b2c919bc1ecfca43c12e54622833bfd549d21a9e36788c5b8a373c
|
7
|
+
data.tar.gz: 5c1fc717a604406792dcea3ab1529c55402f22fee86930d984da7061cac44aad359d5f4142037ef127ed18ef6afa7ff02c0096355c9116b9bd38f4f55f9739d6
|
@@ -1,4 +1,6 @@
|
|
1
1
|
class LazyAttachment < ActiveRecord::Base
|
2
|
+
Result = Struct.new(:ok?, :error)
|
3
|
+
|
2
4
|
belongs_to :lazy_blob, autosave: true
|
3
5
|
belongs_to :record, polymorphic: true
|
4
6
|
has_many :lazy_variants, dependent: :destroy
|
@@ -42,15 +44,54 @@ class LazyAttachment < ActiveRecord::Base
|
|
42
44
|
|
43
45
|
blob = LazyBlob.from_processed_variant(processed, name, format, lazy_blob)
|
44
46
|
|
45
|
-
variant =
|
46
|
-
name: name
|
47
|
-
lazy_blob: blob,
|
48
|
-
lazy_attachment: self
|
47
|
+
variant = lazy_variants.find_or_initialize_by(
|
48
|
+
name: name
|
49
49
|
)
|
50
|
+
variant.lazy_attachment = self
|
51
|
+
variant.lazy_blob = blob
|
50
52
|
|
51
53
|
variant.save!
|
52
54
|
end
|
53
55
|
|
56
|
+
def ensure_variant(name, x_size, y_size, format = "png")
|
57
|
+
unless lazy_blob.content_type.start_with?("image/")
|
58
|
+
return Result.new(false, "Not an image")
|
59
|
+
end
|
60
|
+
|
61
|
+
content_file = Tempfile.new("lazy_blob_content")
|
62
|
+
content_file.binmode
|
63
|
+
content_file.write(lazy_blob.content)
|
64
|
+
content_file.close
|
65
|
+
|
66
|
+
processed = ImageProcessing::MiniMagick
|
67
|
+
.source(content_file.path)
|
68
|
+
.resize_to_limit(x_size, y_size)
|
69
|
+
.convert(format)
|
70
|
+
.call
|
71
|
+
|
72
|
+
blob = LazyBlob.from_processed_variant(processed, name, format, lazy_blob)
|
73
|
+
|
74
|
+
variant = lazy_variants.find_or_initialize_by(
|
75
|
+
name: name
|
76
|
+
)
|
77
|
+
variant.lazy_attachment_id = id
|
78
|
+
variant.lazy_blob = blob
|
79
|
+
|
80
|
+
if variant.save
|
81
|
+
Result.new(true)
|
82
|
+
else
|
83
|
+
Result.new(false, errors.full_messages.join(", "))
|
84
|
+
end
|
85
|
+
rescue => e
|
86
|
+
Result.new(false, e.message)
|
87
|
+
end
|
88
|
+
|
89
|
+
def destroy_all_variants
|
90
|
+
blob_ids = lazy_variants.pluck(:lazy_blob_id)
|
91
|
+
lazy_variants.destroy_all
|
92
|
+
LazyBlob.where(id: blob_ids).destroy_all
|
93
|
+
end
|
94
|
+
|
54
95
|
def variant(name)
|
55
96
|
lazy_variants.find_by(name: name)
|
56
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazy_blob_storage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.pre.beta.
|
4
|
+
version: 2.0.0.pre.beta.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corey Smedstad
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
154
|
- !ruby/object:Gem::Version
|
155
155
|
version: 1.3.1
|
156
156
|
requirements: []
|
157
|
-
rubygems_version: 3.4.
|
157
|
+
rubygems_version: 3.4.18
|
158
158
|
signing_key:
|
159
159
|
specification_version: 4
|
160
160
|
summary: Low traffic site? Small file upload needs? Don't want to setup a cloud service?
|