dragonfly 0.9.15 → 1.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.
- checksums.yaml +7 -0
- data/.gitignore +1 -8
- data/.travis.yml +11 -0
- data/Gemfile +1 -0
- data/History.md +52 -2
- data/LICENSE +1 -1
- data/README.md +38 -95
- data/dev/grid.jpg +0 -0
- data/dev/irbrc.rb +27 -0
- data/dev/rails_template.rb +38 -0
- data/dev/test.ru +56 -0
- data/dev/test_rails +19 -0
- data/dragonfly.gemspec +3 -21
- data/lib/dragonfly.rb +45 -44
- data/lib/dragonfly/app.rb +175 -96
- data/lib/dragonfly/configurable.rb +71 -170
- data/lib/dragonfly/content.rb +211 -0
- data/lib/dragonfly/core_ext/object.rb +1 -6
- data/lib/dragonfly/file_data_store.rb +197 -0
- data/lib/dragonfly/image_magick/analysers/image_properties.rb +23 -0
- data/lib/dragonfly/image_magick/generators/convert.rb +19 -0
- data/lib/dragonfly/image_magick/generators/plain.rb +26 -0
- data/lib/dragonfly/image_magick/generators/plasma.rb +25 -0
- data/lib/dragonfly/image_magick/generators/text.rb +127 -0
- data/lib/dragonfly/image_magick/plugin.rb +83 -0
- data/lib/dragonfly/image_magick/processors/convert.rb +29 -0
- data/lib/dragonfly/image_magick/processors/encode.rb +18 -0
- data/lib/dragonfly/image_magick/processors/thumb.rb +76 -0
- data/lib/dragonfly/job.rb +118 -134
- data/lib/dragonfly/job_endpoint.rb +2 -0
- data/lib/dragonfly/memory_data_store.rb +34 -0
- data/lib/dragonfly/middleware.rb +5 -3
- data/lib/dragonfly/{active_model_extensions.rb → model.rb} +5 -3
- data/lib/dragonfly/{active_model_extensions → model}/attachment.rb +40 -35
- data/lib/dragonfly/{active_model_extensions → model}/attachment_class_methods.rb +36 -40
- data/lib/dragonfly/model/class_methods.rb +109 -0
- data/lib/dragonfly/{active_model_extensions → model}/instance_methods.rb +2 -2
- data/lib/dragonfly/{active_model_extensions → model}/validations.rb +17 -12
- data/lib/dragonfly/railtie.rb +8 -6
- data/lib/dragonfly/register.rb +27 -0
- data/lib/dragonfly/response.rb +47 -52
- data/lib/dragonfly/routed_endpoint.rb +4 -0
- data/lib/dragonfly/serializer.rb +15 -5
- data/lib/dragonfly/server.rb +56 -29
- data/lib/dragonfly/shell.rb +12 -23
- data/lib/dragonfly/spec/data_store_examples.rb +64 -0
- data/lib/dragonfly/temp_object.rb +32 -47
- data/lib/dragonfly/url_attributes.rb +19 -22
- data/lib/dragonfly/url_mapper.rb +3 -0
- data/lib/dragonfly/utils.rb +12 -0
- data/lib/dragonfly/version.rb +1 -1
- data/lib/dragonfly/whitelist.rb +19 -0
- data/lib/rails/generators/dragonfly/USAGE +8 -0
- data/lib/rails/generators/dragonfly/dragonfly_generator.rb +24 -0
- data/lib/rails/generators/dragonfly/templates/initializer.rb.erb +27 -0
- data/samples/gif.gif +0 -0
- data/spec/dragonfly/app_spec.rb +270 -64
- data/spec/dragonfly/configurable_spec.rb +142 -418
- data/spec/dragonfly/content_spec.rb +353 -0
- data/spec/dragonfly/cookie_monster_spec.rb +2 -1
- data/spec/dragonfly/file_data_store_spec.rb +301 -0
- data/spec/dragonfly/image_magick/analysers/image_properties_spec.rb +20 -0
- data/spec/dragonfly/image_magick/generators/convert_spec.rb +19 -0
- data/spec/dragonfly/image_magick/generators/plain_spec.rb +50 -0
- data/spec/dragonfly/image_magick/generators/plasma_spec.rb +32 -0
- data/spec/dragonfly/image_magick/generators/text_spec.rb +77 -0
- data/spec/dragonfly/image_magick/plugin_spec.rb +131 -0
- data/spec/dragonfly/image_magick/processors/convert_spec.rb +56 -0
- data/spec/dragonfly/image_magick/processors/thumb_spec.rb +173 -0
- data/spec/dragonfly/job_endpoint_spec.rb +30 -73
- data/spec/dragonfly/job_spec.rb +280 -608
- data/spec/dragonfly/memory_data_store_spec.rb +20 -0
- data/spec/dragonfly/middleware_spec.rb +47 -27
- data/spec/dragonfly/{active_model_extensions → model}/model_spec.rb +331 -555
- data/spec/dragonfly/model/validations_spec.rb +196 -0
- data/spec/dragonfly/register_spec.rb +35 -0
- data/spec/dragonfly/routed_endpoint_spec.rb +6 -6
- data/spec/dragonfly/serializer_spec.rb +13 -15
- data/spec/dragonfly/server_spec.rb +122 -46
- data/spec/dragonfly/shell_spec.rb +43 -24
- data/spec/dragonfly/temp_object_spec.rb +69 -94
- data/spec/dragonfly/url_attributes_spec.rb +49 -0
- data/spec/dragonfly/utils_spec.rb +32 -0
- data/spec/dragonfly/whitelist_spec.rb +30 -0
- data/spec/dragonfly_spec.rb +43 -0
- data/spec/fixtures/deprecated_stored_content/eggs.bonus +1 -0
- data/spec/fixtures/deprecated_stored_content/eggs.bonus.meta +1 -0
- data/spec/functional/configuration_spec.rb +19 -0
- data/spec/functional/model_urls_spec.rb +43 -41
- data/spec/functional/remote_on_the_fly_spec.rb +14 -16
- data/spec/functional/shell_commands_spec.rb +24 -14
- data/spec/functional/to_response_spec.rb +10 -10
- data/spec/functional/urls_spec.rb +5 -3
- data/spec/spec_helper.rb +23 -28
- data/spec/support/argument_matchers.rb +7 -8
- data/spec/support/image_matchers.rb +14 -36
- data/spec/support/model_helpers.rb +97 -0
- data/spec/support/simple_matchers.rb +12 -0
- metadata +92 -393
- data/.yardopts +0 -29
- data/Rakefile +0 -36
- data/config.ru +0 -14
- data/docs.watchr +0 -1
- data/extra_docs/Analysers.md +0 -68
- data/extra_docs/Caching.md +0 -23
- data/extra_docs/Configuration.md +0 -149
- data/extra_docs/Couch.md +0 -49
- data/extra_docs/DataStorage.md +0 -226
- data/extra_docs/Encoding.md +0 -67
- data/extra_docs/ExampleUseCases.md +0 -116
- data/extra_docs/GeneralUsage.md +0 -105
- data/extra_docs/Generators.md +0 -68
- data/extra_docs/Heroku.md +0 -50
- data/extra_docs/ImageMagick.md +0 -136
- data/extra_docs/Index.md +0 -33
- data/extra_docs/MimeTypes.md +0 -40
- data/extra_docs/Models.md +0 -441
- data/extra_docs/Mongo.md +0 -42
- data/extra_docs/Processing.md +0 -77
- data/extra_docs/Rack.md +0 -52
- data/extra_docs/Rails2.md +0 -57
- data/extra_docs/Rails3.md +0 -56
- data/extra_docs/ServingRemotely.md +0 -104
- data/extra_docs/Sinatra.md +0 -25
- data/extra_docs/URLs.md +0 -203
- data/features/images.feature +0 -47
- data/features/no_processing.feature +0 -14
- data/features/rails.feature +0 -8
- data/features/steps/common_steps.rb +0 -8
- data/features/steps/dragonfly_steps.rb +0 -66
- data/features/steps/rails_steps.rb +0 -40
- data/features/support/env.rb +0 -13
- data/features/support/setup.rb +0 -41
- data/fixtures/rails/files/app/models/album.rb +0 -6
- data/fixtures/rails/files/app/views/albums/new.html.erb +0 -7
- data/fixtures/rails/files/app/views/albums/show.html.erb +0 -6
- data/fixtures/rails/files/config/initializers/dragonfly.rb +0 -4
- data/fixtures/rails/files/features/manage_album_images.feature +0 -38
- data/fixtures/rails/files/features/step_definitions/helper_steps.rb +0 -7
- data/fixtures/rails/files/features/step_definitions/image_steps.rb +0 -25
- data/fixtures/rails/files/features/step_definitions/web_steps.rb +0 -189
- data/fixtures/rails/files/features/support/paths.rb +0 -17
- data/fixtures/rails/files/features/text_images.feature +0 -7
- data/fixtures/rails/template.rb +0 -20
- data/irbrc.rb +0 -19
- data/lib/dragonfly/active_model_extensions/class_methods.rb +0 -98
- data/lib/dragonfly/analyser.rb +0 -58
- data/lib/dragonfly/analysis/file_command_analyser.rb +0 -33
- data/lib/dragonfly/analysis/image_magick_analyser.rb +0 -6
- data/lib/dragonfly/config/heroku.rb +0 -26
- data/lib/dragonfly/config/image_magick.rb +0 -6
- data/lib/dragonfly/config/rails.rb +0 -20
- data/lib/dragonfly/data_storage.rb +0 -11
- data/lib/dragonfly/data_storage/couch_data_store.rb +0 -83
- data/lib/dragonfly/data_storage/file_data_store.rb +0 -144
- data/lib/dragonfly/data_storage/mongo_data_store.rb +0 -96
- data/lib/dragonfly/data_storage/s3data_store.rb +0 -168
- data/lib/dragonfly/encoder.rb +0 -13
- data/lib/dragonfly/encoding/image_magick_encoder.rb +0 -6
- data/lib/dragonfly/function_manager.rb +0 -67
- data/lib/dragonfly/generation/image_magick_generator.rb +0 -6
- data/lib/dragonfly/generator.rb +0 -9
- data/lib/dragonfly/image_magick/analyser.rb +0 -53
- data/lib/dragonfly/image_magick/config.rb +0 -44
- data/lib/dragonfly/image_magick/encoder.rb +0 -57
- data/lib/dragonfly/image_magick/generator.rb +0 -147
- data/lib/dragonfly/image_magick/processor.rb +0 -114
- data/lib/dragonfly/image_magick/utils.rb +0 -46
- data/lib/dragonfly/image_magick_utils.rb +0 -4
- data/lib/dragonfly/job_builder.rb +0 -39
- data/lib/dragonfly/job_definitions.rb +0 -30
- data/lib/dragonfly/loggable.rb +0 -28
- data/lib/dragonfly/processing/image_magick_processor.rb +0 -6
- data/lib/dragonfly/processor.rb +0 -9
- data/lib/dragonfly/rails/images.rb +0 -32
- data/lib/dragonfly/simple_cache.rb +0 -23
- data/spec/dragonfly/active_model_extensions/spec_helper.rb +0 -95
- data/spec/dragonfly/analyser_spec.rb +0 -123
- data/spec/dragonfly/analysis/file_command_analyser_spec.rb +0 -49
- data/spec/dragonfly/data_storage/couch_data_store_spec.rb +0 -84
- data/spec/dragonfly/data_storage/file_data_store_spec.rb +0 -308
- data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +0 -81
- data/spec/dragonfly/data_storage/s3_data_store_spec.rb +0 -277
- data/spec/dragonfly/data_storage/shared_data_store_examples.rb +0 -77
- data/spec/dragonfly/function_manager_spec.rb +0 -154
- data/spec/dragonfly/image_magick/analyser_spec.rb +0 -73
- data/spec/dragonfly/image_magick/encoder_spec.rb +0 -46
- data/spec/dragonfly/image_magick/generator_spec.rb +0 -178
- data/spec/dragonfly/image_magick/processor_spec.rb +0 -293
- data/spec/dragonfly/job_builder_spec.rb +0 -37
- data/spec/dragonfly/job_definitions_spec.rb +0 -57
- data/spec/dragonfly/loggable_spec.rb +0 -80
- data/spec/dragonfly/simple_cache_spec.rb +0 -27
- data/spec/dragonfly/url_attributes.rb +0 -47
- data/spec/functional/deprecations_spec.rb +0 -51
- data/spec/functional/image_magick_app_spec.rb +0 -27
- data/spec/test_imagemagick.ru +0 -49
- data/yard/handlers/configurable_attr_handler.rb +0 -38
- data/yard/setup.rb +0 -15
- data/yard/templates/default/fulldoc/html/css/common.css +0 -109
- data/yard/templates/default/layout/html/layout.erb +0 -93
- data/yard/templates/default/module/html/configuration_summary.erb +0 -31
- data/yard/templates/default/module/setup.rb +0 -17
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'mongo'
|
2
|
-
|
3
|
-
module Dragonfly
|
4
|
-
module DataStorage
|
5
|
-
class MongoDataStore
|
6
|
-
|
7
|
-
include Configurable
|
8
|
-
include Serializer
|
9
|
-
|
10
|
-
configurable_attr :host
|
11
|
-
configurable_attr :hosts
|
12
|
-
configurable_attr :connection_opts, {}
|
13
|
-
configurable_attr :port
|
14
|
-
configurable_attr :database, 'dragonfly'
|
15
|
-
configurable_attr :username
|
16
|
-
configurable_attr :password
|
17
|
-
configurable_attr :connection
|
18
|
-
configurable_attr :db
|
19
|
-
|
20
|
-
# Mongo gem deprecated ObjectID in favour of ObjectId
|
21
|
-
OBJECT_ID = defined?(BSON::ObjectId) ? BSON::ObjectId : BSON::ObjectID
|
22
|
-
INVALID_OBJECT_ID = defined?(BSON::InvalidObjectId) ? BSON::InvalidObjectId : BSON::InvalidObjectID
|
23
|
-
|
24
|
-
def initialize(opts={})
|
25
|
-
self.host = opts[:host]
|
26
|
-
self.hosts = opts[:hosts]
|
27
|
-
self.connection_opts = opts[:connection_opts] if opts[:connection_opts]
|
28
|
-
self.port = opts[:port]
|
29
|
-
self.database = opts[:database] if opts[:database]
|
30
|
-
self.username = opts[:username]
|
31
|
-
self.password = opts[:password]
|
32
|
-
self.connection = opts[:connection]
|
33
|
-
self.db = opts[:db]
|
34
|
-
end
|
35
|
-
|
36
|
-
def store(temp_object, opts={})
|
37
|
-
ensure_authenticated!
|
38
|
-
content_type = opts[:content_type] || opts[:mime_type] || 'application/octet-stream'
|
39
|
-
temp_object.file do |f|
|
40
|
-
mongo_id = grid.put(f, :content_type => content_type,
|
41
|
-
:metadata => marshal_encode(temp_object.meta))
|
42
|
-
mongo_id.to_s
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def retrieve(uid)
|
47
|
-
ensure_authenticated!
|
48
|
-
grid_io = grid.get(bson_id(uid))
|
49
|
-
meta = marshal_decode(grid_io.metadata)
|
50
|
-
meta.merge!(:stored_at => grid_io.upload_date)
|
51
|
-
[
|
52
|
-
grid_io.read,
|
53
|
-
meta
|
54
|
-
]
|
55
|
-
rescue Mongo::GridFileNotFound, INVALID_OBJECT_ID => e
|
56
|
-
raise DataNotFound, "#{e} - #{uid}"
|
57
|
-
end
|
58
|
-
|
59
|
-
def destroy(uid)
|
60
|
-
ensure_authenticated!
|
61
|
-
grid.delete(bson_id(uid))
|
62
|
-
rescue Mongo::GridFileNotFound, INVALID_OBJECT_ID => e
|
63
|
-
raise DataNotFound, "#{e} - #{uid}"
|
64
|
-
end
|
65
|
-
|
66
|
-
def connection
|
67
|
-
@connection ||= if hosts
|
68
|
-
Mongo::ReplSetConnection.new(hosts, connection_opts)
|
69
|
-
else
|
70
|
-
Mongo::Connection.new(host, port, connection_opts)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def db
|
75
|
-
@db ||= connection.db(database)
|
76
|
-
end
|
77
|
-
|
78
|
-
def grid
|
79
|
-
@grid ||= Mongo::Grid.new(db)
|
80
|
-
end
|
81
|
-
|
82
|
-
private
|
83
|
-
|
84
|
-
def ensure_authenticated!
|
85
|
-
if username
|
86
|
-
@authenticated ||= db.authenticate(username, password)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def bson_id(uid)
|
91
|
-
OBJECT_ID.from_string(uid)
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,168 +0,0 @@
|
|
1
|
-
require 'fog'
|
2
|
-
|
3
|
-
module Dragonfly
|
4
|
-
module DataStorage
|
5
|
-
|
6
|
-
class S3DataStore
|
7
|
-
|
8
|
-
include Configurable
|
9
|
-
include Serializer
|
10
|
-
|
11
|
-
configurable_attr :bucket_name
|
12
|
-
configurable_attr :access_key_id
|
13
|
-
configurable_attr :secret_access_key
|
14
|
-
configurable_attr :region
|
15
|
-
configurable_attr :use_filesystem, true
|
16
|
-
configurable_attr :storage_headers, {'x-amz-acl' => 'public-read'}
|
17
|
-
configurable_attr :url_scheme, 'http'
|
18
|
-
configurable_attr :url_host
|
19
|
-
|
20
|
-
REGIONS = {
|
21
|
-
'us-east-1' => 's3.amazonaws.com', #default
|
22
|
-
'us-west-1' => 's3-us-west-1.amazonaws.com',
|
23
|
-
'us-west-2' => 's3-us-west-2.amazonaws.com',
|
24
|
-
'ap-northeast-1' => 's3-ap-northeast-1.amazonaws.com',
|
25
|
-
'ap-southeast-1' => 's3-ap-southeast-1.amazonaws.com',
|
26
|
-
'eu-west-1' => 's3-eu-west-1.amazonaws.com',
|
27
|
-
'sa-east-1' => 's3-sa-east-1.amazonaws.com',
|
28
|
-
'sa-east-1' => 's3-sa-east-1.amazonaws.com'
|
29
|
-
}
|
30
|
-
|
31
|
-
def initialize(opts={})
|
32
|
-
self.bucket_name = opts[:bucket_name]
|
33
|
-
self.access_key_id = opts[:access_key_id]
|
34
|
-
self.secret_access_key = opts[:secret_access_key]
|
35
|
-
self.region = opts[:region]
|
36
|
-
end
|
37
|
-
|
38
|
-
def store(temp_object, opts={})
|
39
|
-
ensure_configured
|
40
|
-
ensure_bucket_initialized
|
41
|
-
|
42
|
-
headers = opts[:headers] || {}
|
43
|
-
mime_type = opts[:mime_type] || opts[:content_type]
|
44
|
-
headers['Content-Type'] = mime_type if mime_type
|
45
|
-
uid = opts[:path] || generate_uid(temp_object.name || 'file')
|
46
|
-
|
47
|
-
rescuing_socket_errors do
|
48
|
-
if use_filesystem
|
49
|
-
temp_object.file do |f|
|
50
|
-
storage.put_object(bucket_name, uid, f, full_storage_headers(headers, temp_object.meta))
|
51
|
-
end
|
52
|
-
else
|
53
|
-
storage.put_object(bucket_name, uid, temp_object.data, full_storage_headers(headers, temp_object.meta))
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
uid
|
58
|
-
end
|
59
|
-
|
60
|
-
def retrieve(uid)
|
61
|
-
ensure_configured
|
62
|
-
response = rescuing_socket_errors{ storage.get_object(bucket_name, uid) }
|
63
|
-
[
|
64
|
-
response.body,
|
65
|
-
parse_s3_metadata(response.headers)
|
66
|
-
]
|
67
|
-
rescue Excon::Errors::NotFound => e
|
68
|
-
raise DataNotFound, "#{e} - #{uid}"
|
69
|
-
end
|
70
|
-
|
71
|
-
def destroy(uid)
|
72
|
-
rescuing_socket_errors{ storage.delete_object(bucket_name, uid) }
|
73
|
-
rescue Excon::Errors::NotFound => e
|
74
|
-
raise DataNotFound, "#{e} - #{uid}"
|
75
|
-
rescue Excon::Errors::Conflict => e
|
76
|
-
raise DestroyError, "#{e} - #{uid}"
|
77
|
-
end
|
78
|
-
|
79
|
-
def url_for(uid, opts={})
|
80
|
-
if opts && opts[:expires]
|
81
|
-
if storage.respond_to?(:get_object_https_url) # fog's get_object_url is deprecated (aug 2011)
|
82
|
-
storage.get_object_https_url(bucket_name, uid, opts[:expires])
|
83
|
-
else
|
84
|
-
storage.get_object_url(bucket_name, uid, opts[:expires])
|
85
|
-
end
|
86
|
-
else
|
87
|
-
scheme = opts[:scheme] || url_scheme
|
88
|
-
host = opts[:host] || url_host || "#{bucket_name}.s3.amazonaws.com"
|
89
|
-
"#{scheme}://#{host}/#{uid}"
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def domain
|
94
|
-
REGIONS[get_region]
|
95
|
-
end
|
96
|
-
|
97
|
-
def storage
|
98
|
-
@storage ||= begin
|
99
|
-
storage = Fog::Storage.new(
|
100
|
-
:provider => 'AWS',
|
101
|
-
:aws_access_key_id => access_key_id,
|
102
|
-
:aws_secret_access_key => secret_access_key,
|
103
|
-
:region => region
|
104
|
-
)
|
105
|
-
storage.sync_clock
|
106
|
-
storage
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def bucket_exists?
|
111
|
-
rescuing_socket_errors{ storage.get_bucket(bucket_name) }
|
112
|
-
true
|
113
|
-
rescue Excon::Errors::NotFound => e
|
114
|
-
false
|
115
|
-
end
|
116
|
-
|
117
|
-
private
|
118
|
-
|
119
|
-
def ensure_configured
|
120
|
-
unless @configured
|
121
|
-
[:bucket_name, :access_key_id, :secret_access_key].each do |attr|
|
122
|
-
raise NotConfigured, "You need to configure #{self.class.name} with #{attr}" if send(attr).nil?
|
123
|
-
end
|
124
|
-
@configured = true
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def ensure_bucket_initialized
|
129
|
-
unless @bucket_initialized
|
130
|
-
rescuing_socket_errors{ storage.put_bucket(bucket_name, 'LocationConstraint' => region) } unless bucket_exists?
|
131
|
-
@bucket_initialized = true
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
def get_region
|
136
|
-
reg = region || 'us-east-1'
|
137
|
-
raise "Invalid region #{reg} - should be one of #{valid_regions.join(', ')}" unless valid_regions.include?(reg)
|
138
|
-
reg
|
139
|
-
end
|
140
|
-
|
141
|
-
def generate_uid(name)
|
142
|
-
"#{Time.now.strftime '%Y/%m/%d/%H/%M/%S'}/#{rand(1000)}/#{name.gsub(/[^\w.]+/, '_')}"
|
143
|
-
end
|
144
|
-
|
145
|
-
def full_storage_headers(headers, meta)
|
146
|
-
{'x-amz-meta-extra' => marshal_encode(meta)}.merge(storage_headers).merge(headers)
|
147
|
-
end
|
148
|
-
|
149
|
-
def parse_s3_metadata(headers)
|
150
|
-
encoded_meta = headers['x-amz-meta-extra']
|
151
|
-
(marshal_decode(encoded_meta) if encoded_meta) || {}
|
152
|
-
end
|
153
|
-
|
154
|
-
def valid_regions
|
155
|
-
REGIONS.keys
|
156
|
-
end
|
157
|
-
|
158
|
-
def rescuing_socket_errors(&block)
|
159
|
-
yield
|
160
|
-
rescue Excon::Errors::SocketError => e
|
161
|
-
storage.reload
|
162
|
-
yield
|
163
|
-
end
|
164
|
-
|
165
|
-
end
|
166
|
-
|
167
|
-
end
|
168
|
-
end
|
data/lib/dragonfly/encoder.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
module Dragonfly
|
2
|
-
class FunctionManager
|
3
|
-
|
4
|
-
# Exceptions
|
5
|
-
class NotDefined < NoMethodError; end
|
6
|
-
class UnableToHandle < NotImplementedError; end
|
7
|
-
|
8
|
-
include Loggable
|
9
|
-
include Configurable
|
10
|
-
|
11
|
-
def initialize
|
12
|
-
@functions = {}
|
13
|
-
@objects = []
|
14
|
-
end
|
15
|
-
|
16
|
-
def add(name, callable_obj=nil, &block)
|
17
|
-
functions[name] ||= []
|
18
|
-
functions[name] << (callable_obj || block)
|
19
|
-
end
|
20
|
-
|
21
|
-
attr_reader :functions, :objects
|
22
|
-
|
23
|
-
def register(klass, *args, &block)
|
24
|
-
obj = klass.new(*args)
|
25
|
-
obj.configure(&block) if block
|
26
|
-
obj.use_same_log_as(self) if obj.is_a?(Loggable)
|
27
|
-
obj.use_as_fallback_config(self) if obj.is_a?(Configurable)
|
28
|
-
methods_to_add(obj).each do |meth|
|
29
|
-
add meth, obj.method(meth)
|
30
|
-
end
|
31
|
-
objects << obj
|
32
|
-
obj
|
33
|
-
end
|
34
|
-
|
35
|
-
def call_last(meth, *args)
|
36
|
-
if functions[meth.to_sym]
|
37
|
-
functions[meth.to_sym].reverse.each do |function|
|
38
|
-
catch :unable_to_handle do
|
39
|
-
return function.call(*args)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
# If the code gets here, then none of the registered functions were able to handle the method call
|
43
|
-
raise UnableToHandle, "None of the functions registered with #{self} were able to deal with the method call " +
|
44
|
-
"#{meth}(#{args.map{|a| a.inspect[0..100]}.join(',')}). You may need to register one that can."
|
45
|
-
else
|
46
|
-
raise NotDefined, "function #{meth} not registered with #{self}"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def get_registered(klass)
|
51
|
-
objects.reverse.detect{|o| o.instance_of?(klass) }
|
52
|
-
end
|
53
|
-
|
54
|
-
def inspect
|
55
|
-
"<#{self.class.name} with functions: #{functions.keys.map{|k| k.to_s }.sort.join(', ')} >"
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
def methods_to_add(obj)
|
61
|
-
methods = obj.public_methods(false).map{|m| m.to_sym }
|
62
|
-
methods -= obj.config_methods if obj.is_a?(Configurable)
|
63
|
-
methods
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
end
|
data/lib/dragonfly/generator.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
module Dragonfly
|
2
|
-
module ImageMagick
|
3
|
-
class Analyser
|
4
|
-
|
5
|
-
include Configurable
|
6
|
-
include Utils
|
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
|
-
alias portrait portrait?
|
26
|
-
|
27
|
-
def landscape?(temp_object)
|
28
|
-
attrs = identify(temp_object)
|
29
|
-
attrs[:width] >= attrs[:height]
|
30
|
-
end
|
31
|
-
alias landscape landscape?
|
32
|
-
|
33
|
-
def depth(temp_object)
|
34
|
-
identify(temp_object)[:depth]
|
35
|
-
end
|
36
|
-
|
37
|
-
def number_of_colours(temp_object)
|
38
|
-
details = raw_identify(temp_object, '-verbose -unique')
|
39
|
-
details[/Colors: (\d+)/, 1].to_i
|
40
|
-
end
|
41
|
-
alias number_of_colors number_of_colours
|
42
|
-
|
43
|
-
def format(temp_object)
|
44
|
-
identify(temp_object)[:format]
|
45
|
-
end
|
46
|
-
|
47
|
-
def image?(temp_object)
|
48
|
-
!!catch(:unable_to_handle){ identify(temp_object) }
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
module Dragonfly
|
2
|
-
module ImageMagick
|
3
|
-
|
4
|
-
# ImageMagick Config is a saved configuration for Dragonfly apps, which does the following:
|
5
|
-
# - registers an imagemagick analyser
|
6
|
-
# - registers an imagemagick processor
|
7
|
-
# - registers an imagemagick encoder
|
8
|
-
# - adds thumb shortcuts like '280x140!', etc.
|
9
|
-
# Look at the source code for apply_configuration to see exactly how it configures the app.
|
10
|
-
module Config
|
11
|
-
|
12
|
-
def self.apply_configuration(app, opts={})
|
13
|
-
app.configure do |c|
|
14
|
-
c.analyser.register(ImageMagick::Analyser)
|
15
|
-
c.processor.register(ImageMagick::Processor)
|
16
|
-
c.encoder.register(ImageMagick::Encoder)
|
17
|
-
c.generator.register(ImageMagick::Generator)
|
18
|
-
|
19
|
-
c.job :thumb do |geometry, format|
|
20
|
-
process :thumb, geometry
|
21
|
-
encode format if format
|
22
|
-
end
|
23
|
-
c.job :gif do
|
24
|
-
encode :gif
|
25
|
-
end
|
26
|
-
c.job :jpg do
|
27
|
-
encode :jpg
|
28
|
-
end
|
29
|
-
c.job :png do
|
30
|
-
encode :png
|
31
|
-
end
|
32
|
-
c.job :strip do
|
33
|
-
process :strip
|
34
|
-
end
|
35
|
-
c.job :convert do |args, format|
|
36
|
-
process :convert, args, format
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|