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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +42 -0
  3. data/.github/workflows/cla.yml +22 -0
  4. data/.rubocop.yml +3 -1
  5. data/Gemfile +5 -3
  6. data/History.md +8 -0
  7. data/README.rdoc +3 -4
  8. data/Rakefile +18 -16
  9. data/asset_cloud.gemspec +19 -18
  10. data/dev.yml +1 -1
  11. data/lib/asset_cloud/asset.rb +17 -13
  12. data/lib/asset_cloud/asset_extension.rb +27 -15
  13. data/lib/asset_cloud/base.rb +77 -72
  14. data/lib/asset_cloud/bucket.rb +5 -2
  15. data/lib/asset_cloud/buckets/active_record_bucket.rb +16 -14
  16. data/lib/asset_cloud/buckets/blackhole_bucket.rb +2 -0
  17. data/lib/asset_cloud/buckets/bucket_chain.rb +38 -31
  18. data/lib/asset_cloud/buckets/file_system_bucket.rb +14 -15
  19. data/lib/asset_cloud/buckets/gcs_bucket.rb +6 -8
  20. data/lib/asset_cloud/buckets/invalid_bucket.rb +9 -6
  21. data/lib/asset_cloud/buckets/memory_bucket.rb +7 -4
  22. data/lib/asset_cloud/buckets/s3_bucket.rb +11 -8
  23. data/lib/asset_cloud/buckets/versioned_memory_bucket.rb +4 -2
  24. data/lib/asset_cloud/callbacks.rb +9 -5
  25. data/lib/asset_cloud/free_key_locator.rb +6 -6
  26. data/lib/asset_cloud/metadata.rb +11 -7
  27. data/lib/asset_cloud/validations.rb +9 -5
  28. data/lib/asset_cloud.rb +23 -21
  29. data/spec/active_record_bucket_spec.rb +27 -26
  30. data/spec/asset_cloud/metadata_spec.rb +4 -2
  31. data/spec/asset_extension_spec.rb +17 -16
  32. data/spec/asset_spec.rb +27 -21
  33. data/spec/base_spec.rb +93 -92
  34. data/spec/blackhole_bucket_spec.rb +12 -11
  35. data/spec/bucket_chain_spec.rb +61 -56
  36. data/spec/bucket_spec.rb +6 -5
  37. data/spec/callbacks_spec.rb +52 -32
  38. data/spec/file_system_spec.rb +25 -24
  39. data/spec/find_free_key_spec.rb +16 -17
  40. data/spec/gcs_bucket_remote_spec.rb +23 -22
  41. data/spec/gcs_bucket_spec.rb +48 -60
  42. data/spec/memory_bucket_spec.rb +12 -11
  43. data/spec/mock_s3_interface.rb +17 -6
  44. data/spec/remote_s3_bucket_spec.rb +31 -28
  45. data/spec/s3_bucket_spec.rb +19 -17
  46. data/spec/spec_helper.rb +8 -7
  47. data/spec/validations_spec.rb +13 -12
  48. data/spec/versioned_memory_bucket_spec.rb +11 -10
  49. metadata +10 -33
  50. data/.github/probots.yml +0 -2
  51. data/.rubocop_todo.yml +0 -326
  52. data/.travis.yml +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8573a0d845bd6022d3540cbb6e28027637bea815896060a6637ed70402fb0614
4
- data.tar.gz: df5f502bd556e2414ee896327ba18c54ce679faa2a2ebcf5b50a630803454719
3
+ metadata.gz: 568dd22b66b6a00beacf0a8d099cad040bcddac422b3932b946573d823e67291
4
+ data.tar.gz: 8e97aa129cc5c6617722a6f5212ff51562cee437ba22476ceb63d7ad9dc62d25
5
5
  SHA512:
6
- metadata.gz: 7302dd7d0e4e4ca392b344c530d3ebd3e610c25e5e6aa45658582944e2333ca66371e511e911f93e38f471815fb184a7d2c52d38dadfdda172a33ff7ff90e6ec
7
- data.tar.gz: 91a7fcfaf2dddbb1b855d6b25cadd563c414e09a625ceafdaaecf68faf07d4b89a6e80b89ab9cd2f264098f3ab9f1f387cf08f8ec8bcde19b67179045989bf40
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
@@ -1,3 +1,5 @@
1
1
  inherit_gem:
2
2
  rubocop-shopify: rubocop.yml
3
- inherit_from: .rubocop_todo.yml
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.5
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
2
 
3
- gem 'aws-sdk-s3', '>= 1.60.2', require: false
4
- gem 'google-cloud-storage'
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 `History.md` and bump the version
38
- (following [Semantic Versioning](https://semver.org/))
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 [release](https://github.com/Shopify/asset_cloud/releases) on
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
- require 'bundler/gem_tasks'
2
- require 'rspec'
1
+ # frozen_string_literal: true
3
2
 
4
- require 'rake'
5
- require 'rake/testtask'
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
- desc 'Default: run unit tests and style checks.'
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 = 'spec/**/*_spec.rb'
16
- t.rspec_opts = ['--color']
17
+ t.pattern = "spec/**/*_spec.rb"
18
+ t.rspec_opts = ["--color"]
17
19
  end
18
20
 
19
- desc 'Generate documentation for the asset_cloud plugin.'
21
+ desc "Generate documentation for the asset_cloud plugin."
20
22
  Rake::RDocTask.new(:rdoc) do |rdoc|
21
- rdoc.rdoc_dir = 'rdoc'
22
- rdoc.title = 'AssetCloud'
23
- rdoc.options << '--line-numbers' << '--inline-source'
24
- rdoc.rdoc_files.include('README')
25
- rdoc.rdoc_files.include('lib/**/*.rb')
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 = %q{asset_cloud}
5
- s.version = "2.7.0"
6
+ s.name = "asset_cloud"
7
+ s.version = "2.7.2"
6
8
 
7
- s.authors = %w(Shopify)
8
- s.summary = %q{An abstraction layer around arbitrary and diverse asset stores.}
9
- s.description = %q{An abstraction layer around arbitrary and diverse asset stores.}
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 = '>= 2.5.0'
13
+ s.required_ruby_version = ">= 2.5.0"
12
14
 
13
- s.email = %q{developers@shopify.com}
14
- s.homepage = %q{http://github.com/Shopify/asset_cloud}
15
- s.require_paths = %w(lib)
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 = `git ls-files`.split($/)
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 'activesupport'
21
+ s.add_dependency("activesupport")
21
22
 
22
- s.metadata['allowed_push_host'] = "https://rubygems.org"
23
+ s.metadata["allowed_push_host"] = "https://rubygems.org"
23
24
 
24
- s.add_development_dependency 'rspec'
25
- s.add_development_dependency 'rake'
26
- s.add_development_dependency 'pry'
27
- s.add_development_dependency 'pry-byebug'
28
- s.add_development_dependency 'rubocop-shopify'
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
@@ -2,7 +2,7 @@ name: asset-cloud
2
2
 
3
3
  up:
4
4
  - ruby:
5
- version: 2.5.0
5
+ version: 3.2.2
6
6
  - bundler
7
7
 
8
8
  commands:
@@ -1,5 +1,6 @@
1
- module AssetCloud
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, :value, :cloud, :metadata, :new_asset
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
- def self.at(cloud, key, value = nil, metadata = nil, &block)
31
- file = self.new(cloud, key, value, metadata, &block)
32
- file.new_asset = false
33
- file
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 or raise(AssetNotSaved, "Validation failed: #{errors.join(', ')}")
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 key, options
141
+ cloud.url_for(key, options)
138
142
  end
139
143
 
140
144
  def bucket_name
141
- @key.split('/').first
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
- def store; true; end
6
- def delete; true; end
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
- delegate :add_error, :to => :asset
22
+
23
+ delegate :add_error, to: :asset
15
24
 
16
25
  class_attribute :extnames
17
26
 
18
- def self.applies_to(*args)
19
- extnames = args.map do |arg|
20
- arg = arg.to_s.downcase
21
- arg = ".#{arg}" unless arg.starts_with?('.')
22
- arg
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
- def self.applies_to_asset?(asset)
28
- extnames = self.extnames || []
29
- extnames.each do |extname|
30
- return true if asset.key.downcase.ends_with?(extname)
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