model_attachment 0.0.6 → 0.0.7
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/lib/model_attachment.rb +39 -16
- metadata +24 -13
data/lib/model_attachment.rb
CHANGED
@@ -14,7 +14,7 @@ require 'model_attachment/amazon'
|
|
14
14
|
|
15
15
|
# The base module that gets included in ActiveRecord::Base.
|
16
16
|
module ModelAttachment
|
17
|
-
VERSION = "0.0.
|
17
|
+
VERSION = "0.0.7"
|
18
18
|
|
19
19
|
class << self
|
20
20
|
|
@@ -70,6 +70,7 @@ module ModelAttachment
|
|
70
70
|
before_destroy :destroy_attached_files
|
71
71
|
|
72
72
|
end
|
73
|
+
|
73
74
|
|
74
75
|
# Places ActiveRecord-style validations on the size of the file assigned. The
|
75
76
|
# possible options are:
|
@@ -126,21 +127,42 @@ module ModelAttachment
|
|
126
127
|
proto = options[:proto] || "http"
|
127
128
|
port = options[:port]
|
128
129
|
server_name = options[:server_name] || "localhost"
|
129
|
-
url_path = options[:path] || "/
|
130
|
+
url_path = options[:path] || "/#{self.class.to_s.downcase.pluralize}/deliver/"
|
130
131
|
type = options[:type]
|
131
|
-
server_name += ":" + port if port
|
132
|
+
server_name += ":" + port.to_s if port
|
133
|
+
type_string = "?type=#{type}" if type
|
134
|
+
|
135
|
+
unless self.class.attachment_options[:aws]
|
136
|
+
bucket = nil
|
137
|
+
end
|
138
|
+
|
139
|
+
# if files are public, serve public url
|
140
|
+
if public?
|
141
|
+
url_path = path.gsub(/^\/public(.*)/, '\1')
|
142
|
+
type_string = "_#{type}" if type
|
143
|
+
url = "#{proto}://#{server_name}#{url_path}#{basename}#{type_string}#{extension}"
|
144
|
+
elsif !bucket.nil?
|
145
|
+
# if bucket is set, then use aws url
|
146
|
+
aws_url(type)
|
147
|
+
else
|
148
|
+
# otherwise use private url with deliver
|
149
|
+
url = "#{proto}://#{server_name}#{url_path}#{id}#{type_string}"
|
150
|
+
end
|
132
151
|
|
133
|
-
url = (bucket.nil? ? "#{proto}://#{server_name}#{url_path}?id=#{id}" : aws_url(type))
|
134
152
|
log("Providing URL: #{url}")
|
135
153
|
return url
|
136
154
|
end
|
137
155
|
|
156
|
+
def public?
|
157
|
+
(path =~ /^\/public/)
|
158
|
+
end
|
159
|
+
|
138
160
|
# returns the rails path of the file
|
139
161
|
def path
|
140
162
|
if (self.class.attachment_options[:path])
|
141
|
-
return
|
163
|
+
return interpolate(self.class.attachment_options[:path])
|
142
164
|
else
|
143
|
-
return "/
|
165
|
+
return "/public/#{self.class.to_s.downcase.pluralize}/" + sprintf("%04d", id) + "/"
|
144
166
|
end
|
145
167
|
end
|
146
168
|
|
@@ -175,6 +197,17 @@ module ModelAttachment
|
|
175
197
|
content_type =~ /^image\//
|
176
198
|
end
|
177
199
|
|
200
|
+
# create the path based on the template
|
201
|
+
def interpolate(path, *args)
|
202
|
+
#methods = ["domain", "folder", "document", "version", "user", "account"]
|
203
|
+
self.class.instance_methods(false).sort.reverse.inject( path.dup ) do |result, tag|
|
204
|
+
#$stderr.puts("Result: #{result} Tag: #{tag}")
|
205
|
+
result.gsub(/:#{tag}/) do |match|
|
206
|
+
send( tag, *args )
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
178
211
|
private
|
179
212
|
|
180
213
|
def process_image_types #:nodoc:
|
@@ -236,16 +269,6 @@ module ModelAttachment
|
|
236
269
|
end
|
237
270
|
end
|
238
271
|
|
239
|
-
# create the path based on the template
|
240
|
-
def interpolate(path, *args)
|
241
|
-
methods = ["domain", "folder", "document", "version"]
|
242
|
-
methods.reverse.inject( path.dup ) do |result, tag|
|
243
|
-
result.gsub(/:#{tag}/) do |match|
|
244
|
-
send( tag, *args )
|
245
|
-
end
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
272
|
# removes any files associated with this instance
|
250
273
|
def destroy_attached_files
|
251
274
|
begin
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: model_attachment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 7
|
9
|
+
version: 0.0.7
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Steve Walker
|
@@ -9,29 +14,33 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-04 00:00:00 -04:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: sqlite3-ruby
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
23
29
|
version: "0"
|
24
|
-
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
25
32
|
- !ruby/object:Gem::Dependency
|
26
33
|
name: activerecord
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - ">="
|
32
38
|
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
33
41
|
version: "0"
|
34
|
-
|
42
|
+
type: :development
|
43
|
+
version_requirements: *id002
|
35
44
|
description: Simple file attachment for ActiveRecord models
|
36
45
|
email: steve@blackboxweb.com
|
37
46
|
executables: []
|
@@ -65,18 +74,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
74
|
requirements:
|
66
75
|
- - ">="
|
67
76
|
- !ruby/object:Gem::Version
|
77
|
+
segments:
|
78
|
+
- 0
|
68
79
|
version: "0"
|
69
|
-
version:
|
70
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
81
|
requirements:
|
72
82
|
- - ">="
|
73
83
|
- !ruby/object:Gem::Version
|
84
|
+
segments:
|
85
|
+
- 0
|
74
86
|
version: "0"
|
75
|
-
version:
|
76
87
|
requirements:
|
77
88
|
- ImageMagick
|
78
89
|
rubyforge_project: model_attachment
|
79
|
-
rubygems_version: 1.3.
|
90
|
+
rubygems_version: 1.3.6
|
80
91
|
signing_key:
|
81
92
|
specification_version: 3
|
82
93
|
summary: Attach files to ActiveRecord models and run commands on images
|