shrine-cloudimage 0.1.1 → 0.2.0

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: 281d70f12285d2b0c69bf9e0a6f6452a50a4be1684c330ad1922a6c4e887681c
4
- data.tar.gz: 253fb09e1102cc9bfe31695728af83166c0ee4b5659b0e122393c1c6f1c02b04
3
+ metadata.gz: a276745ba3cbba20a4a04c21cd3920ececf68924ce41583a4be2f2968507eaab
4
+ data.tar.gz: e3b43a01bfd7013e1469970346536b336dd70c364b0a1e6ae41a5ca63c81a84f
5
5
  SHA512:
6
- metadata.gz: 2265bb6ed5cb06facfd627d5c459478c2402b8db96b1300c17958d588ffbd227778dc472f1cb3f1a9492554aeff034c5610b29026877daed2367a216f5fcdc24
7
- data.tar.gz: 568439c974697f15cbf5fa22b31318f4ac24011a5547b5530557376ed45d34ce2c3fff02d1f06bea7d07d4d33a4251212e3111824046a3d50ba3851906880c28
6
+ metadata.gz: ef40813ee89adbffaab70059e4c98d16fa67994d2841f8352782af10eac6516966b4c78216467ad8aa528864bfb3a45a2ca01f55cc7baa478edeee0bc70a4bef
7
+ data.tar.gz: 8b61a11ac7328fa8ad04d04f3d0f0383a2569e87f8c3e84d61c01f9cc9e69830a1ae6527f39a873e1b4c1429207547fe17013db6e3f860170f9f0b2eb8ce4dcf
data/README.md CHANGED
@@ -10,6 +10,7 @@ Supports Ruby `2.4` and above, `JRuby`, and `TruffleRuby`.
10
10
  - [Installation](#installation)
11
11
  - [Configuration](#configuration)
12
12
  - [Usage](#usage)
13
+ - [Invalidation API](#invalidation-api)
13
14
  - [Development](#development)
14
15
  - [Contributing](#contributing)
15
16
  - [License](#license)
@@ -50,8 +51,7 @@ Shrine.plugin :cloudimage, Cloudimage::Client.new(
50
51
  )
51
52
  ```
52
53
 
53
- See [`cloudimage`](https://github.com/scaleflex/cloudimage-rb) for a list
54
- of available options.
54
+ See [`cloudimage`][cloudimage] for a list of available options.
55
55
 
56
56
  ## Usage
57
57
 
@@ -63,6 +63,33 @@ photo.image.cloudimage_url(w: 300, h: 300, blur: 5)
63
63
  # => "https://token.cloudimg.io/v7/https://my-bucket.s3.us-east-1.amazonaws.com/assets/image.jpg?blur=5&h=300&w=300"
64
64
  ```
65
65
 
66
+ Cloudimage client can also be accessed directly. This way you can centralize your
67
+ config in Shrine initializer and reuse it across your codebase:
68
+
69
+ ```ruby
70
+ uri = Shrine.cloudimage_client.path('/assets/image.png')
71
+ uri.w(200).h(400).to_url
72
+ # => "https://token.cloudimg.io/v7/assets/image.png?h=400&w=200"
73
+ ```
74
+
75
+ ### Invalidation API
76
+
77
+ Set `:invalidate` to `true` if you want images to be automatically
78
+ [purged][invalidation] from Cloudimage on deletion:
79
+
80
+ ```rb
81
+ Shrine.plugin :cloudimage, client: { token: 'token', api_key: 'key' }, invalidate: true
82
+ ```
83
+
84
+ You can also invalidate all cached transformations of the given image manually with
85
+ `Shrine::UploadedFile#cloudimage_invalidate`:
86
+
87
+ ```rb
88
+ photo.image.cloudimage_invalidate
89
+ ```
90
+
91
+ Note that invalidation requires passing the `:api_key` option to your Cloudimage client.
92
+
66
93
  ## Development
67
94
 
68
95
  After checking out the repo, run `bundle install` to install dependencies.
@@ -78,3 +105,6 @@ are expected to adhere to the
78
105
  ## License
79
106
 
80
107
  [MIT](https://opensource.org/licenses/MIT)
108
+
109
+ [invalidation]: https://docs.cloudimage.io/go/cloudimage-documentation-v7/en/caching-acceleration/invalidation-api
110
+ [cloudimage]: https://github.com/scaleflex/cloudimage-rb
@@ -10,7 +10,7 @@ class Shrine
10
10
  opts[:client] = ::Cloudimage::Client.new(**opts[:client])
11
11
  end
12
12
 
13
- uploader.opts[:cloudimage] ||= {}
13
+ uploader.opts[:cloudimage] ||= { invalidate: false }
14
14
  uploader.opts[:cloudimage].merge!(**opts)
15
15
 
16
16
  return if uploader.cloudimage_client
@@ -29,11 +29,25 @@ class Shrine
29
29
  cloudimage_client.path(url).to_url(**options)
30
30
  end
31
31
 
32
+ def delete
33
+ super
34
+ cloudimage_invalidate if cloudimage_invalidate?
35
+ end
36
+
37
+ def cloudimage_invalidate
38
+ path = URI.parse(cloudimage_url).path
39
+ cloudimage_client.invalidate_original(path)
40
+ end
41
+
32
42
  private
33
43
 
34
44
  def cloudimage_client
35
45
  shrine_class.cloudimage_client
36
46
  end
47
+
48
+ def cloudimage_invalidate?
49
+ shrine_class.opts[:cloudimage][:invalidate]
50
+ end
37
51
  end
38
52
  end
39
53
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrine-cloudimage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Klimo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-19 00:00:00.000000000 Z
11
+ date: 2020-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cloudimage