asset_cloud 2.7.0 → 2.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +42 -0
- data/.github/workflows/cla.yml +22 -0
- data/.rubocop.yml +3 -1
- data/Gemfile +5 -3
- data/History.md +8 -0
- data/README.rdoc +3 -4
- data/Rakefile +18 -16
- data/asset_cloud.gemspec +19 -18
- data/dev.yml +1 -1
- data/lib/asset_cloud/asset.rb +17 -13
- data/lib/asset_cloud/asset_extension.rb +27 -15
- data/lib/asset_cloud/base.rb +77 -72
- data/lib/asset_cloud/bucket.rb +5 -2
- data/lib/asset_cloud/buckets/active_record_bucket.rb +16 -14
- data/lib/asset_cloud/buckets/blackhole_bucket.rb +2 -0
- data/lib/asset_cloud/buckets/bucket_chain.rb +38 -31
- data/lib/asset_cloud/buckets/file_system_bucket.rb +14 -15
- data/lib/asset_cloud/buckets/gcs_bucket.rb +6 -8
- data/lib/asset_cloud/buckets/invalid_bucket.rb +9 -6
- data/lib/asset_cloud/buckets/memory_bucket.rb +7 -4
- data/lib/asset_cloud/buckets/s3_bucket.rb +11 -8
- data/lib/asset_cloud/buckets/versioned_memory_bucket.rb +4 -2
- data/lib/asset_cloud/callbacks.rb +9 -5
- data/lib/asset_cloud/free_key_locator.rb +6 -6
- data/lib/asset_cloud/metadata.rb +11 -7
- data/lib/asset_cloud/validations.rb +9 -5
- data/lib/asset_cloud.rb +23 -21
- data/spec/active_record_bucket_spec.rb +27 -26
- data/spec/asset_cloud/metadata_spec.rb +4 -2
- data/spec/asset_extension_spec.rb +17 -16
- data/spec/asset_spec.rb +27 -21
- data/spec/base_spec.rb +93 -92
- data/spec/blackhole_bucket_spec.rb +12 -11
- data/spec/bucket_chain_spec.rb +61 -56
- data/spec/bucket_spec.rb +6 -5
- data/spec/callbacks_spec.rb +52 -32
- data/spec/file_system_spec.rb +25 -24
- data/spec/find_free_key_spec.rb +16 -17
- data/spec/gcs_bucket_remote_spec.rb +23 -22
- data/spec/gcs_bucket_spec.rb +48 -60
- data/spec/memory_bucket_spec.rb +12 -11
- data/spec/mock_s3_interface.rb +17 -6
- data/spec/remote_s3_bucket_spec.rb +31 -28
- data/spec/s3_bucket_spec.rb +19 -17
- data/spec/spec_helper.rb +8 -7
- data/spec/validations_spec.rb +13 -12
- data/spec/versioned_memory_bucket_spec.rb +11 -10
- metadata +10 -33
- data/.github/probots.yml +0 -2
- data/.rubocop_todo.yml +0 -326
- data/.travis.yml +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 568dd22b66b6a00beacf0a8d099cad040bcddac422b3932b946573d823e67291
|
4
|
+
data.tar.gz: 8e97aa129cc5c6617722a6f5212ff51562cee437ba22476ceb63d7ad9dc62d25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cde8568299bb0b63c31ce9affa4880bcc7aa1940a63d1541210289f25dc7766528846d110a9b00ae7d1a412bc5bb2e695294b4bff851fb7aa0cc090856ed2bb
|
7
|
+
data.tar.gz: 821d7f7f2fe4c37df691d52b40217168638ff2d2d5cc3ee2dd056ec231e30f44584b1dbd538dc98d167d07d1a29ac0948bbde798d1b7f1870324f593090ecf88
|
@@ -0,0 +1,42 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
name: Ruby ${{ matrix.ruby }}
|
9
|
+
strategy:
|
10
|
+
fail-fast: false
|
11
|
+
matrix:
|
12
|
+
ruby: ["2.5", "2.6", "2.7", "3.0", "3.1", "3.2"]
|
13
|
+
steps:
|
14
|
+
|
15
|
+
- name: Check out code
|
16
|
+
uses: actions/checkout@v3
|
17
|
+
|
18
|
+
- name: Set up Ruby ${{ matrix.ruby }}
|
19
|
+
uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: ${{ matrix.ruby }}
|
22
|
+
bundler-cache: true
|
23
|
+
|
24
|
+
- name: Tests
|
25
|
+
run: bundle exec rspec
|
26
|
+
|
27
|
+
lint:
|
28
|
+
runs-on: ubuntu-latest
|
29
|
+
name: RuboCop
|
30
|
+
steps:
|
31
|
+
|
32
|
+
- name: Check out code
|
33
|
+
uses: actions/checkout@v3
|
34
|
+
|
35
|
+
- name: Set up Ruby
|
36
|
+
uses: ruby/setup-ruby@v1
|
37
|
+
with:
|
38
|
+
ruby-version: '3.2'
|
39
|
+
bundler-cache: true
|
40
|
+
|
41
|
+
- name: RuboCop
|
42
|
+
run: bundle exec rubocop
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: Contributor License Agreement (CLA)
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request_target:
|
5
|
+
types: [opened, synchronize]
|
6
|
+
issue_comment:
|
7
|
+
types: [created]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
cla:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
if: |
|
13
|
+
(github.event.issue.pull_request
|
14
|
+
&& !github.event.issue.pull_request.merged_at
|
15
|
+
&& contains(github.event.comment.body, 'signed')
|
16
|
+
)
|
17
|
+
|| (github.event.pull_request && !github.event.pull_request.merged)
|
18
|
+
steps:
|
19
|
+
- uses: Shopify/shopify-cla-action@v1
|
20
|
+
with:
|
21
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
22
|
+
cla-token: ${{ secrets.CLA_TOKEN }}
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "aws-sdk-s3", ">= 1.60.2", require: false
|
6
|
+
gem "google-cloud-storage"
|
5
7
|
|
6
8
|
gemspec
|
data/History.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Asset Cloud Version History
|
2
2
|
|
3
|
+
## Version 2.7.2, 2023-04-20
|
4
|
+
|
5
|
+
* Swap the order of operations for checking UUID and asset exist logic in free key locator (https://github.com/Shopify/asset_cloud/pull/83)
|
6
|
+
|
7
|
+
## Version 2.7.1, 2022-03-18
|
8
|
+
|
9
|
+
* Fix incorrect invocation of callbacks defined in external classes (https://github.com/Shopify/asset_cloud/issues/71)
|
10
|
+
|
3
11
|
## Version 2.7.0, 2020-07-15
|
4
12
|
|
5
13
|
* Add `Asset#write!` which raises on validation failure (https://github.com/Shopify/asset_cloud/pull/67)
|
data/README.rdoc
CHANGED
@@ -34,13 +34,12 @@ With GCS Remote test:
|
|
34
34
|
|
35
35
|
Releasing is handled by Shopify's internal Shipit server.
|
36
36
|
|
37
|
-
After merging a change, a separate PR should be opened to update
|
38
|
-
(following
|
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
39
|
|
40
40
|
When merged, the new release will be automatically tagged and deployed to rubygems.org.
|
41
41
|
|
42
|
-
Note that the automatic process does not create a new [
|
43
|
-
GitHub.
|
42
|
+
Note that the automatic process does not create a new {release}[https://github.com/Shopify/asset_cloud/releases] on GitHub.
|
44
43
|
|
45
44
|
== Copyright
|
46
45
|
|
data/Rakefile
CHANGED
@@ -1,28 +1,30 @@
|
|
1
|
-
|
2
|
-
require 'rspec'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require 'rdoc/task'
|
7
|
-
require 'rspec/core/rake_task'
|
8
|
-
require 'rubocop/rake_task'
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec"
|
9
5
|
|
10
|
-
|
6
|
+
require "rake"
|
7
|
+
require "rake/testtask"
|
8
|
+
require "rdoc/task"
|
9
|
+
require "rspec/core/rake_task"
|
10
|
+
require "rubocop/rake_task"
|
11
|
+
|
12
|
+
desc "Default: run unit tests and style checks."
|
11
13
|
task default: [:spec, :rubocop]
|
12
14
|
|
13
15
|
desc "Run all spec examples"
|
14
16
|
RSpec::Core::RakeTask.new do |t|
|
15
|
-
t.pattern =
|
16
|
-
t.rspec_opts = [
|
17
|
+
t.pattern = "spec/**/*_spec.rb"
|
18
|
+
t.rspec_opts = ["--color"]
|
17
19
|
end
|
18
20
|
|
19
|
-
desc
|
21
|
+
desc "Generate documentation for the asset_cloud plugin."
|
20
22
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
21
|
-
rdoc.rdoc_dir =
|
22
|
-
rdoc.title =
|
23
|
-
rdoc.options <<
|
24
|
-
rdoc.rdoc_files.include(
|
25
|
-
rdoc.rdoc_files.include(
|
23
|
+
rdoc.rdoc_dir = "rdoc"
|
24
|
+
rdoc.title = "AssetCloud"
|
25
|
+
rdoc.options << "--line-numbers" << "--inline-source"
|
26
|
+
rdoc.rdoc_files.include("README")
|
27
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
26
28
|
end
|
27
29
|
|
28
30
|
RuboCop::RakeTask.new
|
data/asset_cloud.gemspec
CHANGED
@@ -1,29 +1,30 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
4
|
+
require "English"
|
3
5
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "2.7.
|
6
|
+
s.name = "asset_cloud"
|
7
|
+
s.version = "2.7.2"
|
6
8
|
|
7
|
-
s.authors =
|
8
|
-
s.summary =
|
9
|
-
s.description =
|
9
|
+
s.authors = ["Shopify"]
|
10
|
+
s.summary = "An abstraction layer around arbitrary and diverse asset stores."
|
11
|
+
s.description = "An abstraction layer around arbitrary and diverse asset stores."
|
10
12
|
|
11
|
-
s.required_ruby_version =
|
13
|
+
s.required_ruby_version = ">= 2.5.0"
|
12
14
|
|
13
|
-
s.email =
|
14
|
-
s.homepage =
|
15
|
-
s.require_paths =
|
15
|
+
s.email = "developers@shopify.com"
|
16
|
+
s.homepage = "http://github.com/Shopify/asset_cloud"
|
17
|
+
s.require_paths = ["lib"]
|
16
18
|
|
17
|
-
s.files =
|
18
|
-
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
19
|
+
s.files = %x(git ls-files).split($INPUT_RECORD_SEPARATOR)
|
19
20
|
|
20
|
-
s.add_dependency
|
21
|
+
s.add_dependency("activesupport")
|
21
22
|
|
22
|
-
s.metadata[
|
23
|
+
s.metadata["allowed_push_host"] = "https://rubygems.org"
|
23
24
|
|
24
|
-
s.add_development_dependency
|
25
|
-
s.add_development_dependency
|
26
|
-
s.add_development_dependency
|
27
|
-
s.add_development_dependency
|
28
|
-
s.add_development_dependency
|
25
|
+
s.add_development_dependency("pry")
|
26
|
+
s.add_development_dependency("pry-byebug")
|
27
|
+
s.add_development_dependency("rake")
|
28
|
+
s.add_development_dependency("rspec")
|
29
|
+
s.add_development_dependency("rubocop-shopify")
|
29
30
|
end
|
data/dev.yml
CHANGED
data/lib/asset_cloud/asset.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module AssetCloud
|
3
4
|
class AssetError < StandardError
|
4
5
|
end
|
5
6
|
|
@@ -8,8 +9,9 @@ module AssetCloud
|
|
8
9
|
|
9
10
|
class Asset
|
10
11
|
include Comparable
|
11
|
-
attr_accessor :key, :
|
12
|
+
attr_accessor :key, :cloud, :new_asset
|
12
13
|
attr_reader :extensions
|
14
|
+
attr_writer :value, :metadata
|
13
15
|
|
14
16
|
def initialize(cloud, key, value = nil, metadata = Metadata.non_existing)
|
15
17
|
@new_asset = true
|
@@ -27,10 +29,12 @@ module AssetCloud
|
|
27
29
|
yield self if block_given?
|
28
30
|
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
class << self
|
33
|
+
def at(cloud, key, value = nil, metadata = nil, &block)
|
34
|
+
file = new(cloud, key, value, metadata, &block)
|
35
|
+
file.new_asset = false
|
36
|
+
file
|
37
|
+
end
|
34
38
|
end
|
35
39
|
|
36
40
|
def <=>(other)
|
@@ -42,11 +46,11 @@ module AssetCloud
|
|
42
46
|
end
|
43
47
|
|
44
48
|
def relative_key
|
45
|
-
@key.split("/",2).last
|
49
|
+
@key.split("/", 2).last
|
46
50
|
end
|
47
51
|
|
48
52
|
def relative_key_without_ext
|
49
|
-
relative_key.gsub(/\.[^.]+$/,"")
|
53
|
+
relative_key.gsub(/\.[^.]+$/, "")
|
50
54
|
end
|
51
55
|
|
52
56
|
def dirname
|
@@ -58,7 +62,7 @@ module AssetCloud
|
|
58
62
|
end
|
59
63
|
|
60
64
|
def format
|
61
|
-
extname.sub(
|
65
|
+
extname.sub(".", "")
|
62
66
|
end
|
63
67
|
|
64
68
|
def basename
|
@@ -122,7 +126,7 @@ module AssetCloud
|
|
122
126
|
end
|
123
127
|
|
124
128
|
def store!
|
125
|
-
store
|
129
|
+
store || raise(AssetNotSaved, "Validation failed: #{errors.join(", ")}")
|
126
130
|
end
|
127
131
|
|
128
132
|
def to_param
|
@@ -134,11 +138,11 @@ module AssetCloud
|
|
134
138
|
end
|
135
139
|
|
136
140
|
def url(options = {})
|
137
|
-
cloud.url_for
|
141
|
+
cloud.url_for(key, options)
|
138
142
|
end
|
139
143
|
|
140
144
|
def bucket_name
|
141
|
-
@key.split(
|
145
|
+
@key.split("/").first
|
142
146
|
end
|
143
147
|
|
144
148
|
def bucket
|
@@ -169,7 +173,7 @@ module AssetCloud
|
|
169
173
|
end
|
170
174
|
|
171
175
|
def method_missing(method, *args)
|
172
|
-
if extension = @extensions.find { |e| e.respond_to?(method) }
|
176
|
+
if (extension = @extensions.find { |e| e.respond_to?(method) })
|
173
177
|
extension.public_send(method, *args)
|
174
178
|
else
|
175
179
|
super
|
@@ -1,9 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module AssetCloud
|
2
4
|
class AssetExtension
|
3
5
|
class AssetMismatch < StandardError
|
4
6
|
end
|
5
|
-
|
6
|
-
def
|
7
|
+
|
8
|
+
def store
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
def delete
|
13
|
+
true
|
14
|
+
end
|
7
15
|
|
8
16
|
include AssetCloud::Callbacks
|
9
17
|
include AssetCloud::Validations
|
@@ -11,31 +19,35 @@ module AssetCloud
|
|
11
19
|
callback_methods :store, :delete, :validate
|
12
20
|
|
13
21
|
attr_reader :asset
|
14
|
-
|
22
|
+
|
23
|
+
delegate :add_error, to: :asset
|
15
24
|
|
16
25
|
class_attribute :extnames
|
17
26
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
27
|
+
class << self
|
28
|
+
def applies_to(*args)
|
29
|
+
extnames = args.map do |arg|
|
30
|
+
arg = arg.to_s.downcase
|
31
|
+
arg = ".#{arg}" unless arg.starts_with?(".")
|
32
|
+
arg
|
33
|
+
end
|
34
|
+
self.extnames = extnames
|
23
35
|
end
|
24
|
-
self.extnames = extnames
|
25
|
-
end
|
26
36
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
37
|
+
def applies_to_asset?(asset)
|
38
|
+
extnames = self.extnames || []
|
39
|
+
extnames.each do |extname|
|
40
|
+
return true if asset.key.downcase.ends_with?(extname)
|
41
|
+
end
|
42
|
+
false
|
31
43
|
end
|
32
|
-
false
|
33
44
|
end
|
34
45
|
|
35
46
|
def initialize(asset)
|
36
47
|
unless self.class.applies_to_asset?(asset)
|
37
48
|
raise AssetMismatch, "Instances of #{self.class.name} cannot be applied to asset #{asset.key.inspect}"
|
38
49
|
end
|
50
|
+
|
39
51
|
@asset = asset
|
40
52
|
end
|
41
53
|
end
|