model_attachment 0.0.25 → 0.0.26
Sign up to get free protection for your applications and to get access to all the features.
data/lib/model_attachment.rb
CHANGED
@@ -59,8 +59,10 @@ module ModelAttachment
|
|
59
59
|
elsif !options[:aws].nil? && File.exist?(options[:aws])
|
60
60
|
include AmazonInstanceMethods
|
61
61
|
end
|
62
|
-
|
63
|
-
|
62
|
+
|
63
|
+
class_attribute :attachment_options
|
64
|
+
self.attachment_options = options
|
65
|
+
# write_inheritable_attribute(:attachment_options, options)
|
64
66
|
|
65
67
|
# must be before the save to save the attributes
|
66
68
|
before_save :save_attributes
|
@@ -110,7 +112,8 @@ module ModelAttachment
|
|
110
112
|
|
111
113
|
# Returns attachment options defined by each call to acts_as_attachment.
|
112
114
|
def attachment_options
|
113
|
-
read_inheritable_attribute(:attachment_options)
|
115
|
+
# read_inheritable_attribute(:attachment_options)
|
116
|
+
self.attachment_options
|
114
117
|
end
|
115
118
|
|
116
119
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module ModelAttachment
|
2
2
|
module AmazonInstanceMethods
|
3
|
+
attr_accessor :default_bucket
|
3
4
|
|
4
5
|
# returns the aws url
|
5
6
|
# +type+: type passed to has_attachment, ex. small, large
|
@@ -15,12 +16,6 @@ module ModelAttachment
|
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
|
-
# sets the default aws bucket
|
19
|
-
# +current_bucket+: set the current bucket, default 'globalfolders'
|
20
|
-
def default_bucket(current_bucket = 'globalfolders')
|
21
|
-
current_bucket
|
22
|
-
end
|
23
|
-
|
24
19
|
# creates the aws_key
|
25
20
|
# +type+: type passed to has_attachment, ex. small, large
|
26
21
|
def aws_key(type = "")
|
@@ -41,7 +36,8 @@ module ModelAttachment
|
|
41
36
|
:secret_access_key => config['secret_access_key'],
|
42
37
|
:use_ssl => true,
|
43
38
|
:persistent => true # if issues with disconnections, set to false
|
44
|
-
|
39
|
+
)
|
40
|
+
self.default_bucket = self.class.attachment_options[:bucket] || 'globalfolders'
|
45
41
|
else
|
46
42
|
raise "You must provide an amazon.yml config file"
|
47
43
|
end
|
@@ -63,7 +59,7 @@ module ModelAttachment
|
|
63
59
|
AWS::S3::S3Object.store(aws_key(name.to_s), open(full_filename, 'rb'), default_bucket, :content_type => content_type)
|
64
60
|
end
|
65
61
|
|
66
|
-
self.bucket = default_bucket
|
62
|
+
self.bucket = self.default_bucket
|
67
63
|
@dirty = true
|
68
64
|
save!
|
69
65
|
rescue AWS::S3::ResponseError => error
|
@@ -155,4 +151,4 @@ module ModelAttachment
|
|
155
151
|
end
|
156
152
|
|
157
153
|
end
|
158
|
-
end
|
154
|
+
end
|
@@ -82,7 +82,7 @@ end
|
|
82
82
|
class DocumentWithResize < Document
|
83
83
|
has_attachment :path => "/system/:domain/:folder/:document/:version/",
|
84
84
|
:types => {
|
85
|
-
:small => { :command => '/
|
85
|
+
:small => { :command => '/usr/local/bin/convert -geometry 100x100' }
|
86
86
|
}
|
87
87
|
end
|
88
88
|
|
@@ -90,8 +90,9 @@ class DocumentWithAWS < Document
|
|
90
90
|
has_attachment :path => "/system/:domain/:folder/:document/:version/",
|
91
91
|
:aws => File.join(Rails.root, "amazon.yml"),
|
92
92
|
:types => {
|
93
|
-
:small => { :command => '/
|
93
|
+
:small => { :command => '/usr/local/bin/convert -geometry 100x100' }
|
94
94
|
},
|
95
|
+
:bucket => 'test.globalfolders.com',
|
95
96
|
:logging => true
|
96
97
|
end
|
97
98
|
|
@@ -184,10 +185,10 @@ class ModelAttachmentTest < Test::Unit::TestCase
|
|
184
185
|
assert_equal "image/jpeg", document.content_type
|
185
186
|
|
186
187
|
document.move_to_amazon
|
187
|
-
assert_equal 'globalfolders', document.bucket
|
188
|
+
assert_equal 'test.globalfolders.com', document.bucket
|
188
189
|
|
189
|
-
assert_match /https:\/\/s3.amazonaws.com\/globalfolders\/system\/bbs\/1\/1\/0\/test3\.jpg/, document.url
|
190
|
-
assert_match /https:\/\/s3.amazonaws.com\/globalfolders\/system\/bbs\/1\/1\/0\/test3_small\.jpg/, document.url(:type => "small")
|
190
|
+
assert_match /https:\/\/s3.amazonaws.com\/test.globalfolders.com\/system\/bbs\/1\/1\/0\/test3\.jpg/, document.url
|
191
|
+
assert_match /https:\/\/s3.amazonaws.com\/test.globalfolders.com\/system\/bbs\/1\/1\/0\/test3_small\.jpg/, document.url(:type => "small")
|
191
192
|
|
192
193
|
assert !File.exists?(RAILS_ROOT + "/system/bbs/1/1/0/test3.jpg")
|
193
194
|
assert !File.exists?(RAILS_ROOT + "/system/bbs/1/1/0/test3_small.jpg")
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: model_attachment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.26
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Steve Walker
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2012-06-05 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -58,7 +58,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
hash: -
|
61
|
+
hash: -87829182241577493
|
62
62
|
segments:
|
63
63
|
- 0
|
64
64
|
version: "0"
|
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
71
|
requirements: []
|
72
72
|
|
73
73
|
rubyforge_project: model_attachment
|
74
|
-
rubygems_version: 1.
|
74
|
+
rubygems_version: 1.6.2
|
75
75
|
signing_key:
|
76
76
|
specification_version: 3
|
77
77
|
summary: A simple file attachment gem
|