asset_cloud 2.7.1 → 2.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/ci.yml +21 -7
- data/.github/workflows/cla.yml +22 -0
- data/.gitignore +0 -1
- data/.rubocop.yml +0 -1
- data/.ruby-version +1 -0
- data/Gemfile +5 -3
- data/Gemfile.lock +180 -0
- data/History.md +9 -0
- data/README.rdoc +1 -3
- data/Rakefile +18 -16
- data/asset_cloud.gemspec +19 -18
- data/dev.yml +1 -2
- 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 +24 -16
- 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 +24 -22
- 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 +65 -39
- 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 +13 -36
- data/.github/probots.yml +0 -2
- data/.rubocop_todo.yml +0 -326
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bed261dca11417616d233595b006d2bd53e3f19c542320d387d0edc2dc76182f
|
4
|
+
data.tar.gz: 8c19949270fd24f85ac239c15e063be7369679bb235adcd26f96d2f13590aec9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8eadac3515bc1efafa9e563a0596a74f84a2faa26234cc451ddd412935de975f5047b412149b0daeb9c93f0a733590fd244df983432fd68591aef7fb75d7bb34
|
7
|
+
data.tar.gz: f1ad4789ac383943515c389f1ec20b778c1bfcec7efe1cdab6970204646bace030bee8e22fef8c99bffe117b9559829db6bb56e4206d22933c05875b368f278d
|
data/.github/workflows/ci.yml
CHANGED
@@ -3,25 +3,39 @@ name: CI
|
|
3
3
|
on: [push, pull_request]
|
4
4
|
|
5
5
|
jobs:
|
6
|
-
|
6
|
+
test:
|
7
7
|
runs-on: ubuntu-latest
|
8
8
|
name: Ruby ${{ matrix.ruby }}
|
9
9
|
strategy:
|
10
|
+
fail-fast: false
|
10
11
|
matrix:
|
11
|
-
ruby: ["
|
12
|
+
ruby: ["3.0", "3.1", "3.2", "3.3"]
|
12
13
|
steps:
|
13
14
|
|
14
15
|
- name: Check out code
|
15
|
-
uses: actions/checkout@
|
16
|
+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
16
17
|
|
17
18
|
- name: Set up Ruby ${{ matrix.ruby }}
|
18
|
-
uses: ruby/setup-ruby@v1
|
19
|
+
uses: ruby/setup-ruby@e34163cd15f4bb403dcd72d98e295997e6a55798 # v1.238.0
|
19
20
|
with:
|
20
21
|
ruby-version: ${{ matrix.ruby }}
|
21
22
|
bundler-cache: true
|
22
23
|
|
23
|
-
- name: RuboCop
|
24
|
-
run: bundle exec rubocop || true # until we fix offenses due to outdated config
|
25
|
-
|
26
24
|
- name: Tests
|
27
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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
34
|
+
|
35
|
+
- name: Set up Ruby
|
36
|
+
uses: ruby/setup-ruby@e34163cd15f4bb403dcd72d98e295997e6a55798 # v1.238.0
|
37
|
+
with:
|
38
|
+
bundler-cache: true
|
39
|
+
|
40
|
+
- name: RuboCop
|
41
|
+
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/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.2
|
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/Gemfile.lock
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
asset_cloud (2.7.3)
|
5
|
+
activesupport
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (7.1.3.2)
|
11
|
+
base64
|
12
|
+
bigdecimal
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
connection_pool (>= 2.2.5)
|
15
|
+
drb
|
16
|
+
i18n (>= 1.6, < 2)
|
17
|
+
minitest (>= 5.1)
|
18
|
+
mutex_m
|
19
|
+
tzinfo (~> 2.0)
|
20
|
+
addressable (2.8.6)
|
21
|
+
public_suffix (>= 2.0.2, < 6.0)
|
22
|
+
ast (2.4.2)
|
23
|
+
aws-eventstream (1.3.0)
|
24
|
+
aws-partitions (1.922.0)
|
25
|
+
aws-sdk-core (3.193.0)
|
26
|
+
aws-eventstream (~> 1, >= 1.3.0)
|
27
|
+
aws-partitions (~> 1, >= 1.651.0)
|
28
|
+
aws-sigv4 (~> 1.8)
|
29
|
+
jmespath (~> 1, >= 1.6.1)
|
30
|
+
aws-sdk-kms (1.80.0)
|
31
|
+
aws-sdk-core (~> 3, >= 3.193.0)
|
32
|
+
aws-sigv4 (~> 1.1)
|
33
|
+
aws-sdk-s3 (1.148.0)
|
34
|
+
aws-sdk-core (~> 3, >= 3.193.0)
|
35
|
+
aws-sdk-kms (~> 1)
|
36
|
+
aws-sigv4 (~> 1.8)
|
37
|
+
aws-sigv4 (1.8.0)
|
38
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
39
|
+
base64 (0.2.0)
|
40
|
+
bigdecimal (3.1.7)
|
41
|
+
byebug (11.1.3)
|
42
|
+
coderay (1.1.3)
|
43
|
+
concurrent-ruby (1.2.3)
|
44
|
+
connection_pool (2.4.1)
|
45
|
+
declarative (0.0.20)
|
46
|
+
diff-lcs (1.5.1)
|
47
|
+
digest-crc (0.6.5)
|
48
|
+
rake (>= 12.0.0, < 14.0.0)
|
49
|
+
drb (2.2.1)
|
50
|
+
faraday (2.9.0)
|
51
|
+
faraday-net_http (>= 2.0, < 3.2)
|
52
|
+
faraday-net_http (3.1.0)
|
53
|
+
net-http
|
54
|
+
google-apis-core (0.14.1)
|
55
|
+
addressable (~> 2.5, >= 2.5.1)
|
56
|
+
googleauth (~> 1.9)
|
57
|
+
httpclient (>= 2.8.1, < 3.a)
|
58
|
+
mini_mime (~> 1.0)
|
59
|
+
representable (~> 3.0)
|
60
|
+
retriable (>= 2.0, < 4.a)
|
61
|
+
rexml
|
62
|
+
google-apis-iamcredentials_v1 (0.20.0)
|
63
|
+
google-apis-core (>= 0.14.0, < 2.a)
|
64
|
+
google-apis-storage_v1 (0.37.0)
|
65
|
+
google-apis-core (>= 0.14.0, < 2.a)
|
66
|
+
google-cloud-core (1.7.0)
|
67
|
+
google-cloud-env (>= 1.0, < 3.a)
|
68
|
+
google-cloud-errors (~> 1.0)
|
69
|
+
google-cloud-env (2.1.1)
|
70
|
+
faraday (>= 1.0, < 3.a)
|
71
|
+
google-cloud-errors (1.4.0)
|
72
|
+
google-cloud-storage (1.51.0)
|
73
|
+
addressable (~> 2.8)
|
74
|
+
digest-crc (~> 0.4)
|
75
|
+
google-apis-core (~> 0.13)
|
76
|
+
google-apis-iamcredentials_v1 (~> 0.18)
|
77
|
+
google-apis-storage_v1 (~> 0.37)
|
78
|
+
google-cloud-core (~> 1.6)
|
79
|
+
googleauth (~> 1.9)
|
80
|
+
mini_mime (~> 1.0)
|
81
|
+
googleauth (1.11.0)
|
82
|
+
faraday (>= 1.0, < 3.a)
|
83
|
+
google-cloud-env (~> 2.1)
|
84
|
+
jwt (>= 1.4, < 3.0)
|
85
|
+
multi_json (~> 1.11)
|
86
|
+
os (>= 0.9, < 2.0)
|
87
|
+
signet (>= 0.16, < 2.a)
|
88
|
+
httpclient (2.8.3)
|
89
|
+
i18n (1.14.4)
|
90
|
+
concurrent-ruby (~> 1.0)
|
91
|
+
jmespath (1.6.2)
|
92
|
+
json (2.7.2)
|
93
|
+
jwt (2.8.1)
|
94
|
+
base64
|
95
|
+
language_server-protocol (3.17.0.3)
|
96
|
+
method_source (1.1.0)
|
97
|
+
mini_mime (1.1.5)
|
98
|
+
minitest (5.22.3)
|
99
|
+
multi_json (1.15.0)
|
100
|
+
mutex_m (0.2.0)
|
101
|
+
net-http (0.4.1)
|
102
|
+
uri
|
103
|
+
os (1.1.4)
|
104
|
+
parallel (1.24.0)
|
105
|
+
parser (3.3.1.0)
|
106
|
+
ast (~> 2.4.1)
|
107
|
+
racc
|
108
|
+
pry (0.14.2)
|
109
|
+
coderay (~> 1.1)
|
110
|
+
method_source (~> 1.0)
|
111
|
+
pry-byebug (3.10.1)
|
112
|
+
byebug (~> 11.0)
|
113
|
+
pry (>= 0.13, < 0.15)
|
114
|
+
public_suffix (5.0.5)
|
115
|
+
racc (1.7.3)
|
116
|
+
rainbow (3.1.1)
|
117
|
+
rake (13.2.1)
|
118
|
+
regexp_parser (2.9.0)
|
119
|
+
representable (3.2.0)
|
120
|
+
declarative (< 0.1.0)
|
121
|
+
trailblazer-option (>= 0.1.1, < 0.2.0)
|
122
|
+
uber (< 0.2.0)
|
123
|
+
retriable (3.1.2)
|
124
|
+
rexml (3.3.9)
|
125
|
+
rspec (3.13.0)
|
126
|
+
rspec-core (~> 3.13.0)
|
127
|
+
rspec-expectations (~> 3.13.0)
|
128
|
+
rspec-mocks (~> 3.13.0)
|
129
|
+
rspec-core (3.13.0)
|
130
|
+
rspec-support (~> 3.13.0)
|
131
|
+
rspec-expectations (3.13.0)
|
132
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
133
|
+
rspec-support (~> 3.13.0)
|
134
|
+
rspec-mocks (3.13.0)
|
135
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
136
|
+
rspec-support (~> 3.13.0)
|
137
|
+
rspec-support (3.13.1)
|
138
|
+
rubocop (1.63.4)
|
139
|
+
json (~> 2.3)
|
140
|
+
language_server-protocol (>= 3.17.0)
|
141
|
+
parallel (~> 1.10)
|
142
|
+
parser (>= 3.3.0.2)
|
143
|
+
rainbow (>= 2.2.2, < 4.0)
|
144
|
+
regexp_parser (>= 1.8, < 3.0)
|
145
|
+
rexml (>= 3.2.5, < 4.0)
|
146
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
147
|
+
ruby-progressbar (~> 1.7)
|
148
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
149
|
+
rubocop-ast (1.31.3)
|
150
|
+
parser (>= 3.3.1.0)
|
151
|
+
rubocop-shopify (2.15.1)
|
152
|
+
rubocop (~> 1.51)
|
153
|
+
ruby-progressbar (1.13.0)
|
154
|
+
signet (0.19.0)
|
155
|
+
addressable (~> 2.8)
|
156
|
+
faraday (>= 0.17.5, < 3.a)
|
157
|
+
jwt (>= 1.5, < 3.0)
|
158
|
+
multi_json (~> 1.10)
|
159
|
+
trailblazer-option (0.1.2)
|
160
|
+
tzinfo (2.0.6)
|
161
|
+
concurrent-ruby (~> 1.0)
|
162
|
+
uber (0.1.0)
|
163
|
+
unicode-display_width (2.5.0)
|
164
|
+
uri (0.13.2)
|
165
|
+
|
166
|
+
PLATFORMS
|
167
|
+
ruby
|
168
|
+
|
169
|
+
DEPENDENCIES
|
170
|
+
asset_cloud!
|
171
|
+
aws-sdk-s3 (>= 1.60.2)
|
172
|
+
google-cloud-storage
|
173
|
+
pry
|
174
|
+
pry-byebug
|
175
|
+
rake
|
176
|
+
rspec
|
177
|
+
rubocop-shopify
|
178
|
+
|
179
|
+
BUNDLED WITH
|
180
|
+
2.5.9
|
data/History.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Asset Cloud Version History
|
2
2
|
|
3
|
+
## Version 2.7.3, 2025-07-31
|
4
|
+
|
5
|
+
* Refactor AssetCloud::Callbacks.execute_callbacks to allow for subclassing
|
6
|
+
* Fix usage of Procs with callback methods
|
7
|
+
|
8
|
+
## Version 2.7.2, 2023-04-20
|
9
|
+
|
10
|
+
* Swap the order of operations for checking UUID and asset exist logic in free key locator (https://github.com/Shopify/asset_cloud/pull/83)
|
11
|
+
|
3
12
|
## Version 2.7.1, 2022-03-18
|
4
13
|
|
5
14
|
* Fix incorrect invocation of callbacks defined in external classes (https://github.com/Shopify/asset_cloud/issues/71)
|
data/README.rdoc
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
{<img src="https://travis-ci.org/Shopify/asset_cloud.png?branch=master" alt="Build Status" />}[https://travis-ci.org/Shopify/asset_cloud]
|
2
|
-
|
3
1
|
= AssetCloud
|
4
2
|
|
5
3
|
An abstraction layer around arbitrary and diverse asset stores.
|
@@ -43,4 +41,4 @@ Note that the automatic process does not create a new {release}[https://github.c
|
|
43
41
|
|
44
42
|
== Copyright
|
45
43
|
|
46
|
-
Copyright (c) 2008-
|
44
|
+
Copyright (c) 2008-2025 Tobias Lütke & Shopify, Inc. Released under the MIT license (see LICENSE for details).
|
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.3"
|
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 = ">= 3.0.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
|