asset_cloud 2.2.1 → 2.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d836e4ffccd7ef2587c6d9059f2d3cbf27945e8
4
- data.tar.gz: b3a39486d765695ba72331d9094ca5c8e6fc27c0
3
+ metadata.gz: c234877222854a009ce8f3cd01cc47e3827ce575
4
+ data.tar.gz: d0cfa40ee942e449c59b9bb6f2b362a7565e9ed1
5
5
  SHA512:
6
- metadata.gz: bfc48a05fd7bdc09cef91ff32882d667cd6774ef72e550a0dd772f7c5bf320955f4040d9bd52142c3941b094751bca6a8bc6d6e3a4c2f7714a1b4340e92b2689
7
- data.tar.gz: 2fd7ff5b0d9e0036de07b8feb7953845a4d4063185bc9f460bfab7bf5f64ac39aeabd499a565251b11bbf656b277ecac937b15180bc837a0c63926f1c49d703a
6
+ metadata.gz: 71784bf57b3a79dd4cbe76a6d5921617ae368a62871e3289f9a50bef1273901d985c0553fa8868f742a1959f39c578f1b8e33f64c6625fae686e1ceb629fac1b
7
+ data.tar.gz: b520683f21e5fafacac076b20fee73d08744589b9631e5176d1e48edf9744d24b0e3bd6f5693f850b99e68a9abd0bf2ce256ed50c6831a3287ce99c22a5498ea
data/.travis.yml CHANGED
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
+ before_install:
3
+ - gem install bundler
2
4
  rvm:
3
5
  - '1.9.3'
4
6
  - '2.0'
data/History.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Asset Cloud Version History
2
2
 
3
+ ## Version 2.2.2, 2016-02-11
4
+
5
+ * Allow asset_class to be a proc which determines the class to use within a bucket (https://github.com/Shopify/asset_cloud/pull/15)
6
+
3
7
  ## Version 2.2.0, 2015-03-17
4
8
 
5
9
  * Reduce the limitations on filenames so as not to catch valid filenames. (https://github.com/Shopify/asset_cloud/pull/12)
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.2.1"
5
+ s.version = "2.2.2"
6
6
 
7
7
  s.authors = %w(Shopify)
8
8
  s.summary = %q{An abstraction layer around arbitrary and diverse asset stores.}
@@ -60,7 +60,10 @@ module AssetCloud
60
60
  self.asset_classes[bucket_name.to_sym] = asset_class if asset_class
61
61
  else
62
62
  self.root_bucket_class = bucket_class
63
- self.root_asset_class = asset_class if asset_class
63
+ if asset_class
64
+ raise ArgumentError, 'asset_class on the root bucket cannot be a proc' if asset_class.is_a?(Proc)
65
+ self.root_asset_class = asset_class
66
+ end
64
67
  end
65
68
  end
66
69
 
@@ -216,7 +219,10 @@ module AssetCloud
216
219
  end
217
220
 
218
221
  def asset_class_for(key)
219
- klass = self.class.asset_classes[bucket_symbol_for_key(key)] || self.class.root_asset_class
222
+ klass = self.class.asset_classes[bucket_symbol_for_key(key)]
223
+ klass = klass.call(key) if klass.is_a?(Proc)
224
+ klass ||= self.class.root_asset_class
225
+
220
226
  constantize_if_necessary(klass)
221
227
  end
222
228
 
data/spec/base_spec.rb CHANGED
@@ -3,10 +3,15 @@ require 'spec_helper'
3
3
  class SpecialAsset < AssetCloud::Asset
4
4
  end
5
5
 
6
- class BasicCloud < AssetCloud::Base
7
- bucket :special, AssetCloud::MemoryBucket, :asset_class => SpecialAsset
6
+ class LiquidAsset < AssetCloud::Asset
8
7
  end
9
8
 
9
+ class BasicCloud < AssetCloud::Base
10
+ bucket :special, AssetCloud::MemoryBucket, asset_class: SpecialAsset
11
+ bucket :conditional, AssetCloud::MemoryBucket, asset_class: Proc.new {|key|
12
+ LiquidAsset if key.ends_with?('.liquid')
13
+ }
14
+ end
10
15
 
11
16
  describe BasicCloud do
12
17
  directory = File.dirname(__FILE__) + '/files'
@@ -177,6 +182,15 @@ describe BasicCloud do
177
182
  @fs.build('assets/foo').should be_instance_of(AssetCloud::Asset)
178
183
  @fs.build('special/foo').should be_instance_of(SpecialAsset)
179
184
  end
185
+
186
+ it "should allow specifying a proc that determines the class to use, using the default bucket when returning nil" do
187
+ @fs.build('conditional/default.js').should be_instance_of(AssetCloud::Asset)
188
+ @fs.build('conditional/better.liquid').should be_instance_of(LiquidAsset)
189
+ end
190
+
191
+ it "should raise " do
192
+ expect { BasicCloud.bucket(AssetCloud::MemoryBucket, asset_class: Proc.new {}) }.to(raise_error(ArgumentError))
193
+ end
180
194
  end
181
195
 
182
196
  describe "MATCH_BUCKET" 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.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-24 00:00:00.000000000 Z
11
+ date: 2016-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport