Shopify-asset_cloud 0.5.1
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.
- data/.document +3 -0
- data/.gitignore +3 -0
- data/CHANGELOG +7 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +37 -0
- data/VERSION +1 -0
- data/asset_cloud.gemspec +79 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/asset_cloud/asset.rb +119 -0
- data/lib/asset_cloud/base.rb +178 -0
- data/lib/asset_cloud/blackhole_bucket.rb +24 -0
- data/lib/asset_cloud/bucket.rb +57 -0
- data/lib/asset_cloud/callbacks.rb +65 -0
- data/lib/asset_cloud/file_system_bucket.rb +79 -0
- data/lib/asset_cloud/free_key_locator.rb +39 -0
- data/lib/asset_cloud/invalid_bucket.rb +28 -0
- data/lib/asset_cloud/memory_bucket.rb +40 -0
- data/lib/asset_cloud/metadata.rb +30 -0
- data/lib/asset_cloud.rb +32 -0
- data/spec/asset_spec.rb +135 -0
- data/spec/base_spec.rb +77 -0
- data/spec/blackhole_bucket_spec.rb +41 -0
- data/spec/bucket_spec.rb +41 -0
- data/spec/callbacks_spec.rb +108 -0
- data/spec/file_system_spec.rb +73 -0
- data/spec/files/products/key.txt +1 -0
- data/spec/find_free_key_spec.rb +66 -0
- data/spec/memory_bucket_spec.rb +30 -0
- data/spec/regexp_spec.rb +20 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +4 -0
- metadata +95 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
class FileSystemCloud < AssetCloud::Base
|
4
|
+
bucket AssetCloud::InvalidBucket
|
5
|
+
bucket :products, AssetCloud::FileSystemBucket
|
6
|
+
bucket :tmp, AssetCloud::FileSystemBucket
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
describe FileSystemCloud do
|
11
|
+
directory = File.dirname(__FILE__) + '/files'
|
12
|
+
|
13
|
+
before do
|
14
|
+
@fs = FileSystemCloud.new(directory , 'http://assets/files' )
|
15
|
+
FileUtils.mkdir_p(directory + '/tmp')
|
16
|
+
end
|
17
|
+
|
18
|
+
after do
|
19
|
+
FileUtils.rm_rf(directory + '/tmp')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should use invalid bucket for random directories" do
|
23
|
+
@fs.bucket_for('does-not-exist/file.txt').should be_an_instance_of(AssetCloud::InvalidBucket)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should use filesystem bucekt for products/ and tmp/ directories" do
|
27
|
+
@fs.bucket_for('products/file.txt').should be_an_instance_of(AssetCloud::FileSystemBucket)
|
28
|
+
@fs.bucket_for('tmp/file.txt').should be_an_instance_of(AssetCloud::FileSystemBucket)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return Asset for existing files" do
|
32
|
+
@fs['products/key.txt'].exist?.should == true
|
33
|
+
@fs['products/key.txt'].should be_an_instance_of(AssetCloud::Asset)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should be able to test if a file exists or not" do
|
37
|
+
@fs.stat('products/key.txt').exist?.should == true
|
38
|
+
@fs.stat('products/key2.txt').exist?.should == false
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be able to list files" do
|
42
|
+
@fs.ls('products').collect(&:key).should == ['products/key.txt']
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'when modifying file system' do
|
46
|
+
|
47
|
+
it "should call write after storing an asset" do
|
48
|
+
@fs.buckets[:tmp].should_receive(:write).with('tmp/new_file.test', 'hello world').and_return(true)
|
49
|
+
|
50
|
+
@fs.build('tmp/new_file.test', 'hello world').store
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should be able to create new files" do
|
54
|
+
@fs.build('tmp/new_file.test', 'hello world').store
|
55
|
+
|
56
|
+
@fs.stat('tmp/new_file.test').exist.should == true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should be able to create new files with simple assignment" do
|
60
|
+
@fs['tmp/new_file.test'] = 'hello world'
|
61
|
+
|
62
|
+
@fs.stat('tmp/new_file.test').exist.should == true
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should create directories as needed" do
|
66
|
+
@fs.build('tmp/new_file.test', 'hello world').store
|
67
|
+
|
68
|
+
@fs['tmp/new_file.test'].exist?.should == true
|
69
|
+
@fs['tmp/new_file.test'].value.should == 'hello world'
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
value
|
@@ -0,0 +1,66 @@
|
|
1
|
+
|
2
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
+
|
4
|
+
|
5
|
+
class FindFreeKey
|
6
|
+
extend AssetCloud::FreeKeyLocator
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "FreeFilenameLocator", 'when asked to return a free key such as the one passed in' do
|
10
|
+
|
11
|
+
it "should simply return the key if it happens to be free" do
|
12
|
+
FindFreeKey.should_receive(:exist?).with('free.txt').and_return(false)
|
13
|
+
|
14
|
+
FindFreeKey.find_free_key_like('free.txt').should == 'free.txt'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should append _1 to the key before the extension if key is taken " do
|
18
|
+
FindFreeKey.should_receive(:exist?).with('free.txt').and_return(true)
|
19
|
+
FindFreeKey.should_receive(:exist?).with('free_1.txt').and_return(false)
|
20
|
+
|
21
|
+
FindFreeKey.find_free_key_like('free.txt').should == 'free_1.txt'
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
it "should should increment the number at the end of the basename until it finds a free filename" do
|
26
|
+
FindFreeKey.should_receive(:exist?).with('free.txt').and_return(true)
|
27
|
+
FindFreeKey.should_receive(:exist?).with('free_1.txt').and_return(true)
|
28
|
+
FindFreeKey.should_receive(:exist?).with('free_2.txt').and_return(true)
|
29
|
+
FindFreeKey.should_receive(:exist?).with('free_3.txt').and_return(false)
|
30
|
+
|
31
|
+
FindFreeKey.find_free_key_like('free.txt').should == 'free_3.txt'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should recognize a number at the end of the filename and simply increment that one" do
|
35
|
+
FindFreeKey.should_receive(:exist?).with('file9.txt').and_return(true)
|
36
|
+
FindFreeKey.should_receive(:exist?).with('file10.txt').and_return(false)
|
37
|
+
|
38
|
+
FindFreeKey.find_free_key_like('file9.txt').should == 'file10.txt'
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
it "should not strip any directory information from the key" do
|
43
|
+
FindFreeKey.should_receive(:exist?).with('products/images/image.gif').and_return(true)
|
44
|
+
FindFreeKey.should_receive(:exist?).with('products/images/image_1.gif').and_return(true)
|
45
|
+
FindFreeKey.should_receive(:exist?).with('products/images/image_2.gif').and_return(false)
|
46
|
+
|
47
|
+
FindFreeKey.find_free_key_like('products/images/image.gif').should == 'products/images/image_2.gif'
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should just pick a random value after 10 sequential attempts" do
|
51
|
+
FindFreeKey.should_receive(:exist?).with('free.txt').and_return(true)
|
52
|
+
FindFreeKey.should_receive(:exist?).with('free_1.txt').and_return(true)
|
53
|
+
FindFreeKey.should_receive(:exist?).with('free_2.txt').and_return(true)
|
54
|
+
FindFreeKey.should_receive(:exist?).with('free_3.txt').and_return(true)
|
55
|
+
FindFreeKey.should_receive(:exist?).with('free_4.txt').and_return(true)
|
56
|
+
FindFreeKey.should_receive(:exist?).with('free_5.txt').and_return(true)
|
57
|
+
FindFreeKey.should_receive(:exist?).with('free_6.txt').and_return(true)
|
58
|
+
FindFreeKey.should_receive(:exist?).with('free_7.txt').and_return(true)
|
59
|
+
FindFreeKey.should_receive(:exist?).with('free_8.txt').and_return(true)
|
60
|
+
FindFreeKey.should_receive(:exist?).with('free_9.txt').and_return(true)
|
61
|
+
FindFreeKey.should_receive(:exist?).with('free_10.txt').and_return(true)
|
62
|
+
|
63
|
+
lambda { FindFreeKey.find_free_key_like('free.txt').should == 'file10.txt' }.should raise_error(Spec::Mocks::MockExpectationError)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
class MemoryCloud < AssetCloud::Base
|
4
|
+
bucket :memory, AssetCloud::MemoryBucket
|
5
|
+
end
|
6
|
+
|
7
|
+
describe AssetCloud::MemoryBucket do
|
8
|
+
directory = File.dirname(__FILE__) + '/files'
|
9
|
+
|
10
|
+
before do
|
11
|
+
@fs = MemoryCloud.new(directory , 'http://assets/files' )
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
describe 'modifying items in subfolder' do
|
16
|
+
|
17
|
+
it "should return nil when file does not exist" do
|
18
|
+
@fs['memory/essay.txt'].exist?.should == false
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return set content when asked for the same file" do
|
22
|
+
@fs['memory/essay.txt'] = 'text'
|
23
|
+
@fs['memory/essay.txt'].value.should == 'text'
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
end
|
data/spec/regexp_spec.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
describe Regexp do
|
2
|
+
|
3
|
+
before { @regexp = /^(\w+)(\/|$)/ }
|
4
|
+
|
5
|
+
it "should match following stuff " do
|
6
|
+
|
7
|
+
'products/key.txt' =~ @regexp
|
8
|
+
$1.should == 'products'
|
9
|
+
|
10
|
+
'products/subpath/key.txt' =~ @regexp
|
11
|
+
$1.should == 'products'
|
12
|
+
|
13
|
+
'key.txt' =~ @regexp
|
14
|
+
$1.should == nil
|
15
|
+
|
16
|
+
'products' =~ @regexp
|
17
|
+
$1.should == 'products'
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Shopify-asset_cloud
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shopify
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-17 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: An abstraction layer around arbitrary and diverse asset stores.
|
17
|
+
email: developers@shopify.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- .document
|
27
|
+
- .gitignore
|
28
|
+
- CHANGELOG
|
29
|
+
- LICENSE
|
30
|
+
- README.rdoc
|
31
|
+
- Rakefile
|
32
|
+
- VERSION
|
33
|
+
- asset_cloud.gemspec
|
34
|
+
- init.rb
|
35
|
+
- install.rb
|
36
|
+
- lib/asset_cloud.rb
|
37
|
+
- lib/asset_cloud/asset.rb
|
38
|
+
- lib/asset_cloud/base.rb
|
39
|
+
- lib/asset_cloud/blackhole_bucket.rb
|
40
|
+
- lib/asset_cloud/bucket.rb
|
41
|
+
- lib/asset_cloud/callbacks.rb
|
42
|
+
- lib/asset_cloud/file_system_bucket.rb
|
43
|
+
- lib/asset_cloud/free_key_locator.rb
|
44
|
+
- lib/asset_cloud/invalid_bucket.rb
|
45
|
+
- lib/asset_cloud/memory_bucket.rb
|
46
|
+
- lib/asset_cloud/metadata.rb
|
47
|
+
- spec/asset_spec.rb
|
48
|
+
- spec/base_spec.rb
|
49
|
+
- spec/blackhole_bucket_spec.rb
|
50
|
+
- spec/bucket_spec.rb
|
51
|
+
- spec/callbacks_spec.rb
|
52
|
+
- spec/file_system_spec.rb
|
53
|
+
- spec/files/products/key.txt
|
54
|
+
- spec/find_free_key_spec.rb
|
55
|
+
- spec/memory_bucket_spec.rb
|
56
|
+
- spec/regexp_spec.rb
|
57
|
+
- spec/spec.opts
|
58
|
+
- spec/spec_helper.rb
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://github.com/Shopify/asset_cloud
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --charset=UTF-8
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.2.0
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: An abstraction layer around arbitrary and diverse asset stores.
|
85
|
+
test_files:
|
86
|
+
- spec/asset_spec.rb
|
87
|
+
- spec/base_spec.rb
|
88
|
+
- spec/blackhole_bucket_spec.rb
|
89
|
+
- spec/bucket_spec.rb
|
90
|
+
- spec/callbacks_spec.rb
|
91
|
+
- spec/file_system_spec.rb
|
92
|
+
- spec/find_free_key_spec.rb
|
93
|
+
- spec/memory_bucket_spec.rb
|
94
|
+
- spec/regexp_spec.rb
|
95
|
+
- spec/spec_helper.rb
|