dragonfly 0.8.1 → 0.8.2

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/Gemfile CHANGED
@@ -3,7 +3,6 @@ source :rubygems
3
3
  # These gems are needed for development and testing
4
4
  group :development, :test, :cucumber do
5
5
  gem 'aws-s3'
6
- gem 'bson_ext'
7
6
  gem 'capybara'
8
7
  gem 'cucumber', '0.8.5'
9
8
  gem 'cucumber-rails'
@@ -16,8 +15,15 @@ group :development, :test, :cucumber do
16
15
  gem 'rack-cache'
17
16
  gem 'rails', '3.0.3', :require => nil
18
17
  gem 'rake'
19
- gem 'rmagick', '2.12.2', :require => nil
20
18
  gem 'rspec', '~> 1.3'
21
- gem 'sqlite3-ruby', '1.3.0' # 1.3.1 segfaults on Ruby 1.9.2
22
19
  gem 'yard'
20
+ if RUBY_PLATFORM == "java"
21
+ gem "jdbc-sqlite3"
22
+ gem "activerecord-jdbcsqlite3-adapter"
23
+ gem "jruby-openssl"
24
+ else
25
+ gem 'bson_ext'
26
+ gem 'rmagick', '2.12.2', :require => nil
27
+ gem 'sqlite3-ruby', '1.3.0' # 1.3.1 segfaults on Ruby 1.9.2
28
+ end
23
29
  end
data/Gemfile.rails.2.3.5 CHANGED
@@ -10,5 +10,11 @@ group :development, :test, :cucumber do
10
10
  gem 'rack-cache', :require => nil
11
11
  gem 'rails', '2.3.5', :require => nil
12
12
  gem 'rspec', '~> 1.3'
13
- gem 'sqlite3-ruby', '1.3.0'
13
+ if RUBY_PLATFORM == "java"
14
+ gem "jdbc-sqlite3"
15
+ gem "activerecord-jdbcsqlite3-adapter"
16
+ gem "jruby-openssl"
17
+ else
18
+ gem 'sqlite3-ruby', '1.3.0' # 1.3.1 segfaults on Ruby 1.9.2
19
+ end
14
20
  end
data/History.md CHANGED
@@ -1,3 +1,12 @@
1
+ 0.8.2 (2010-01-11)
2
+ ==================
3
+ Fixes
4
+ -----
5
+ - Renamed ActiveModel methods like 'attachments' to avoid name clashes
6
+ - Respond properly to HEAD, POST, PUT and DELETE requests
7
+ - Got it working with jRuby and Rubinius
8
+ - Made DOS protection SHA (and ETag) consistent
9
+
1
10
  0.8.1 (2010-11-22)
2
11
  ==================
3
12
  Fixes
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.1
1
+ 0.8.2
data/config.ru CHANGED
@@ -1,9 +1,10 @@
1
- require 'rubygems'
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+ $:.unshift(File.expand_path('../lib', __FILE__))
4
+ require 'dragonfly'
2
5
  require 'rack/cache'
3
- require File.dirname(__FILE__) + '/lib/dragonfly'
4
6
 
5
- APP = Dragonfly[:images].configure_with(:imagemagick) do |c|
6
- end
7
+ APP = Dragonfly[:images].configure_with(:imagemagick)
7
8
 
8
9
  use Rack::Cache,
9
10
  :verbose => true,
data/dragonfly.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dragonfly}
8
- s.version = "0.8.1"
8
+ s.version = "0.8.2"
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 = %q{2010-11-22}
12
+ s.date = %q{2011-01-11}
13
13
  s.email = %q{mark@new-bamboo.co.uk}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -81,6 +81,8 @@ Gem::Specification.new do |s|
81
81
  "lib/dragonfly/config/r_magick.rb",
82
82
  "lib/dragonfly/config/rails.rb",
83
83
  "lib/dragonfly/configurable.rb",
84
+ "lib/dragonfly/core_ext/array.rb",
85
+ "lib/dragonfly/core_ext/hash.rb",
84
86
  "lib/dragonfly/core_ext/object.rb",
85
87
  "lib/dragonfly/core_ext/string.rb",
86
88
  "lib/dragonfly/core_ext/symbol.rb",
@@ -132,13 +134,14 @@ Gem::Specification.new do |s|
132
134
  "spec/dragonfly/app_spec.rb",
133
135
  "spec/dragonfly/config/r_magick_spec.rb",
134
136
  "spec/dragonfly/configurable_spec.rb",
137
+ "spec/dragonfly/core_ext/array_spec.rb",
138
+ "spec/dragonfly/core_ext/hash_spec.rb",
135
139
  "spec/dragonfly/core_ext/string_spec.rb",
136
140
  "spec/dragonfly/core_ext/symbol_spec.rb",
137
141
  "spec/dragonfly/data_storage/data_store_spec.rb",
138
142
  "spec/dragonfly/data_storage/file_data_store_spec.rb",
139
143
  "spec/dragonfly/data_storage/mongo_data_store_spec.rb",
140
144
  "spec/dragonfly/data_storage/s3_data_store_spec.rb",
141
- "spec/dragonfly/deprecation_spec.rb",
142
145
  "spec/dragonfly/encoding/image_magick_encoder_spec.rb",
143
146
  "spec/dragonfly/encoding/r_magick_encoder_spec.rb",
144
147
  "spec/dragonfly/function_manager_spec.rb",
@@ -189,13 +192,14 @@ Gem::Specification.new do |s|
189
192
  "spec/dragonfly/app_spec.rb",
190
193
  "spec/dragonfly/config/r_magick_spec.rb",
191
194
  "spec/dragonfly/configurable_spec.rb",
195
+ "spec/dragonfly/core_ext/array_spec.rb",
196
+ "spec/dragonfly/core_ext/hash_spec.rb",
192
197
  "spec/dragonfly/core_ext/string_spec.rb",
193
198
  "spec/dragonfly/core_ext/symbol_spec.rb",
194
199
  "spec/dragonfly/data_storage/data_store_spec.rb",
195
200
  "spec/dragonfly/data_storage/file_data_store_spec.rb",
196
201
  "spec/dragonfly/data_storage/mongo_data_store_spec.rb",
197
202
  "spec/dragonfly/data_storage/s3_data_store_spec.rb",
198
- "spec/dragonfly/deprecation_spec.rb",
199
203
  "spec/dragonfly/encoding/image_magick_encoder_spec.rb",
200
204
  "spec/dragonfly/encoding/r_magick_encoder_spec.rb",
201
205
  "spec/dragonfly/function_manager_spec.rb",
@@ -229,7 +233,6 @@ Gem::Specification.new do |s|
229
233
 
230
234
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
231
235
  s.add_development_dependency(%q<aws-s3>, [">= 0"])
232
- s.add_development_dependency(%q<bson_ext>, [">= 0"])
233
236
  s.add_development_dependency(%q<capybara>, [">= 0"])
234
237
  s.add_development_dependency(%q<cucumber>, ["= 0.8.5"])
235
238
  s.add_development_dependency(%q<cucumber-rails>, [">= 0"])
@@ -242,14 +245,14 @@ Gem::Specification.new do |s|
242
245
  s.add_development_dependency(%q<rack-cache>, [">= 0"])
243
246
  s.add_development_dependency(%q<rails>, ["= 3.0.3"])
244
247
  s.add_development_dependency(%q<rake>, [">= 0"])
245
- s.add_development_dependency(%q<rmagick>, ["= 2.12.2"])
246
248
  s.add_development_dependency(%q<rspec>, ["~> 1.3"])
247
- s.add_development_dependency(%q<sqlite3-ruby>, ["= 1.3.0"])
248
249
  s.add_development_dependency(%q<yard>, [">= 0"])
250
+ s.add_development_dependency(%q<bson_ext>, [">= 0"])
251
+ s.add_development_dependency(%q<rmagick>, ["= 2.12.2"])
252
+ s.add_development_dependency(%q<sqlite3-ruby>, ["= 1.3.0"])
249
253
  s.add_runtime_dependency(%q<rack>, [">= 0"])
250
254
  else
251
255
  s.add_dependency(%q<aws-s3>, [">= 0"])
252
- s.add_dependency(%q<bson_ext>, [">= 0"])
253
256
  s.add_dependency(%q<capybara>, [">= 0"])
254
257
  s.add_dependency(%q<cucumber>, ["= 0.8.5"])
255
258
  s.add_dependency(%q<cucumber-rails>, [">= 0"])
@@ -262,15 +265,15 @@ Gem::Specification.new do |s|
262
265
  s.add_dependency(%q<rack-cache>, [">= 0"])
263
266
  s.add_dependency(%q<rails>, ["= 3.0.3"])
264
267
  s.add_dependency(%q<rake>, [">= 0"])
265
- s.add_dependency(%q<rmagick>, ["= 2.12.2"])
266
268
  s.add_dependency(%q<rspec>, ["~> 1.3"])
267
- s.add_dependency(%q<sqlite3-ruby>, ["= 1.3.0"])
268
269
  s.add_dependency(%q<yard>, [">= 0"])
270
+ s.add_dependency(%q<bson_ext>, [">= 0"])
271
+ s.add_dependency(%q<rmagick>, ["= 2.12.2"])
272
+ s.add_dependency(%q<sqlite3-ruby>, ["= 1.3.0"])
269
273
  s.add_dependency(%q<rack>, [">= 0"])
270
274
  end
271
275
  else
272
276
  s.add_dependency(%q<aws-s3>, [">= 0"])
273
- s.add_dependency(%q<bson_ext>, [">= 0"])
274
277
  s.add_dependency(%q<capybara>, [">= 0"])
275
278
  s.add_dependency(%q<cucumber>, ["= 0.8.5"])
276
279
  s.add_dependency(%q<cucumber-rails>, [">= 0"])
@@ -283,10 +286,11 @@ Gem::Specification.new do |s|
283
286
  s.add_dependency(%q<rack-cache>, [">= 0"])
284
287
  s.add_dependency(%q<rails>, ["= 3.0.3"])
285
288
  s.add_dependency(%q<rake>, [">= 0"])
286
- s.add_dependency(%q<rmagick>, ["= 2.12.2"])
287
289
  s.add_dependency(%q<rspec>, ["~> 1.3"])
288
- s.add_dependency(%q<sqlite3-ruby>, ["= 1.3.0"])
289
290
  s.add_dependency(%q<yard>, [">= 0"])
291
+ s.add_dependency(%q<bson_ext>, [">= 0"])
292
+ s.add_dependency(%q<rmagick>, ["= 2.12.2"])
293
+ s.add_dependency(%q<sqlite3-ruby>, ["= 1.3.0"])
290
294
  s.add_dependency(%q<rack>, [">= 0"])
291
295
  end
292
296
  end
data/extra_docs/Index.md CHANGED
@@ -6,9 +6,6 @@ I actually lied about image handling - it can be used for any type of content.
6
6
 
7
7
  See the links on the right for more info.
8
8
 
9
- **NOTE: the API has changed since v0.6.2!
10
- [Docs for v0.6.2 are here](v0.6.2/index.html) for a very limited time.**
11
-
12
9
  Installation
13
10
  ------------
14
11
 
data/irbrc.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "rubygems"
2
2
  require "bundler/setup"
3
- require File.dirname(__FILE__) + '/lib/dragonfly'
3
+ $:.unshift(File.expand_path('../lib', __FILE__))
4
+ require 'dragonfly'
4
5
  APP = Dragonfly[:images].configure_with(:imagemagick)
5
6
 
6
7
  # available_uids = `find #{APP.datastore.root_path} ! -type d`.split("\n").map do |file|
data/lib/dragonfly.rb CHANGED
@@ -30,9 +30,11 @@ end
30
30
 
31
31
  autoload_files_in_dir("#{File.dirname(__FILE__)}/dragonfly", 'Dragonfly')
32
32
 
33
- require File.dirname(__FILE__) + '/dragonfly/core_ext/object'
34
- require File.dirname(__FILE__) + '/dragonfly/core_ext/string'
35
- require File.dirname(__FILE__) + '/dragonfly/core_ext/symbol'
33
+ require 'dragonfly/core_ext/object'
34
+ require 'dragonfly/core_ext/string'
35
+ require 'dragonfly/core_ext/symbol'
36
+ require 'dragonfly/core_ext/array'
37
+ require 'dragonfly/core_ext/hash'
36
38
 
37
39
  module Dragonfly
38
40
  class << self
@@ -11,20 +11,20 @@ module Dragonfly
11
11
  define_method macro_name do |attribute|
12
12
 
13
13
  # Prior to activerecord 3, adding before callbacks more than once does add it more than once
14
- before_save :save_attachments unless respond_to?(:before_save_callback_chain) && before_save_callback_chain.find(:save_attachments)
15
- before_destroy :destroy_attachments unless respond_to?(:before_destroy_callback_chain) && before_destroy_callback_chain.find(:destroy_attachments)
14
+ before_save :save_dragonfly_attachments unless respond_to?(:before_save_callback_chain) && before_save_callback_chain.find(:save_dragonfly_attachments)
15
+ before_destroy :destroy_dragonfly_attachments unless respond_to?(:before_destroy_callback_chain) && before_destroy_callback_chain.find(:destroy_dragonfly_attachments)
16
16
 
17
17
  # Register the new attribute
18
18
  dragonfly_apps_for_attributes[attribute] = app
19
19
 
20
20
  # Define the setter for the attribute
21
21
  define_method "#{attribute}=" do |value|
22
- attachments[attribute].assign(value)
22
+ dragonfly_attachments[attribute].assign(value)
23
23
  end
24
24
 
25
25
  # Define the getter for the attribute
26
26
  define_method attribute do
27
- attachments[attribute].to_value
27
+ dragonfly_attachments[attribute].to_value
28
28
  end
29
29
 
30
30
  end
@@ -2,8 +2,8 @@ module Dragonfly
2
2
  module ActiveModelExtensions
3
3
  module InstanceMethods
4
4
 
5
- def attachments
6
- @attachments ||= self.class.dragonfly_apps_for_attributes.inject({}) do |hash, (attribute, app)|
5
+ def dragonfly_attachments
6
+ @dragonfly_attachments ||= self.class.dragonfly_apps_for_attributes.inject({}) do |hash, (attribute, app)|
7
7
  hash[attribute] = Attachment.new(app, self, attribute)
8
8
  hash
9
9
  end
@@ -11,14 +11,14 @@ module Dragonfly
11
11
 
12
12
  private
13
13
 
14
- def save_attachments
15
- attachments.each do |attribute, attachment|
14
+ def save_dragonfly_attachments
15
+ dragonfly_attachments.each do |attribute, attachment|
16
16
  attachment.save!
17
17
  end
18
18
  end
19
19
 
20
- def destroy_attachments
21
- attachments.each do |attribute, attachment|
20
+ def destroy_dragonfly_attachments
21
+ dragonfly_attachments.each do |attribute, attachment|
22
22
  attachment.destroy!
23
23
  end
24
24
  end
data/lib/dragonfly/app.rb CHANGED
@@ -127,31 +127,17 @@ module Dragonfly
127
127
  url_path_prefix.blank? ? '/' : url_path_prefix
128
128
  end
129
129
 
130
- def url_for(job, *args)
131
- if (args.length == 1 && args.first.kind_of?(Hash)) || args.empty?
132
- opts = args.first ? args.first.dup : {}
133
- host = opts.delete(:host) || url_host
134
- suffix = opts.delete(:suffix) || url_suffix
135
- suffix = suffix.call(job) if suffix.respond_to?(:call)
136
- path_prefix = opts.delete(:path_prefix) || url_path_prefix
137
- path = "#{host}#{path_prefix}#{job.to_path}#{suffix}"
138
- query = opts
139
- query.merge!(server.required_params_for(job)) if protect_from_dos_attacks
140
- path << "?#{Rack::Utils.build_query(query)}" if query.any?
141
- path
142
- else
143
- # Deprecation stuff - will be removed!!!
144
- case args[0]
145
- when /^(\d+)?x(\d+)?/
146
- log.warn("DEPRECATED USE OF url_for and will be removed in the future - please use thumb(#{args.map{|a|a.inspect}.join(', ')}).url")
147
- args[1] ? job.thumb(args[0], args[1]).url : job.thumb(args[0]).url
148
- when :gif, :png, :jpg, :jpeg
149
- log.warn("DEPRECATED USE OF url_for and will be removed in the future - please use encode(#{args.first.inspect}).url")
150
- job.encode(args[0]).url
151
- else
152
- raise "DEPRECATED USE OF url_for - will be removed in future versions - please consult the docs"
153
- end
154
- end
130
+ def url_for(job, opts={})
131
+ opts = opts.dup
132
+ host = opts.delete(:host) || url_host
133
+ suffix = opts.delete(:suffix) || url_suffix
134
+ suffix = suffix.call(job) if suffix.respond_to?(:call)
135
+ path_prefix = opts.delete(:path_prefix) || url_path_prefix
136
+ path = "#{host}#{path_prefix}#{job.to_path}#{suffix}"
137
+ query = opts
138
+ query.merge!(server.required_params_for(job)) if protect_from_dos_attacks
139
+ path << "?#{Rack::Utils.build_query(query)}" if query.any?
140
+ path
155
141
  end
156
142
 
157
143
  def define_macro(mod, macro_name)
@@ -25,7 +25,15 @@ module Dragonfly
25
25
  end
26
26
  end
27
27
 
28
- class DeferredBlock < Proc; end
28
+ class DeferredBlock # Inheriting from Proc causes errors in some versions of Ruby
29
+ def initialize(blk)
30
+ @blk = blk
31
+ end
32
+
33
+ def call
34
+ @blk.call
35
+ end
36
+ end
29
37
 
30
38
  module InstanceMethods
31
39
 
@@ -64,7 +72,7 @@ module Dragonfly
64
72
  private
65
73
 
66
74
  def configurable_attr attribute, default=nil, &blk
67
- default_configuration[attribute] = blk ? DeferredBlock.new(&blk) : default
75
+ default_configuration[attribute] = blk ? DeferredBlock.new(blk) : default
68
76
 
69
77
  # Define the reader
70
78
  define_method(attribute) do
@@ -0,0 +1,7 @@
1
+ class Array
2
+
3
+ def to_dragonfly_unique_s
4
+ map{|item| item.to_dragonfly_unique_s }.join
5
+ end
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ class Hash
2
+
3
+ def to_dragonfly_unique_s
4
+ sort_by{|k, v| k.to_dragonfly_unique_s }.to_dragonfly_unique_s
5
+ end
6
+
7
+ end
@@ -4,5 +4,9 @@ class Object
4
4
  def blank?
5
5
  respond_to?(:empty?) ? empty? : !self
6
6
  end
7
+
8
+ def to_dragonfly_unique_s
9
+ to_s
10
+ end
7
11
 
8
12
  end
@@ -57,7 +57,7 @@ module Dragonfly
57
57
  dirname = File.dirname(path)
58
58
  basename = File.basename(path, '.*')
59
59
  extname = File.extname(path)
60
- "#{dirname}/#{basename}_#{Time.now.usec.to_s(32)}#{extname}"
60
+ "#{dirname}/#{basename}_#{(Time.now.usec*10 + rand(100)).to_s(32)}#{extname}"
61
61
  end
62
62
 
63
63
  private
data/lib/dragonfly/job.rb CHANGED
@@ -243,16 +243,20 @@ module Dragonfly
243
243
 
244
244
  # Serializing, etc.
245
245
 
246
+ def to_unique_s
247
+ to_a.to_dragonfly_unique_s
248
+ end
249
+
246
250
  def serialize
247
251
  Serializer.marshal_encode(to_a)
248
252
  end
249
253
 
250
254
  def unique_signature
251
- Digest::SHA1.hexdigest(serialize)
255
+ Digest::SHA1.hexdigest(to_unique_s)
252
256
  end
253
257
 
254
258
  def sha
255
- Digest::SHA1.hexdigest("#{serialize}#{app.secret}")[0...8]
259
+ Digest::SHA1.hexdigest("#{to_unique_s}#{app.secret}")[0...8]
256
260
  end
257
261
 
258
262
  def validate_sha!(sha)
@@ -268,8 +272,8 @@ module Dragonfly
268
272
 
269
273
  # URLs, etc.
270
274
 
271
- def url(*args)
272
- app.url_for(self, *args) unless steps.empty?
275
+ def url(opts={})
276
+ app.url_for(self, opts) unless steps.empty?
273
277
  end
274
278
 
275
279
  def b64_data
@@ -16,11 +16,13 @@ module Dragonfly
16
16
  end
17
17
 
18
18
  def to_response
19
- if etag_matches?
20
- # Not Modified
19
+ if !(request.head? || request.get?)
20
+ [405, method_not_allowed_headers, ["#{request.request_method} method not allowed"]]
21
+ elsif etag_matches?
21
22
  [304, cache_headers, []]
22
- else
23
- # Success
23
+ elsif request.head?
24
+ [200, success_headers.merge(cache_headers), []]
25
+ elsif request.get?
24
26
  [200, success_headers.merge(cache_headers), job.result]
25
27
  end
26
28
  rescue DataStorage::DataNotFound => e
@@ -65,6 +67,13 @@ module Dragonfly
65
67
  parts << %(filename="#{URI.encode(filename)}") if filename
66
68
  parts.any? ? {"Content-Disposition" => parts.join('; ')} : {}
67
69
  end
70
+
71
+ def method_not_allowed_headers
72
+ {
73
+ 'Content-Type' => 'text/plain',
74
+ 'Allow' => 'GET, HEAD'
75
+ }
76
+ end
68
77
 
69
78
  def content_disposition
70
79
  @content_disposition ||= evaluate(app.content_disposition)