simple_active_storage 0.1.2 → 0.1.3

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
  SHA1:
3
- metadata.gz: 642cee73e9cefa777da14f34728f9f73cd5f814d
4
- data.tar.gz: a1816cac9a5dabc1c7862be75edc68ef74a16ada
3
+ metadata.gz: 3a16b25d0eca6b42b114935bdebcc7da5914e411
4
+ data.tar.gz: 10dbec194c30dfb5c4b3f912d85fadeb83823920
5
5
  SHA512:
6
- metadata.gz: b435641a3ba3b8ef53719e1614fc60d451c93ba012e12930657d1a99c61cbc3c5367639e187f5b5d5f71626ee10a6b6832e5524e4e51fef76e0e5f4f5768ce57
7
- data.tar.gz: 1157fef26391f004346806924ce76c28a865856a43fb8bb10c0f7f217181667ed9678b27f56d1bcd0ce6ce0eb76e15b7aeec9985345366975f2bfb6288b76d9f
6
+ metadata.gz: acf5cfedc94e52a9bf9129a95f92968945ff64dcf2dd82ea3df6608232e58d9f13f3a9010767ae7104f750cd85fb4ecc5ae2e241a8d2f89ba537dae3664192b4
7
+ data.tar.gz: 3afe88d39d5466dac5b7324fda1d8e3079805cc2c53896ee1bc0ee7f9deaa61549016ff3fb2de167d857c367aa9edeb0e61e0ac6422683caca3f9a81faced0f4
data/README.md CHANGED
@@ -94,6 +94,28 @@ and return json data it looks like below:
94
94
  originally there is no transformations field in json data.
95
95
  the transformations field data is provide by SimpleActiveStorage.
96
96
 
97
+ ### short cut url
98
+ the representation url is very long
99
+ because rails encrypted transformation information to a very long string
100
+ ```
101
+ http://www.example.com/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--578572a7c2d5925ac32622a7d7b832f68c536f51/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VWTI5dFltbHVaVjl2Y0hScGIyNXpld1k2QzNKbGMybDZaVWtpRERRd01IZzBNREFHT2daRlZBPT0iLCJleHAiOm51bGwsInB1ciI6InZhcmlhdGlvbiJ9fQ==--b87eb27c4abc3f9bd937642f2e5809bfd553edf8/avatar.jpg
102
+ ```
103
+ ```
104
+ eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VWTI5dFltbHVaVjl2Y0hScGIyNXpld1k2QzNKbGMybDZaVWtpRERRd01IZzBNREFHT2daRlZBPT0iLCJleHAiOm51bGwsInB1ciI6InZhcmlhdGlvbiJ9fQ==--b87eb27c4abc3f9bd937642f2e5809bfd553edf8
105
+ ```
106
+ this is part of the representation url
107
+ included transformation information , can be decrypted by rails
108
+ if you turned on by set
109
+ ``` ruby
110
+ SimpleActiveStorage.config.enable_shortcut_url = true
111
+ ```
112
+ you will get this short url:
113
+ ```
114
+ http://www.example.com/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--578572a7c2d5925ac32622a7d7b832f68c536f51/thumb/avatar.jpg
115
+ ```
116
+ the difference between two urls is that transofrmation(variantation_key) part.
117
+
118
+
97
119
  ## Installation
98
120
  Add this line to your application's Gemfile:
99
121
 
@@ -1,5 +1,9 @@
1
1
  # SimpleActiveStorage.default_url_options = {host: "www.example.com"}
2
2
  #
3
+ # # shortcut representation url # default: false
4
+ #
5
+ # SimpleActiveStorage.config.enable_shortcut_url = true
6
+ #
3
7
  # SimpleActiveStorage.transformation :thumb do
4
8
  # {
5
9
  # combine_options: {
@@ -5,4 +5,5 @@ require "simple_active_storage/direct_uploads_controller"
5
5
 
6
6
  module SimpleActiveStorage
7
7
  # Your code goes here...
8
+ include ActiveSupport::Configurable
8
9
  end
@@ -10,10 +10,20 @@ module SimpleActiveStorage
10
10
  ActiveStorage::Preview.send :include,SimpleActiveStorage::Url
11
11
  ActiveStorage::Blob.send :include,SimpleActiveStorage::Url
12
12
 
13
- end
14
-
15
- config.after_initialize do
16
13
  ActiveStorage::DirectUploadsController.send :prepend,SimpleActiveStorage::DirectUploadsController
14
+
15
+
16
+ old_wrap = ActiveStorage::Variation.method :wrap
17
+ # redefine wrap
18
+ ActiveStorage::Variation.define_singleton_method :wrap do |transformation|
19
+ if SimpleActiveStorage.config.enable_shortcut_url && transformation.is_a?(String)
20
+ if SimpleActiveStorage.transformation_exists? transformation.to_sym
21
+ transformation = transformation.to_sym
22
+ end
23
+ end
24
+ old_wrap.call(transformation)
25
+ end
26
+
17
27
  end
18
28
 
19
29
  end
@@ -10,10 +10,17 @@ module SimpleActiveStorage
10
10
  transformations[name] = transformation
11
11
  end
12
12
 
13
+ def self.transformation_exists?(name)
14
+ self.transformations.keys.include? name
15
+ end
16
+
13
17
  module Variation
14
18
  extend ActiveSupport::Concern
19
+
20
+
15
21
  def initialize(transformation)
16
22
  if transformation.is_a? Symbol
23
+ @transformation_name = transformation
17
24
  transformation = SimpleActiveStorage.transformations[transformation]
18
25
  if transformation.nil?
19
26
  raise TransformationNotFound.new("transformation: #{transformation} not found, perhaps you forget define it?")
@@ -21,6 +28,14 @@ module SimpleActiveStorage
21
28
  end
22
29
  super(transformation)
23
30
  end
31
+
32
+ def key
33
+ if SimpleActiveStorage.config.enable_shortcut_url && @transformation_name
34
+ @transformation_name.to_s
35
+ else
36
+ super
37
+ end
38
+ end
24
39
  end
25
40
 
26
41
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleActiveStorage
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - aotianlong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-29 00:00:00.000000000 Z
11
+ date: 2018-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails