asset_cloud 2.6.0 → 2.7.1

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: 134ba5f46359569f492531369197e78de71f48eabc0efef27c60b9f2a9b2a4fd
4
- data.tar.gz: 28edd6a34bfb58f3fe796c697a0c58855a65f117c489a4d427711b88386b2df0
3
+ metadata.gz: 5b202062a28470fab35e4aadafe3600f7944d2cb075d0076274acfd72dd93a6e
4
+ data.tar.gz: ad42d5f81dbe67cfde24248c3f8f8b2cb5d9bd1694be44d98546f234c8ef703b
5
5
  SHA512:
6
- metadata.gz: 161578c01372d753f3fe15558bc0f2b446e2cdbab75272c48c72bb3ce3e0a94c67616544b712efafc74eac6a7e0e18f69367712e5a37e87a769723177479c0c8
7
- data.tar.gz: a65784b410afe987d821589a631cf16e4b78795b6e07cebf6b6a4252c5631dc35eaca8a1da8ea2cbe4bf37d3308965bd5ed3a6dafe0c57de37a49489d8e11d4d
6
+ metadata.gz: c22411e548811567b511d54b55b79591835721aefd3a34b89ab504871473a477eddbb0903e7c30292c2fefa0e7c51b54b0a94e8ae3081961b40bfb8a69287de4
7
+ data.tar.gz: 822630e44304e0e2507d01a9e162898bd0c053ade3eabe785c625e407216c7a54166087c270f5166c63261cc98757664c201a6472cb474034b5c7a3af389679f
@@ -0,0 +1,27 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ name: Ruby ${{ matrix.ruby }}
9
+ strategy:
10
+ matrix:
11
+ ruby: ["2.5", "2.6", "2.7"]
12
+ steps:
13
+
14
+ - name: Check out code
15
+ uses: actions/checkout@v3
16
+
17
+ - name: Set up Ruby ${{ matrix.ruby }}
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: ${{ matrix.ruby }}
21
+ bundler-cache: true
22
+
23
+ - name: RuboCop
24
+ run: bundle exec rubocop || true # until we fix offenses due to outdated config
25
+
26
+ - name: Tests
27
+ run: bundle exec rspec
data/History.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Asset Cloud Version History
2
2
 
3
+ ## Version 2.7.1, 2022-03-18
4
+
5
+ * Fix incorrect invocation of callbacks defined in external classes (https://github.com/Shopify/asset_cloud/issues/71)
6
+
7
+ ## Version 2.7.0, 2020-07-15
8
+
9
+ * Add `Asset#write!` which raises on validation failure (https://github.com/Shopify/asset_cloud/pull/67)
10
+
3
11
  ## Version 2.6.0, 2020-05-22
4
12
 
5
13
  * Add checksum to metadata (https://github.com/Shopify/asset_cloud/pull/57)
data/README.rdoc CHANGED
@@ -9,7 +9,7 @@ An abstraction layer around arbitrary and diverse asset stores.
9
9
  +value_hash+ is intended as a *private* hash/checksum, not exposed to end users. Its underlying algorithm is private, and
10
10
  could change over time so should not be relied on by clients.
11
11
 
12
- +checksum+ is intended as a *public* hash/checksum, exposed to end users. Its underlying algorithms is documented (e.g. MD5)
12
+ +checksum+ is intended as a *public* hash/checksum, exposed to end users. Its underlying algorithm is documented (e.g. MD5)
13
13
  and is not expected to change.
14
14
 
15
15
  == Installation
@@ -30,6 +30,17 @@ With GCS Remote test:
30
30
 
31
31
  GCS_PROJECT_ID="<project_id>" GCS_KEY_FILEPATH="<path_to_key>" GCS_BUCKET="<bucket_name>" bundle exec rake spec
32
32
 
33
+ == Releasing
34
+
35
+ Releasing is handled by Shopify's internal Shipit server.
36
+
37
+ After merging a change, a separate PR should be opened to update +History.md+ and bump the version
38
+ (following {Semantic Versioning}[https://semver.org]).
39
+
40
+ When merged, the new release will be automatically tagged and deployed to rubygems.org.
41
+
42
+ Note that the automatic process does not create a new {release}[https://github.com/Shopify/asset_cloud/releases] on GitHub.
43
+
33
44
  == Copyright
34
45
 
35
46
  Copyright (c) 2008-2014 Tobias Lütke & Shopify, Inc. Released under the MIT license (see LICENSE for details).
data/asset_cloud.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{asset_cloud}
5
- s.version = "2.6.0"
5
+ s.version = "2.7.1"
6
6
 
7
7
  s.authors = %w(Shopify)
8
8
  s.summary = %q{An abstraction layer around arbitrary and diverse asset stores.}
@@ -151,6 +151,12 @@ module AssetCloud
151
151
  bucket_for(key).write(key, value)
152
152
  end
153
153
 
154
+ def write!(key, value)
155
+ asset = self[key]
156
+ asset.value = value
157
+ asset.store!
158
+ end
159
+
154
160
  def read(key)
155
161
  logger.info { " [#{self.class.name}] Reading from #{key}" } if logger
156
162
 
@@ -17,7 +17,7 @@ module AssetCloud
17
17
  bucket.create_file(
18
18
  data,
19
19
  absolute_key(key),
20
- options
20
+ **options,
21
21
  )
22
22
  end
23
23
 
@@ -59,15 +59,15 @@ module AssetCloud
59
59
 
60
60
  def execute_callbacks(symbol, args)
61
61
  callbacks_for(symbol).each do |callback|
62
-
62
+
63
63
  result = case callback
64
64
  when Symbol
65
65
  send(callback, *args)
66
66
  when Proc, Method
67
67
  callback.call(self, *args)
68
68
  else
69
- if callback.respond_to?(method)
70
- callback.send(method, self, *args)
69
+ if callback.respond_to?(symbol)
70
+ callback.send(symbol, self, *args)
71
71
  else
72
72
  raise StandardError, "Callbacks must be a symbol denoting the method to call, a string to be evaluated, a block to be invoked, or an object responding to the callback method."
73
73
  end
data/spec/base_spec.rb CHANGED
@@ -7,11 +7,18 @@ end
7
7
  class LiquidAsset < AssetCloud::Asset
8
8
  end
9
9
 
10
+ class BrokenBucket < AssetCloud::Bucket
11
+ def write(*)
12
+ false
13
+ end
14
+ end
15
+
10
16
  class BasicCloud < AssetCloud::Base
11
17
  bucket :special, AssetCloud::MemoryBucket, asset_class: SpecialAsset
12
18
  bucket :conditional, AssetCloud::MemoryBucket, asset_class: proc { |key|
13
19
  LiquidAsset if key.ends_with?('.liquid')
14
20
  }
21
+ bucket :broken, BrokenBucket, asset_class: AssetCloud::Asset
15
22
  end
16
23
 
17
24
  describe BasicCloud do
@@ -192,6 +199,20 @@ describe BasicCloud do
192
199
  end
193
200
  end
194
201
 
202
+ describe "write!" do
203
+ it "should write through the Asset object (and thus run any callbacks on the asset)" do
204
+ special_asset = double(:special_asset)
205
+ expect(special_asset).to(receive(:value=).with('fancy fancy!'))
206
+ expect(special_asset).to(receive(:store!))
207
+ expect(SpecialAsset).to(receive(:at).and_return(special_asset))
208
+ @fs.write!('special/fancy.txt', 'fancy fancy!')
209
+ end
210
+
211
+ it "should raise AssetNotSaved when write fails" do
212
+ expect { @fs.write!('broken/file.txt', 'n/a') }.to(raise_error(AssetCloud::AssetNotSaved))
213
+ end
214
+ end
215
+
195
216
  describe "MATCH_BUCKET" do
196
217
  it "should match following stuff " do
197
218
  'products/key.txt' =~ AssetCloud::Base::MATCH_BUCKET
@@ -1,6 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
  require 'spec_helper'
3
3
 
4
+
5
+ class AfterStoreCallback
6
+ def self.after_store(*args); end
7
+ end
8
+
4
9
  class CallbackAsset < AssetCloud::Asset
5
10
  before_store :callback_before_store
6
11
  before_delete :callback_before_delete
@@ -9,6 +14,8 @@ class CallbackAsset < AssetCloud::Asset
9
14
  after_validate :add_spice
10
15
  validate :valid_value
11
16
 
17
+ after_store ::AfterStoreCallback
18
+
12
19
  private
13
20
 
14
21
  def callback_before_delete(*args); end
@@ -143,4 +150,15 @@ describe CallbackAsset do
143
150
 
144
151
  expect(@asset.delete).to(eq(nil))
145
152
  end
153
+
154
+ it "should invoke after_store callback defined in separate class" do
155
+ local_fs = BasicCloud.new(File.dirname(__FILE__) + '/files', 'http://assets/')
156
+ local_fs.write('callback_assets/foo', 'bar')
157
+ local_asset = local_fs.asset_at('callback_assets/foo')
158
+
159
+ expect(local_asset).to(receive(:callback_before_store).and_return(true))
160
+ expect(::AfterStoreCallback).to(receive(:after_store))
161
+
162
+ expect(local_asset.store).to(eq(true))
163
+ end
146
164
  end
@@ -38,16 +38,29 @@ describe AssetCloud::GCSBucket do
38
38
  expect(file.class).to(eq(Google::Cloud::Storage::File))
39
39
  end
40
40
 
41
- it "#write writes a file into the bucket" do
42
- local_path = "#{directory}/products/key.txt"
43
- key = 'test/key.txt'
44
- expect_any_instance_of(MockGCSBucket).to(receive(:create_file).with(
45
- local_path,
46
- "s#{@cloud.url}/#{key}",
47
- {}
48
- ))
49
-
50
- @bucket.write(key, local_path)
41
+ if RUBY_VERSION >= '2.7'
42
+ it "#write writes a file into the bucket" do
43
+ local_path = "#{directory}/products/key.txt"
44
+ key = 'test/key.txt'
45
+ expect_any_instance_of(MockGCSBucket).to(receive(:create_file).with(
46
+ local_path,
47
+ "s#{@cloud.url}/#{key}",
48
+ ))
49
+
50
+ @bucket.write(key, local_path)
51
+ end
52
+ else
53
+ it "#write writes a file into the bucket" do
54
+ local_path = "#{directory}/products/key.txt"
55
+ key = 'test/key.txt'
56
+ expect_any_instance_of(MockGCSBucket).to(receive(:create_file).with(
57
+ local_path,
58
+ "s#{@cloud.url}/#{key}",
59
+ {}
60
+ ))
61
+
62
+ @bucket.write(key, local_path)
63
+ end
51
64
  end
52
65
 
53
66
  it "#write writes a file into the bucket with metadata" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asset_cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0
4
+ version: 2.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-22 00:00:00.000000000 Z
11
+ date: 2022-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -101,10 +101,10 @@ extensions: []
101
101
  extra_rdoc_files: []
102
102
  files:
103
103
  - ".github/probots.yml"
104
+ - ".github/workflows/ci.yml"
104
105
  - ".gitignore"
105
106
  - ".rubocop.yml"
106
107
  - ".rubocop_todo.yml"
107
- - ".travis.yml"
108
108
  - Gemfile
109
109
  - History.md
110
110
  - LICENSE
@@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
174
  requirements: []
175
- rubygems_version: 3.0.3
175
+ rubygems_version: 3.2.20
176
176
  signing_key:
177
177
  specification_version: 4
178
178
  summary: An abstraction layer around arbitrary and diverse asset stores.
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- language: ruby
2
- before_install:
3
- - gem install bundler
4
- rvm:
5
- - '2.5'
6
- - '2.6'