asset_cloud 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/Gemfile +3 -0
  4. data/LICENSE +20 -0
  5. data/README.rdoc +13 -0
  6. data/Rakefile +24 -0
  7. data/asset_cloud.gemspec +24 -0
  8. data/lib/asset_cloud.rb +54 -0
  9. data/lib/asset_cloud/asset.rb +187 -0
  10. data/lib/asset_cloud/asset_extension.rb +42 -0
  11. data/lib/asset_cloud/base.rb +247 -0
  12. data/lib/asset_cloud/bucket.rb +39 -0
  13. data/lib/asset_cloud/buckets/active_record_bucket.rb +57 -0
  14. data/lib/asset_cloud/buckets/blackhole_bucket.rb +23 -0
  15. data/lib/asset_cloud/buckets/bucket_chain.rb +84 -0
  16. data/lib/asset_cloud/buckets/file_system_bucket.rb +79 -0
  17. data/lib/asset_cloud/buckets/invalid_bucket.rb +28 -0
  18. data/lib/asset_cloud/buckets/memory_bucket.rb +42 -0
  19. data/lib/asset_cloud/buckets/versioned_memory_bucket.rb +33 -0
  20. data/lib/asset_cloud/callbacks.rb +63 -0
  21. data/lib/asset_cloud/free_key_locator.rb +28 -0
  22. data/lib/asset_cloud/metadata.rb +29 -0
  23. data/lib/asset_cloud/validations.rb +52 -0
  24. data/spec/active_record_bucket_spec.rb +95 -0
  25. data/spec/asset_extension_spec.rb +103 -0
  26. data/spec/asset_spec.rb +177 -0
  27. data/spec/base_spec.rb +114 -0
  28. data/spec/blackhole_bucket_spec.rb +41 -0
  29. data/spec/bucket_chain_spec.rb +158 -0
  30. data/spec/callbacks_spec.rb +125 -0
  31. data/spec/file_system_spec.rb +74 -0
  32. data/spec/files/products/key.txt +1 -0
  33. data/spec/files/versioned_stuff/foo +1 -0
  34. data/spec/find_free_key_spec.rb +39 -0
  35. data/spec/memory_bucket_spec.rb +52 -0
  36. data/spec/spec_helper.rb +5 -0
  37. data/spec/validations_spec.rb +53 -0
  38. data/spec/versioned_memory_bucket_spec.rb +36 -0
  39. metadata +151 -0
@@ -0,0 +1 @@
1
+ value
@@ -0,0 +1 @@
1
+ four
@@ -0,0 +1,39 @@
1
+
2
+ require '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 a UUID to the key before the extension if key is taken " do
18
+ SecureRandom.stub(:uuid).and_return('moo')
19
+ FindFreeKey.should_receive(:exist?).with('free.txt').and_return(true)
20
+ FindFreeKey.should_receive(:exist?).with('free_moo.txt').and_return(false)
21
+
22
+ FindFreeKey.find_free_key_like('free.txt').should == 'free_moo.txt'
23
+ end
24
+
25
+
26
+ it "should not strip any directory information from the key" do
27
+ SecureRandom.stub(:uuid).and_return('moo')
28
+ FindFreeKey.should_receive(:exist?).with('products/images/image.gif').and_return(true)
29
+ FindFreeKey.should_receive(:exist?).with('products/images/image_moo.gif').and_return(false)
30
+
31
+ FindFreeKey.find_free_key_like('products/images/image.gif').should == 'products/images/image_moo.gif'
32
+ end
33
+
34
+ it "should raise an exception if the randomly chosen value (after 10 attempts) is also taken" do
35
+ FindFreeKey.stub(:exist?).and_return(true)
36
+ lambda { FindFreeKey.find_free_key_like('free.txt') }.should raise_error(StandardError)
37
+ end
38
+
39
+ end
@@ -0,0 +1,52 @@
1
+ require '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
+ describe "#versioned?" do
29
+ it "should return false" do
30
+ @fs.buckets[:memory].versioned?.should == false
31
+ end
32
+ end
33
+
34
+ describe '#ls' do
35
+ before do
36
+ %w{a b}.each do |letter|
37
+ 2.times {|number| @fs.write("memory/#{letter}#{number}",'.')}
38
+ end
39
+ end
40
+
41
+ it "should return a list of assets which start with the given prefix" do
42
+ @fs.buckets[:memory].ls('memory/a').size.should == 2
43
+ end
44
+
45
+ it "should return a list of all assets when a prefix is not given" do
46
+ @fs.buckets[:memory].ls.size.should == 4
47
+ end
48
+ end
49
+
50
+
51
+
52
+ end
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ require 'active_support/all'
4
+ $:<< File.dirname(__FILE__) + "/../lib"
5
+ require 'asset_cloud'
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ class ValidatedAsset < AssetCloud::Asset
4
+ validate :no_cats
5
+
6
+ private
7
+ def no_cats
8
+ add_error('no cats allowed!') if value =~ /cat/i
9
+ add_warning('bad dog!', 'wet dog smell!') if value =~ /dog/i
10
+ end
11
+ end
12
+
13
+ class BasicCloud < AssetCloud::Base
14
+ bucket :dog_pound, AssetCloud::MemoryBucket, :asset_class => ValidatedAsset
15
+ end
16
+
17
+ describe ValidatedAsset do
18
+ before(:each) do
19
+ @cloud = BasicCloud.new(File.dirname(__FILE__) + '/files', 'http://assets/')
20
+ @cat = @cloud.build('dog_pound/fido', 'cat')
21
+ @dog = @cloud.build('dog_pound/fido', 'dog')
22
+ end
23
+
24
+ describe "#store" do
25
+ it "should not store the asset unless validations pass" do
26
+ @cloud.should_receive(:write).with('dog_pound/fido', 'dog').and_return(true)
27
+
28
+ @cat.store
29
+ @cat.store.should == false
30
+ @cat.errors.should == ['no cats allowed!']
31
+ @dog.store.should == true
32
+ end
33
+
34
+ it "should store asset with warnings and save them in the warnings array" do
35
+ @dog.store.should == true
36
+ @dog.warnings.should == ['bad dog!', 'wet dog smell!']
37
+ @cat.store.should == false
38
+ @cat.warnings.should == []
39
+ end
40
+ end
41
+
42
+ describe "#valid?" do
43
+ it "should clear errors, run validations, and return validity" do
44
+ @cat.store
45
+ @cat.errors.should == ['no cats allowed!']
46
+ @cat.valid?.should == false
47
+ @cat.errors.should == ['no cats allowed!']
48
+ @cat.value = 'disguised feline'
49
+ @cat.valid?.should == true
50
+ @cat.errors.should be_empty
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ class VersionedMemoryCloud < AssetCloud::Base
4
+ bucket :memory, AssetCloud::VersionedMemoryBucket
5
+ end
6
+
7
+ describe AssetCloud::VersionedMemoryBucket do
8
+ directory = File.dirname(__FILE__) + '/files'
9
+
10
+ before do
11
+ @fs = VersionedMemoryCloud.new(directory , 'http://assets/files' )
12
+ %w{one two three}.each do |content|
13
+ @fs.write("memory/foo", content)
14
+ end
15
+ end
16
+
17
+ describe '#versioned?' do
18
+ it "should return true" do
19
+ @fs.buckets[:memory].versioned?.should == true
20
+ end
21
+ end
22
+
23
+ describe '#read_version' do
24
+ it "should return the appropriate data when given a key and version" do
25
+ @fs.read_version('memory/foo', 1).should == 'one'
26
+ @fs.read_version('memory/foo', 3).should == 'three'
27
+ end
28
+ end
29
+
30
+ describe '#versions' do
31
+ it "should return a list of available version identifiers for the given key" do
32
+ @fs.versions('memory/foo').should == [1,2,3]
33
+ end
34
+ end
35
+
36
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asset_cloud
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Shopify
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2009-08-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: class_inheritable_attributes
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: An abstraction layer around arbitrary and diverse asset stores.
70
+ email: developers@shopify.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - .gitignore
76
+ - Gemfile
77
+ - LICENSE
78
+ - README.rdoc
79
+ - Rakefile
80
+ - asset_cloud.gemspec
81
+ - lib/asset_cloud.rb
82
+ - lib/asset_cloud/asset.rb
83
+ - lib/asset_cloud/asset_extension.rb
84
+ - lib/asset_cloud/base.rb
85
+ - lib/asset_cloud/bucket.rb
86
+ - lib/asset_cloud/buckets/active_record_bucket.rb
87
+ - lib/asset_cloud/buckets/blackhole_bucket.rb
88
+ - lib/asset_cloud/buckets/bucket_chain.rb
89
+ - lib/asset_cloud/buckets/file_system_bucket.rb
90
+ - lib/asset_cloud/buckets/invalid_bucket.rb
91
+ - lib/asset_cloud/buckets/memory_bucket.rb
92
+ - lib/asset_cloud/buckets/versioned_memory_bucket.rb
93
+ - lib/asset_cloud/callbacks.rb
94
+ - lib/asset_cloud/free_key_locator.rb
95
+ - lib/asset_cloud/metadata.rb
96
+ - lib/asset_cloud/validations.rb
97
+ - spec/active_record_bucket_spec.rb
98
+ - spec/asset_extension_spec.rb
99
+ - spec/asset_spec.rb
100
+ - spec/base_spec.rb
101
+ - spec/blackhole_bucket_spec.rb
102
+ - spec/bucket_chain_spec.rb
103
+ - spec/callbacks_spec.rb
104
+ - spec/file_system_spec.rb
105
+ - spec/files/products/key.txt
106
+ - spec/files/versioned_stuff/foo
107
+ - spec/find_free_key_spec.rb
108
+ - spec/memory_bucket_spec.rb
109
+ - spec/spec_helper.rb
110
+ - spec/validations_spec.rb
111
+ - spec/versioned_memory_bucket_spec.rb
112
+ homepage: http://github.com/Shopify/asset_cloud
113
+ licenses: []
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.0.14
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: An abstraction layer around arbitrary and diverse asset stores.
135
+ test_files:
136
+ - spec/active_record_bucket_spec.rb
137
+ - spec/asset_extension_spec.rb
138
+ - spec/asset_spec.rb
139
+ - spec/base_spec.rb
140
+ - spec/blackhole_bucket_spec.rb
141
+ - spec/bucket_chain_spec.rb
142
+ - spec/callbacks_spec.rb
143
+ - spec/file_system_spec.rb
144
+ - spec/files/products/key.txt
145
+ - spec/files/versioned_stuff/foo
146
+ - spec/find_free_key_spec.rb
147
+ - spec/memory_bucket_spec.rb
148
+ - spec/spec_helper.rb
149
+ - spec/validations_spec.rb
150
+ - spec/versioned_memory_bucket_spec.rb
151
+ has_rdoc: