simple_active_storage 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +10 -2
- data/lib/simple_active_storage/attached.rb +10 -1
- data/lib/simple_active_storage/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c09916e7b604311ed141ed9384280a19c03e74bcec6740aee56b18afaaa517f9
|
4
|
+
data.tar.gz: eba0289e76f641dd870c7ebf6959be60cc5273b446e3db12e4a550942f7701a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a769fae12817704e8fdafd027ba382e0e031ad90fd0d9d4de9b6a8a1e1fe3f20db27b1467632565f460ceb2515f8731f32cc8d65c3e01f8d6cb39df63d80d2dc
|
7
|
+
data.tar.gz: cb7b838f2f74c0937eeac3f3e04b1403493878693bc438b96708973bec2704ca7bf23ca2bdd786a9a462f46b4fe587265f15b2533882fbca367d2967b531b2a3
|
data/README.md
CHANGED
@@ -95,7 +95,7 @@ originally there is no transformations field in json data.
|
|
95
95
|
the transformations field data is provide by SimpleActiveStorage.
|
96
96
|
|
97
97
|
### short cut url
|
98
|
-
the representation url is very long
|
98
|
+
the representation url is very long
|
99
99
|
because rails encrypted transformation information to a very long string
|
100
100
|
```
|
101
101
|
http://www.example.com/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--578572a7c2d5925ac32622a7d7b832f68c536f51/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VWTI5dFltbHVaVjl2Y0hScGIyNXpld1k2QzNKbGMybDZaVWtpRERRd01IZzBNREFHT2daRlZBPT0iLCJleHAiOm51bGwsInB1ciI6InZhcmlhdGlvbiJ9fQ==--b87eb27c4abc3f9bd937642f2e5809bfd553edf8/avatar.jpg
|
@@ -105,7 +105,7 @@ eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VWTI5dFltbHVaVjl2Y0hScGIyNXpld1k2QzNKbGMy
|
|
105
105
|
```
|
106
106
|
this is part of the representation url
|
107
107
|
included transformation information , can be decrypted by rails
|
108
|
-
if you turned on by set
|
108
|
+
if you turned on by set
|
109
109
|
``` ruby
|
110
110
|
SimpleActiveStorage.config.enable_shortcut_url = true
|
111
111
|
```
|
@@ -116,6 +116,14 @@ http://www.example.com/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVz
|
|
116
116
|
the difference between two urls is that transofrmation(variantation_key) part.
|
117
117
|
|
118
118
|
|
119
|
+
### auto remove duplicate blobs
|
120
|
+
user = User.first
|
121
|
+
avatar = user.avatar
|
122
|
+
user.photos.attach avatar.blob
|
123
|
+
user.photos.attach avatar.blob # raise error without simple active storage
|
124
|
+
user.photos.attachments.size # 1
|
125
|
+
|
126
|
+
|
119
127
|
## Installation
|
120
128
|
Add this line to your application's Gemfile:
|
121
129
|
|
@@ -3,9 +3,18 @@
|
|
3
3
|
module SimpleActiveStorage
|
4
4
|
module Attached
|
5
5
|
module Many
|
6
|
+
# 检查过滤掉已经存在的
|
6
7
|
def attach(*attachables)
|
7
8
|
record.try(:before_active_storage_attach,attachables)
|
8
|
-
|
9
|
+
|
10
|
+
# remove duplicate attachments
|
11
|
+
signed_ids = attachments.map(&:signed_id)
|
12
|
+
blobs = attachables.map{|attachable| create_blob_from attachable}.compact
|
13
|
+
filtered_blobs = blobs.find_all{|blob|
|
14
|
+
!signed_ids.include?(blob.signed_id)
|
15
|
+
}
|
16
|
+
|
17
|
+
result = super(*filtered_blobs)
|
9
18
|
record.try(:after_active_storage_attach,{name: name, attachments: attachments})
|
10
19
|
result
|
11
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_active_storage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aotianlong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
81
|
rubyforge_project:
|
82
|
-
rubygems_version: 2.
|
82
|
+
rubygems_version: 2.7.8
|
83
83
|
signing_key:
|
84
84
|
specification_version: 4
|
85
85
|
summary: add shortcut variant support for active storage
|