dragonfly 0.9.9 → 0.9.10

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of dragonfly might be problematic. Click here for more details.

data/History.md CHANGED
@@ -1,3 +1,9 @@
1
+ 0.9.10 (2012-01-11)
2
+ ===================
3
+ Fixes
4
+ -----
5
+ - FileDataStore was causing errors when the storage path was flat (not in a directory structure)
6
+
1
7
  0.9.9 (2011-12-30)
2
8
  ==================
3
9
  Features
data/README.md CHANGED
@@ -13,7 +13,7 @@ For the lazy Rails user...
13
13
 
14
14
  ```ruby
15
15
  gem 'rack-cache', :require => 'rack/cache'
16
- gem 'dragonfly', '~>0.9.9'
16
+ gem 'dragonfly', '~>0.9.10'
17
17
  ```
18
18
 
19
19
  **Initializer** (e.g. config/initializers/dragonfly.rb):
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.9
1
+ 0.9.10
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "dragonfly"
8
- s.version = "0.9.9"
8
+ s.version = "0.9.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mark Evans"]
12
- s.date = "2011-12-30"
12
+ s.date = "2012-01-11"
13
13
  s.description = "Dragonfly is a framework that enables on-the-fly processing for any content type.\n It is especially suited to image handling. Its uses range from image thumbnails to standard attachments to on-demand text generation."
14
14
  s.email = "mark@new-bamboo.co.uk"
15
15
  s.extra_rdoc_files = [
@@ -40,7 +40,7 @@ The datastore remains as the {Dragonfly::DataStorage::FileDataStore FileDataStor
40
40
 
41
41
  application.rb if using with Rails:
42
42
 
43
- config.middleware.insert 0, 'Dragonfly::Middleware', :images
43
+ config.middleware.insert 1, 'Dragonfly::Middleware', :images
44
44
 
45
45
  We don't store the S3 access key and secret in the repository, rather we use Heroku's
46
46
  {http://docs.heroku.com/config-vars config variables} using the command line (we only have to do this once).
@@ -122,7 +122,7 @@ Note that the text generation options are meant to resemble css as much as possi
122
122
 
123
123
  You can use `padding-top`, `padding-left`, etc., as well as the standard css shortcuts for `padding` (it assumes unit is px).
124
124
 
125
- An alternative for `:font_family` is `:font` (see {http://www.imagemagick.org/script/command-line-options.php#font}), which could be a complete filename.
125
+ An alternative for `:font_family` is `:font` (see {http://www.imagemagick.org/script/command-line-options.php#font the imagemagick docs}), which could be a complete filename.
126
126
  Available fonts are those available on your system.
127
127
 
128
128
  Configuration
@@ -35,7 +35,7 @@ application.rb:
35
35
  Gemfile
36
36
  -------
37
37
 
38
- gem 'dragonfly', '~>0.9.9'
38
+ gem 'dragonfly', '~>0.9.10'
39
39
  gem 'rack-cache', :require => 'rack/cache'
40
40
 
41
41
  Capistrano
@@ -10,8 +10,8 @@ For most cases, this is the way to go - you have control over it and you can {fi
10
10
  However, if for whatever reason you must serve content from the datastore directly, e.g. for lightening the load on your server, Dragonfly
11
11
  provides a number of ways of doing this.
12
12
 
13
- Serving Original Content
14
- ------------------------
13
+ Original Content
14
+ ----------------
15
15
  The {file:DataStorage#File\_datastore FileDataStore}, {file:DataStorage#S3\_datastore S3DataStore} and
16
16
  {file:DataStorage#Couch\_datastore CouchDataStore} allow for serving data directly, so given a Dragonfly app
17
17
 
@@ -27,10 +27,30 @@ we can get the remote url using
27
27
 
28
28
  or from a model attachment:
29
29
 
30
- my_model.attachment.remote_url # http://my-bucket.s....
30
+ my_model.attachment.remote_url # http://my-bucket.s3.amazonaws.com/2011...
31
31
 
32
- Serving Processed Content
33
- -------------------------
32
+ Processed Content
33
+ -----------------
34
+ If using models, the quick and easy way to serve e.g. image thumbnails remotely is to process them _on upload_
35
+ like most other attachment ruby gems (see {file:Models#Up-front_thumbnailing}),
36
+ e.g. for my avatar model,
37
+
38
+ class Avatar
39
+ image_accessor :image do
40
+ copy_to(:small_image){|a| a.thumb('200x200#') }
41
+ end
42
+ image_accessor :small_image
43
+ end
44
+
45
+ Then we can use `remote_url` for for each accessor.
46
+
47
+ avatar.image.remote_url # http://my-bucket.s3.amazonaws.com/some/path.jpg
48
+ avatar.small_image.remote_url # http://my-bucket.s3.amazonaws.com/some/other/path.jpg
49
+
50
+ However, this has all the limitations that come with up-front processing, such as having to regenerate the thumbnail when the size requirement changes.
51
+
52
+ Serving Processed Content *on-the-fly*
53
+ --------------------------------------
34
54
  Serving processed versions of content such as thumbnails remotely is a bit more tricky as we need to upload the thumbnail
35
55
  to the datastore in the on-the-fly manner.
36
56
 
@@ -38,34 +58,35 @@ Dragonfly provides a way of doing this using `define_url` and `before_serve` met
38
58
 
39
59
  The details of keeping track of/expiring these thumbnails is up to you.
40
60
 
41
- Below is an example using an ActiveRecord 'Thumb' table to keep track of image thumbnails.
61
+ We need to keep track of which thumbnails have been already created, by storing a uid for each one.
62
+ Below is an example using an ActiveRecord 'Thumb' table to keep track of already created thumbnail uids.
42
63
  It has two string columns; 'job' and 'uid'.
43
64
 
44
65
  app.configure do |c|
45
66
 
46
- c.server.before_serve do |job, env|
47
- # Before serving, the first time it is requested...
48
- # store the thumbnail in the datastore
49
- uid = job.store
50
-
51
- # Keep track of its uid
52
- Thumb.create!(
53
- :uid => uid,
54
- :job => job.serialize # 'BAhbBls...' - holds all the job info
55
- ) # e.g. fetch 'some_uid' then resize to '40x40'
56
- end
57
-
58
67
  # Override the .url method...
59
68
  c.define_url do |app, job, opts|
60
69
  thumb = Thumb.find_by_job(job.serialize)
61
- # If (fetch 'some_uid' then resize to '40x40') has been stored already..
70
+ # If (fetch 'some_uid' then resize to '40x40') has been stored already, give the datastore's remote url ...
62
71
  if thumb
63
72
  app.datastore.url_for(thumb.uid)
64
- # ...otherwise serve from the Dragonfly server as per usual
73
+ # ...otherwise give the local Dragonfly server url
65
74
  else
66
75
  app.server.url_for(job)
67
76
  end
68
77
  end
78
+
79
+ # Before serving from the local Dragonfly server...
80
+ c.server.before_serve do |job, env|
81
+ # ...store the thumbnail in the datastore...
82
+ uid = job.store
83
+
84
+ # ...keep track of its uid so next time we can serve directly from the datastore
85
+ Thumb.create!(
86
+ :uid => uid,
87
+ :job => job.serialize # 'BAhbBls...' - holds all the job info
88
+ ) # e.g. fetch 'some_uid' then resize to '40x40'
89
+ end
69
90
 
70
91
  end
71
92
 
@@ -81,7 +81,7 @@ module Dragonfly
81
81
  private
82
82
 
83
83
  def absolute(relative_path)
84
- File.join(root_path, relative_path)
84
+ relative_path.to_s == '.' ? root_path : File.join(root_path, relative_path)
85
85
  end
86
86
 
87
87
  def relative(absolute_path)
@@ -91,6 +91,10 @@ module Dragonfly
91
91
  def directory_empty?(path)
92
92
  Dir.entries(path) == ['.','..']
93
93
  end
94
+
95
+ def root_path?(dir)
96
+ root_path == dir
97
+ end
94
98
 
95
99
  def meta_data_path(data_path)
96
100
  "#{data_path}.meta"
@@ -126,7 +130,7 @@ module Dragonfly
126
130
  containing_directory = Pathname.new(path).dirname
127
131
  containing_directory.ascend do |relative_dir|
128
132
  dir = absolute(relative_dir)
129
- FileUtils.rmdir dir if directory_empty?(dir)
133
+ FileUtils.rmdir dir if directory_empty?(dir) && !root_path?(dir)
130
134
  end
131
135
  end
132
136
 
@@ -174,6 +174,12 @@ describe Dragonfly::DataStorage::FileDataStore do
174
174
  @data_store.destroy(uid)
175
175
  @data_store.root_path.should be_an_empty_directory
176
176
  end
177
+
178
+ it "should not prune root_path directory when destroying file without directory prefix in path" do
179
+ uid = @data_store.store(@temp_object, :path => 'mate.png')
180
+ @data_store.destroy(uid)
181
+ @data_store.root_path.should be_an_empty_directory
182
+ end
177
183
 
178
184
  it "should raise an error if the data doesn't exist on destroy" do
179
185
  uid = @data_store.store(@temp_object)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dragonfly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
4
+ version: 0.9.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-30 00:00:00.000000000Z
12
+ date: 2012-01-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &2166406820 !ruby/object:Gem::Requirement
16
+ requirement: &70223626180020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2166406820
24
+ version_requirements: *70223626180020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: capybara
27
- requirement: &2166405800 !ruby/object:Gem::Requirement
27
+ requirement: &70223626179540 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2166405800
35
+ version_requirements: *70223626179540
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: cucumber
38
- requirement: &2166404860 !ruby/object:Gem::Requirement
38
+ requirement: &70223626173660 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.10.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2166404860
46
+ version_requirements: *70223626173660
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: cucumber-rails
49
- requirement: &2166404060 !ruby/object:Gem::Requirement
49
+ requirement: &70223626173180 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.5.2
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2166404060
57
+ version_requirements: *70223626173180
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: database_cleaner
60
- requirement: &2166403120 !ruby/object:Gem::Requirement
60
+ requirement: &70223626172700 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2166403120
68
+ version_requirements: *70223626172700
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: jeweler
71
- requirement: &2166402100 !ruby/object:Gem::Requirement
71
+ requirement: &70223626172220 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.5.2
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2166402100
79
+ version_requirements: *70223626172220
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: fog
82
- requirement: &2166401160 !ruby/object:Gem::Requirement
82
+ requirement: &70223626171740 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2166401160
90
+ version_requirements: *70223626171740
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: mongo
93
- requirement: &2166400320 !ruby/object:Gem::Requirement
93
+ requirement: &70223626170440 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2166400320
101
+ version_requirements: *70223626170440
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: couchrest
104
- requirement: &2166399340 !ruby/object:Gem::Requirement
104
+ requirement: &70223626169900 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '1.0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *2166399340
112
+ version_requirements: *70223626169900
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: rack-cache
115
- requirement: &2166398460 !ruby/object:Gem::Requirement
115
+ requirement: &70223626169420 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *2166398460
123
+ version_requirements: *70223626169420
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: rails
126
- requirement: &2166397520 !ruby/object:Gem::Requirement
126
+ requirement: &70223626168940 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ~>
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: 3.1.0
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *2166397520
134
+ version_requirements: *70223626168940
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: rspec
137
- requirement: &2166396660 !ruby/object:Gem::Requirement
137
+ requirement: &70223626168460 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ~>
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '2.5'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *2166396660
145
+ version_requirements: *70223626168460
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: webmock
148
- requirement: &2166395620 !ruby/object:Gem::Requirement
148
+ requirement: &70223626167980 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,10 +153,10 @@ dependencies:
153
153
  version: '0'
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *2166395620
156
+ version_requirements: *70223626167980
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: yard
159
- requirement: &2166394640 !ruby/object:Gem::Requirement
159
+ requirement: &70223626167500 !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
162
162
  - - ! '>='
@@ -164,10 +164,10 @@ dependencies:
164
164
  version: '0'
165
165
  type: :development
166
166
  prerelease: false
167
- version_requirements: *2166394640
167
+ version_requirements: *70223626167500
168
168
  - !ruby/object:Gem::Dependency
169
169
  name: bluecloth
170
- requirement: &2166393680 !ruby/object:Gem::Requirement
170
+ requirement: &70223626167020 !ruby/object:Gem::Requirement
171
171
  none: false
172
172
  requirements:
173
173
  - - ! '>='
@@ -175,10 +175,10 @@ dependencies:
175
175
  version: '0'
176
176
  type: :development
177
177
  prerelease: false
178
- version_requirements: *2166393680
178
+ version_requirements: *70223626167020
179
179
  - !ruby/object:Gem::Dependency
180
180
  name: bson_ext
181
- requirement: &2166392920 !ruby/object:Gem::Requirement
181
+ requirement: &70223626166540 !ruby/object:Gem::Requirement
182
182
  none: false
183
183
  requirements:
184
184
  - - ~>
@@ -186,10 +186,10 @@ dependencies:
186
186
  version: 1.3.1
187
187
  type: :development
188
188
  prerelease: false
189
- version_requirements: *2166392920
189
+ version_requirements: *70223626166540
190
190
  - !ruby/object:Gem::Dependency
191
191
  name: sqlite3-ruby
192
- requirement: &2166392240 !ruby/object:Gem::Requirement
192
+ requirement: &70223626166060 !ruby/object:Gem::Requirement
193
193
  none: false
194
194
  requirements:
195
195
  - - ! '>='
@@ -197,7 +197,7 @@ dependencies:
197
197
  version: '0'
198
198
  type: :development
199
199
  prerelease: false
200
- version_requirements: *2166392240
200
+ version_requirements: *70223626166060
201
201
  description: ! "Dragonfly is a framework that enables on-the-fly processing for any
202
202
  content type.\n It is especially suited to image handling. Its uses range from
203
203
  image thumbnails to standard attachments to on-demand text generation."
@@ -394,7 +394,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
394
394
  version: '0'
395
395
  segments:
396
396
  - 0
397
- hash: 3133110676781217122
397
+ hash: 2886754180935822941
398
398
  required_rubygems_version: !ruby/object:Gem::Requirement
399
399
  none: false
400
400
  requirements: