dragonfly 0.8.6 → 0.9.0
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/{.specopts → .rspec} +0 -1
- data/.yardopts +6 -2
- data/Gemfile +14 -13
- data/History.md +47 -9
- data/README.md +25 -5
- data/Rakefile +37 -79
- data/VERSION +1 -1
- data/dragonfly.gemspec +140 -89
- data/extra_docs/Analysers.md +8 -48
- data/extra_docs/Configuration.md +40 -25
- data/extra_docs/Couch.md +49 -0
- data/extra_docs/DataStorage.md +94 -24
- data/extra_docs/Encoding.md +6 -35
- data/extra_docs/ExampleUseCases.md +113 -0
- data/extra_docs/GeneralUsage.md +7 -23
- data/extra_docs/Generators.md +15 -49
- data/extra_docs/Heroku.md +7 -8
- data/extra_docs/ImageMagick.md +126 -0
- data/extra_docs/MimeTypes.md +3 -3
- data/extra_docs/Models.md +163 -0
- data/extra_docs/Mongo.md +1 -4
- data/extra_docs/Processing.md +7 -60
- data/extra_docs/Rails2.md +3 -1
- data/extra_docs/Rails3.md +2 -10
- data/extra_docs/ServingRemotely.md +83 -0
- data/extra_docs/Sinatra.md +3 -3
- data/extra_docs/URLs.md +60 -33
- data/features/rails_3.0.5.feature +8 -0
- data/features/steps/rails_steps.rb +7 -18
- data/features/support/env.rb +10 -37
- data/features/support/setup.rb +32 -0
- data/fixtures/rails_3.0.5/files/app/models/album.rb +5 -0
- data/fixtures/rails_3.0.5/files/app/views/albums/new.html.erb +7 -0
- data/fixtures/{files → rails_3.0.5/files}/app/views/albums/show.html.erb +2 -0
- data/fixtures/{files → rails_3.0.5/files}/config/initializers/dragonfly.rb +0 -0
- data/fixtures/rails_3.0.5/files/features/manage_album_images.feature +38 -0
- data/fixtures/rails_3.0.5/files/features/step_definitions/helper_steps.rb +7 -0
- data/fixtures/{files → rails_3.0.5/files}/features/step_definitions/image_steps.rb +11 -1
- data/fixtures/{files → rails_3.0.5/files}/features/support/paths.rb +2 -0
- data/fixtures/{files → rails_3.0.5/files}/features/text_images.feature +0 -0
- data/fixtures/{rails_3.0.3 → rails_3.0.5}/template.rb +2 -2
- data/irbrc.rb +2 -1
- data/lib/dragonfly.rb +7 -0
- data/lib/dragonfly/active_model_extensions/attachment.rb +134 -46
- data/lib/dragonfly/active_model_extensions/attachment_class_methods.rb +144 -0
- data/lib/dragonfly/active_model_extensions/class_methods.rb +62 -9
- data/lib/dragonfly/active_model_extensions/instance_methods.rb +2 -2
- data/lib/dragonfly/active_model_extensions/validations.rb +10 -6
- data/lib/dragonfly/analyser.rb +0 -1
- data/lib/dragonfly/analysis/file_command_analyser.rb +1 -1
- data/lib/dragonfly/analysis/image_magick_analyser.rb +2 -43
- data/lib/dragonfly/app.rb +64 -55
- data/lib/dragonfly/config/heroku.rb +1 -1
- data/lib/dragonfly/config/image_magick.rb +2 -37
- data/lib/dragonfly/config/rails.rb +5 -2
- data/lib/dragonfly/configurable.rb +115 -35
- data/lib/dragonfly/core_ext/object.rb +1 -1
- data/lib/dragonfly/core_ext/string.rb +1 -1
- data/lib/dragonfly/data_storage/couch_data_store.rb +84 -0
- data/lib/dragonfly/data_storage/file_data_store.rb +43 -18
- data/lib/dragonfly/data_storage/mongo_data_store.rb +8 -4
- data/lib/dragonfly/data_storage/s3data_store.rb +82 -38
- data/lib/dragonfly/encoding/image_magick_encoder.rb +2 -53
- data/lib/dragonfly/function_manager.rb +4 -2
- data/lib/dragonfly/generation/image_magick_generator.rb +2 -136
- data/lib/dragonfly/hash_with_css_style_keys.rb +21 -0
- data/lib/dragonfly/image_magick/analyser.rb +51 -0
- data/lib/dragonfly/image_magick/config.rb +44 -0
- data/lib/dragonfly/{encoding/r_magick_encoder.rb → image_magick/encoder.rb} +10 -14
- data/lib/dragonfly/image_magick/generator.rb +145 -0
- data/lib/dragonfly/image_magick/processor.rb +104 -0
- data/lib/dragonfly/image_magick/utils.rb +72 -0
- data/lib/dragonfly/image_magick_utils.rb +2 -79
- data/lib/dragonfly/job.rb +152 -90
- data/lib/dragonfly/middleware.rb +5 -19
- data/lib/dragonfly/processing/image_magick_processor.rb +2 -95
- data/lib/dragonfly/rails/images.rb +15 -10
- data/lib/dragonfly/response.rb +26 -12
- data/lib/dragonfly/serializer.rb +1 -4
- data/lib/dragonfly/server.rb +103 -0
- data/lib/dragonfly/temp_object.rb +56 -101
- data/lib/dragonfly/url_mapper.rb +78 -0
- data/spec/dragonfly/active_model_extensions/model_spec.rb +772 -65
- data/spec/dragonfly/active_model_extensions/spec_helper.rb +90 -10
- data/spec/dragonfly/analyser_spec.rb +1 -1
- data/spec/dragonfly/analysis/file_command_analyser_spec.rb +5 -14
- data/spec/dragonfly/app_spec.rb +35 -180
- data/spec/dragonfly/configurable_spec.rb +259 -18
- data/spec/dragonfly/core_ext/string_spec.rb +2 -2
- data/spec/dragonfly/core_ext/symbol_spec.rb +1 -1
- data/spec/dragonfly/data_storage/couch_data_store_spec.rb +84 -0
- data/spec/dragonfly/data_storage/file_data_store_spec.rb +149 -22
- data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +21 -2
- data/spec/dragonfly/data_storage/s3_data_store_spec.rb +207 -43
- data/spec/dragonfly/data_storage/{data_store_spec.rb → shared_data_store_examples.rb} +16 -15
- data/spec/dragonfly/function_manager_spec.rb +2 -2
- data/spec/dragonfly/{generation/hash_with_css_style_keys_spec.rb → hash_with_css_style_keys_spec.rb} +2 -2
- data/spec/dragonfly/{analysis/shared_analyser_spec.rb → image_magick/analyser_spec.rb} +19 -6
- data/spec/dragonfly/{encoding/image_magick_encoder_spec.rb → image_magick/encoder_spec.rb} +2 -2
- data/spec/dragonfly/image_magick/generator_spec.rb +172 -0
- data/spec/dragonfly/{processing/shared_processing_spec.rb → image_magick/processor_spec.rb} +55 -6
- data/spec/dragonfly/image_magick/utils_spec.rb +18 -0
- data/spec/dragonfly/job_builder_spec.rb +1 -1
- data/spec/dragonfly/job_definitions_spec.rb +1 -1
- data/spec/dragonfly/job_endpoint_spec.rb +26 -3
- data/spec/dragonfly/job_spec.rb +426 -208
- data/spec/dragonfly/loggable_spec.rb +2 -2
- data/spec/dragonfly/middleware_spec.rb +5 -26
- data/spec/dragonfly/routed_endpoint_spec.rb +1 -1
- data/spec/dragonfly/serializer_spec.rb +1 -14
- data/spec/dragonfly/server_spec.rb +261 -0
- data/spec/dragonfly/simple_cache_spec.rb +1 -1
- data/spec/dragonfly/temp_object_spec.rb +84 -130
- data/spec/dragonfly/url_mapper_spec.rb +130 -0
- data/spec/functional/deprecations_spec.rb +51 -0
- data/spec/functional/image_magick_app_spec.rb +27 -0
- data/spec/functional/model_urls_spec.rb +85 -0
- data/spec/functional/remote_on_the_fly_spec.rb +51 -0
- data/spec/functional/to_response_spec.rb +31 -0
- data/spec/spec_helper.rb +12 -22
- data/spec/{argument_matchers.rb → support/argument_matchers.rb} +0 -0
- data/spec/{image_matchers.rb → support/image_matchers.rb} +4 -4
- data/spec/support/simple_matchers.rb +53 -0
- data/yard/handlers/configurable_attr_handler.rb +2 -2
- data/yard/templates/default/fulldoc/html/css/common.css +12 -10
- data/yard/templates/default/layout/html/layout.erb +6 -0
- metadata +267 -308
- data/Gemfile.rails.2.3.5 +0 -20
- data/features/3.0.3.feature +0 -8
- data/features/rails_2.3.5.feature +0 -7
- data/fixtures/files/app/models/album.rb +0 -3
- data/fixtures/files/app/views/albums/new.html.erb +0 -4
- data/fixtures/files/features/manage_album_images.feature +0 -12
- data/fixtures/rails_2.3.5/template.rb +0 -10
- data/lib/dragonfly/analysis/r_magick_analyser.rb +0 -63
- data/lib/dragonfly/config/r_magick.rb +0 -46
- data/lib/dragonfly/generation/hash_with_css_style_keys.rb +0 -23
- data/lib/dragonfly/generation/r_magick_generator.rb +0 -155
- data/lib/dragonfly/processing/r_magick_processor.rb +0 -126
- data/lib/dragonfly/r_magick_utils.rb +0 -48
- data/lib/dragonfly/simple_endpoint.rb +0 -76
- data/spec/dragonfly/active_model_extensions/active_model_setup.rb +0 -97
- data/spec/dragonfly/active_model_extensions/active_record_setup.rb +0 -85
- data/spec/dragonfly/analysis/image_magick_analyser_spec.rb +0 -15
- data/spec/dragonfly/analysis/r_magick_analyser_spec.rb +0 -31
- data/spec/dragonfly/config/r_magick_spec.rb +0 -29
- data/spec/dragonfly/encoding/r_magick_encoder_spec.rb +0 -41
- data/spec/dragonfly/generation/image_magick_generator_spec.rb +0 -12
- data/spec/dragonfly/generation/r_magick_generator_spec.rb +0 -28
- data/spec/dragonfly/generation/shared_generator_spec.rb +0 -91
- data/spec/dragonfly/image_magick_utils_spec.rb +0 -16
- data/spec/dragonfly/processing/image_magick_processor_spec.rb +0 -29
- data/spec/dragonfly/processing/r_magick_processor_spec.rb +0 -30
- data/spec/dragonfly/simple_endpoint_spec.rb +0 -97
- data/spec/simple_matchers.rb +0 -44
@@ -0,0 +1,144 @@
|
|
1
|
+
module Dragonfly
|
2
|
+
module ActiveModelExtensions
|
3
|
+
class Attachment
|
4
|
+
class << self
|
5
|
+
|
6
|
+
class ConfigProxy
|
7
|
+
|
8
|
+
def initialize(spec, block)
|
9
|
+
@spec = spec
|
10
|
+
instance_eval(&block)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
attr_reader :spec
|
16
|
+
|
17
|
+
def after_assign(*callbacks, &block)
|
18
|
+
add_callbacks(:after_assign, *callbacks, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def after_unassign(*callbacks, &block)
|
22
|
+
add_callbacks(:after_unassign, *callbacks, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
def copy_to(accessor, &block)
|
26
|
+
after_assign do |a|
|
27
|
+
self.send "#{accessor}=", (block_given? ? instance_exec(a, &block) : a)
|
28
|
+
end
|
29
|
+
after_unassign{|a| self.send("#{accessor}=", nil) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def storage_opts(opts=nil, &block)
|
33
|
+
spec.storage_opts_specs << (opts || block)
|
34
|
+
end
|
35
|
+
|
36
|
+
def storage_opt(key, value, &block)
|
37
|
+
if value.is_a? Symbol
|
38
|
+
storage_opts{|a| {key => send(value)} }
|
39
|
+
elsif block_given?
|
40
|
+
storage_opts{|a| {key => instance_exec(a, &block)} }
|
41
|
+
else
|
42
|
+
storage_opts{|a| {key => value} }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def add_callbacks(name, *callbacks, &block)
|
47
|
+
if block_given?
|
48
|
+
spec.callbacks[name] << block
|
49
|
+
else
|
50
|
+
spec.callbacks[name].push(*callbacks)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def method_missing(meth, *args, &block)
|
55
|
+
if meth.to_s =~ /^storage_(.*)$/
|
56
|
+
storage_opt($1.to_sym, args.first, &block)
|
57
|
+
else
|
58
|
+
super
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
def init(model_class, attribute, app, config_block)
|
65
|
+
@model_class, @attribute, @app, @config_block = model_class, attribute, app, config_block
|
66
|
+
include app.analyser.analysis_methods
|
67
|
+
include app.job_definitions
|
68
|
+
define_method :format do
|
69
|
+
job.format
|
70
|
+
end
|
71
|
+
define_method :mime_type do
|
72
|
+
job.mime_type
|
73
|
+
end
|
74
|
+
ConfigProxy.new(self, config_block) if config_block
|
75
|
+
self
|
76
|
+
end
|
77
|
+
|
78
|
+
attr_reader :model_class, :attribute, :app, :config_block
|
79
|
+
|
80
|
+
# Callbacks
|
81
|
+
def callbacks
|
82
|
+
@callbacks ||= Hash.new{|h,k| h[k] = [] }
|
83
|
+
end
|
84
|
+
|
85
|
+
def run_callbacks(name, model, attachment)
|
86
|
+
attachment.should_run_callbacks = false
|
87
|
+
callbacks[name].each do |callback|
|
88
|
+
case callback
|
89
|
+
when Symbol then model.send(callback)
|
90
|
+
when Proc then model.instance_exec(attachment, &callback)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
attachment.should_run_callbacks = true
|
94
|
+
end
|
95
|
+
|
96
|
+
# Magic attributes
|
97
|
+
def allowed_magic_attributes
|
98
|
+
app.analyser.analysis_method_names + [:size, :basename, :name, :ext, :meta]
|
99
|
+
end
|
100
|
+
|
101
|
+
def magic_attributes
|
102
|
+
@magic_attributes ||= begin
|
103
|
+
prefix = attribute.to_s + '_'
|
104
|
+
model_class.public_instance_methods.inject([]) do |attrs, name|
|
105
|
+
_, __, suffix = name.to_s.partition(prefix)
|
106
|
+
if !suffix.empty? && allowed_magic_attributes.include?(suffix.to_sym)
|
107
|
+
attrs << suffix.to_sym
|
108
|
+
end
|
109
|
+
attrs
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def ensure_uses_cached_magic_attributes
|
115
|
+
return if @uses_cached_magic_attributes
|
116
|
+
magic_attributes.each do |attr|
|
117
|
+
define_method attr do
|
118
|
+
magic_attribute_for(attr)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
@uses_cached_magic_attributes = true
|
122
|
+
end
|
123
|
+
|
124
|
+
# Storage options
|
125
|
+
def storage_opts_specs
|
126
|
+
@storage_opts_specs ||= []
|
127
|
+
end
|
128
|
+
|
129
|
+
def evaluate_storage_opts(model, attachment)
|
130
|
+
storage_opts_specs.inject({}) do |opts, spec|
|
131
|
+
options = case spec
|
132
|
+
when Proc then model.instance_exec(attachment, &spec)
|
133
|
+
when Symbol then model.send(spec)
|
134
|
+
else spec
|
135
|
+
end
|
136
|
+
opts.merge!(options)
|
137
|
+
opts
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -7,15 +7,15 @@ module Dragonfly
|
|
7
7
|
def register_dragonfly_app(macro_name, app)
|
8
8
|
(class << self; self; end).class_eval do
|
9
9
|
|
10
|
-
# Defines e.g. 'image_accessor' for any
|
11
|
-
define_method macro_name do |attribute|
|
10
|
+
# Defines e.g. 'image_accessor' for any activemodel class body
|
11
|
+
define_method macro_name do |attribute, &config_block|
|
12
12
|
|
13
|
-
#
|
14
|
-
before_save :save_dragonfly_attachments
|
15
|
-
before_destroy :destroy_dragonfly_attachments
|
13
|
+
# Add callbacks
|
14
|
+
before_save :save_dragonfly_attachments
|
15
|
+
before_destroy :destroy_dragonfly_attachments
|
16
16
|
|
17
17
|
# Register the new attribute
|
18
|
-
|
18
|
+
dragonfly_attachment_classes << new_dragonfly_attachment_class(attribute, app, config_block)
|
19
19
|
|
20
20
|
# Define the setter for the attribute
|
21
21
|
define_method "#{attribute}=" do |value|
|
@@ -27,19 +27,72 @@ module Dragonfly
|
|
27
27
|
dragonfly_attachments[attribute].to_value
|
28
28
|
end
|
29
29
|
|
30
|
+
# Define the URL setter
|
31
|
+
define_method "#{attribute}_url=" do |url|
|
32
|
+
unless url.blank?
|
33
|
+
dragonfly_attachments[attribute].assign(app.fetch_url(url))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Define the URL getter
|
38
|
+
define_method "#{attribute}_url" do
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
|
42
|
+
# Define the remove setter
|
43
|
+
define_method "remove_#{attribute}=" do |value|
|
44
|
+
unless [0, "0", false, "false", "", nil].include?(value)
|
45
|
+
dragonfly_attachments[attribute].assign(nil)
|
46
|
+
instance_variable_set("@remove_#{attribute}", true)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Define the remove getter
|
51
|
+
attr_reader "remove_#{attribute}"
|
52
|
+
|
53
|
+
# Define the retained setter
|
54
|
+
define_method "retained_#{attribute}=" do |string|
|
55
|
+
unless string.blank?
|
56
|
+
begin
|
57
|
+
dragonfly_attachments[attribute].retained_attrs = Serializer.marshal_decode(string)
|
58
|
+
rescue Serializer::BadString => e
|
59
|
+
app.log.warn("*** WARNING ***: couldn't update attachment with serialized retained_#{attribute} string #{string.inspect}")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
dragonfly_attachments[attribute].should_retain = true
|
63
|
+
dragonfly_attachments[attribute].retain!
|
64
|
+
string
|
65
|
+
end
|
66
|
+
|
67
|
+
# Define the retained getter
|
68
|
+
define_method "retained_#{attribute}" do
|
69
|
+
attrs = dragonfly_attachments[attribute].retained_attrs
|
70
|
+
Serializer.marshal_encode(attrs) if attrs
|
71
|
+
end
|
72
|
+
|
30
73
|
end
|
31
74
|
|
32
75
|
end
|
33
76
|
app
|
34
77
|
end
|
35
78
|
|
36
|
-
def
|
37
|
-
@
|
79
|
+
def dragonfly_attachment_classes
|
80
|
+
@dragonfly_attachment_classes ||= begin
|
38
81
|
parent_class = ancestors.select{|a| a.is_a?(Class) }[1]
|
39
|
-
parent_class.respond_to?(:
|
82
|
+
if parent_class.respond_to?(:dragonfly_attachment_classes)
|
83
|
+
parent_class.dragonfly_attachment_classes.map do |klass|
|
84
|
+
new_dragonfly_attachment_class(klass.attribute, klass.app, klass.config_block)
|
85
|
+
end
|
86
|
+
else
|
87
|
+
[]
|
88
|
+
end
|
40
89
|
end
|
41
90
|
end
|
42
91
|
|
92
|
+
def new_dragonfly_attachment_class(attribute, app, config_block)
|
93
|
+
Class.new(Attachment).init(self, attribute, app, config_block)
|
94
|
+
end
|
95
|
+
|
43
96
|
end
|
44
97
|
end
|
45
98
|
end
|
@@ -3,8 +3,8 @@ module Dragonfly
|
|
3
3
|
module InstanceMethods
|
4
4
|
|
5
5
|
def dragonfly_attachments
|
6
|
-
@dragonfly_attachments ||= self.class.
|
7
|
-
hash[attribute] =
|
6
|
+
@dragonfly_attachments ||= self.class.dragonfly_attachment_classes.inject({}) do |hash, klass|
|
7
|
+
hash[klass.attribute] = klass.new(self)
|
8
8
|
hash
|
9
9
|
end
|
10
10
|
end
|
@@ -12,19 +12,23 @@ module Dragonfly
|
|
12
12
|
allowed_values = opts[:in] || [opts[:as]]
|
13
13
|
|
14
14
|
args = attrs + [opts]
|
15
|
-
validates_each(*args) do |
|
15
|
+
validates_each(*args) do |model, attr, attachment|
|
16
16
|
if attachment
|
17
17
|
property = attachment.send(property_name)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
unless allowed_values.include?(property)
|
19
|
+
message = opts[:message] ||
|
20
|
+
"#{property_name.to_s.humanize.downcase} is incorrect. "+
|
21
|
+
"It needs to be #{Validations.expected_values_string(allowed_values)}"+
|
22
|
+
(property ? ", but was '#{property}'" : "")
|
23
|
+
message = message.call(property, model) if message.respond_to?(:call)
|
24
|
+
model.errors.add(attr, message)
|
25
|
+
end
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
25
29
|
end
|
26
30
|
|
27
|
-
def expected_values_string(allowed_values)
|
31
|
+
def self.expected_values_string(allowed_values)
|
28
32
|
if allowed_values.is_a?(Range)
|
29
33
|
"between #{allowed_values.first} and #{allowed_values.last}"
|
30
34
|
else
|
data/lib/dragonfly/analyser.rb
CHANGED
@@ -1,47 +1,6 @@
|
|
1
1
|
module Dragonfly
|
2
2
|
module Analysis
|
3
|
-
|
4
|
-
|
5
|
-
include ImageMagickUtils
|
6
|
-
include Configurable
|
7
|
-
|
8
|
-
def width(temp_object)
|
9
|
-
identify(temp_object)[:width]
|
10
|
-
end
|
11
|
-
|
12
|
-
def height(temp_object)
|
13
|
-
identify(temp_object)[:height]
|
14
|
-
end
|
15
|
-
|
16
|
-
def aspect_ratio(temp_object)
|
17
|
-
attrs = identify(temp_object)
|
18
|
-
attrs[:width].to_f / attrs[:height]
|
19
|
-
end
|
20
|
-
|
21
|
-
def portrait?(temp_object)
|
22
|
-
attrs = identify(temp_object)
|
23
|
-
attrs[:width] <= attrs[:height]
|
24
|
-
end
|
25
|
-
|
26
|
-
def landscape?(temp_object)
|
27
|
-
attrs = identify(temp_object)
|
28
|
-
attrs[:width] >= attrs[:height]
|
29
|
-
end
|
30
|
-
|
31
|
-
def depth(temp_object)
|
32
|
-
identify(temp_object)[:depth]
|
33
|
-
end
|
34
|
-
|
35
|
-
def number_of_colours(temp_object)
|
36
|
-
details = raw_identify(temp_object, '-verbose -unique')
|
37
|
-
details[/Colors: (\d+)/, 1].to_i
|
38
|
-
end
|
39
|
-
alias number_of_colors number_of_colours
|
40
|
-
|
41
|
-
def format(temp_object)
|
42
|
-
identify(temp_object)[:format]
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
3
|
+
puts "WARNING: Dragonfly::Analysis::ImageMagickAnalyser is DEPRECATED and will soon be removed. Please use Dragonfly::ImageMagick::Analyser instead."
|
4
|
+
ImageMagickAnalyser = ImageMagick::Analyser
|
46
5
|
end
|
47
6
|
end
|
data/lib/dragonfly/app.rb
CHANGED
@@ -25,33 +25,29 @@ module Dragonfly
|
|
25
25
|
|
26
26
|
def initialize
|
27
27
|
@analyser, @processor, @encoder, @generator = Analyser.new, Processor.new, Encoder.new, Generator.new
|
28
|
-
@analyser.
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
[@analyser, @processor, @encoder, @generator].each do |obj|
|
29
|
+
obj.use_same_log_as(self)
|
30
|
+
obj.use_as_fallback_config(self)
|
31
|
+
end
|
32
|
+
@server = Server.new(self)
|
32
33
|
@job_definitions = JobDefinitions.new
|
33
|
-
@server = Dragonfly::SimpleEndpoint.new(self)
|
34
34
|
end
|
35
35
|
|
36
36
|
include Configurable
|
37
37
|
|
38
38
|
extend Forwardable
|
39
39
|
def_delegator :datastore, :destroy
|
40
|
-
def_delegators :new_job, :fetch, :generate, :fetch_file
|
41
|
-
|
40
|
+
def_delegators :new_job, :fetch, :generate, :fetch_file, :fetch_url
|
41
|
+
def_delegators :server, :call
|
42
42
|
|
43
43
|
configurable_attr :datastore do DataStorage::FileDataStore.new end
|
44
44
|
configurable_attr :cache_duration, 3600*24*365 # (1 year)
|
45
45
|
configurable_attr :fallback_mime_type, 'application/octet-stream'
|
46
|
-
configurable_attr :url_path_prefix
|
47
|
-
configurable_attr :url_host
|
48
|
-
configurable_attr :url_suffix
|
49
|
-
configurable_attr :protect_from_dos_attacks, false
|
50
46
|
configurable_attr :secret, 'secret yo'
|
51
47
|
configurable_attr :log do Logger.new('/var/tmp/dragonfly.log') end
|
52
|
-
configurable_attr :
|
48
|
+
configurable_attr :trust_file_extensions, true
|
53
49
|
configurable_attr :content_disposition
|
54
|
-
configurable_attr :content_filename, Response::DEFAULT_FILENAME
|
50
|
+
configurable_attr :content_filename, Dragonfly::Response::DEFAULT_FILENAME
|
55
51
|
|
56
52
|
attr_reader :analyser
|
57
53
|
attr_reader :processor
|
@@ -59,33 +55,14 @@ module Dragonfly
|
|
59
55
|
attr_reader :generator
|
60
56
|
attr_reader :server
|
61
57
|
|
62
|
-
|
63
|
-
configuration_method :processor
|
64
|
-
configuration_method :encoder
|
65
|
-
configuration_method :generator
|
58
|
+
nested_configurable :server, :analyser, :processor, :encoder, :generator
|
66
59
|
|
67
60
|
attr_accessor :job_definitions
|
68
61
|
|
69
|
-
|
70
|
-
|
71
|
-
:image_magick => 'ImageMagick',
|
72
|
-
:rmagick => 'RMagick',
|
73
|
-
:r_magick => 'RMagick',
|
74
|
-
:rails => 'Rails',
|
75
|
-
:heroku => 'Heroku'
|
76
|
-
}
|
77
|
-
|
78
|
-
def configurer_for(symbol)
|
79
|
-
class_name = SAVED_CONFIGS[symbol]
|
80
|
-
if class_name.nil?
|
81
|
-
raise ArgumentError, "#{symbol.inspect} is not a known configuration - try one of #{SAVED_CONFIGS.keys.join(', ')}"
|
82
|
-
end
|
83
|
-
Config.const_get(class_name)
|
84
|
-
end
|
85
|
-
|
86
|
-
def new_job(content=nil, opts={})
|
87
|
-
content ? Job.new(self, TempObject.new(content, opts)) : Job.new(self)
|
62
|
+
def new_job(content=nil, meta={})
|
63
|
+
job_class.new(self, content, meta)
|
88
64
|
end
|
65
|
+
alias create new_job
|
89
66
|
|
90
67
|
def endpoint(job=nil, &block)
|
91
68
|
block ? RoutedEndpoint.new(self, &block) : JobEndpoint.new(job)
|
@@ -96,9 +73,20 @@ module Dragonfly
|
|
96
73
|
end
|
97
74
|
configuration_method :job
|
98
75
|
|
76
|
+
def job_class
|
77
|
+
@job_class ||= begin
|
78
|
+
app = self
|
79
|
+
Class.new(Job).class_eval do
|
80
|
+
include app.analyser.analysis_methods
|
81
|
+
include app.job_definitions
|
82
|
+
include Job::OverrideInstanceMethods
|
83
|
+
self
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
99
88
|
def store(object, opts={})
|
100
89
|
temp_object = object.is_a?(TempObject) ? object : TempObject.new(object)
|
101
|
-
temp_object.extract_attributes_from(opts)
|
102
90
|
datastore.store(temp_object, opts)
|
103
91
|
end
|
104
92
|
|
@@ -115,29 +103,28 @@ module Dragonfly
|
|
115
103
|
registered_mime_types[file_ext_string(format)]
|
116
104
|
end
|
117
105
|
|
118
|
-
def
|
119
|
-
|
120
|
-
(mime_type_for(temp_object.ext) if infer_mime_type_from_file_ext) ||
|
121
|
-
analyser.analyse(temp_object, :mime_type) ||
|
122
|
-
mime_type_for(analyser.analyse(temp_object, :format)) ||
|
123
|
-
fallback_mime_type
|
106
|
+
def response_headers
|
107
|
+
@response_headers ||= {}
|
124
108
|
end
|
109
|
+
configuration_method :response_headers
|
125
110
|
|
126
|
-
def
|
127
|
-
|
111
|
+
def define_url(&block)
|
112
|
+
@url_proc = block
|
128
113
|
end
|
114
|
+
configuration_method :define_url
|
129
115
|
|
130
116
|
def url_for(job, opts={})
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
117
|
+
if @url_proc
|
118
|
+
@url_proc.call(self, job, opts)
|
119
|
+
else
|
120
|
+
server.url_for(job, opts)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def remote_url_for(uid, opts={})
|
125
|
+
datastore.url_for(uid, opts)
|
126
|
+
rescue NoMethodError => e
|
127
|
+
raise NotImplementedError, "The datastore doesn't support serving content directly - #{datastore.inspect}"
|
141
128
|
end
|
142
129
|
|
143
130
|
def define_macro(mod, macro_name)
|
@@ -157,9 +144,31 @@ module Dragonfly
|
|
157
144
|
alias included included_with_dragonfly
|
158
145
|
end
|
159
146
|
end
|
147
|
+
|
148
|
+
# Deprecated methods
|
149
|
+
def url_path_prefix=(thing)
|
150
|
+
raise NoMethodError, "url_path_prefix is deprecated - please use url_format, e.g. url_format = '/media/:job/:basename.:format' - see docs for more details"
|
151
|
+
end
|
152
|
+
configuration_method :url_path_prefix=
|
153
|
+
|
154
|
+
def url_suffix=(thing)
|
155
|
+
raise NoMethodError, "url_suffix is deprecated - please use url_format, e.g. url_format = '/media/:job/:basename.:format' - see docs for more details"
|
156
|
+
end
|
157
|
+
configuration_method :url_suffix=
|
158
|
+
|
159
|
+
def infer_mime_type_from_file_ext=(bool)
|
160
|
+
raise NoMethodError, "infer_mime_type_from_file_ext is deprecated - please use trust_file_extensions = #{bool.inspect} instead"
|
161
|
+
end
|
162
|
+
configuration_method :infer_mime_type_from_file_ext=
|
160
163
|
|
161
164
|
private
|
162
165
|
|
166
|
+
attr_accessor :get_remote_url
|
167
|
+
|
168
|
+
def saved_configs
|
169
|
+
self.class.saved_configs
|
170
|
+
end
|
171
|
+
|
163
172
|
def file_ext_string(format)
|
164
173
|
'.' + format.to_s.downcase.sub(/^.*\./,'')
|
165
174
|
end
|