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.

Files changed (203) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -8
  3. data/.travis.yml +11 -0
  4. data/Gemfile +1 -0
  5. data/History.md +52 -2
  6. data/LICENSE +1 -1
  7. data/README.md +38 -95
  8. data/dev/grid.jpg +0 -0
  9. data/dev/irbrc.rb +27 -0
  10. data/dev/rails_template.rb +38 -0
  11. data/dev/test.ru +56 -0
  12. data/dev/test_rails +19 -0
  13. data/dragonfly.gemspec +3 -21
  14. data/lib/dragonfly.rb +45 -44
  15. data/lib/dragonfly/app.rb +175 -96
  16. data/lib/dragonfly/configurable.rb +71 -170
  17. data/lib/dragonfly/content.rb +211 -0
  18. data/lib/dragonfly/core_ext/object.rb +1 -6
  19. data/lib/dragonfly/file_data_store.rb +197 -0
  20. data/lib/dragonfly/image_magick/analysers/image_properties.rb +23 -0
  21. data/lib/dragonfly/image_magick/generators/convert.rb +19 -0
  22. data/lib/dragonfly/image_magick/generators/plain.rb +26 -0
  23. data/lib/dragonfly/image_magick/generators/plasma.rb +25 -0
  24. data/lib/dragonfly/image_magick/generators/text.rb +127 -0
  25. data/lib/dragonfly/image_magick/plugin.rb +83 -0
  26. data/lib/dragonfly/image_magick/processors/convert.rb +29 -0
  27. data/lib/dragonfly/image_magick/processors/encode.rb +18 -0
  28. data/lib/dragonfly/image_magick/processors/thumb.rb +76 -0
  29. data/lib/dragonfly/job.rb +118 -134
  30. data/lib/dragonfly/job_endpoint.rb +2 -0
  31. data/lib/dragonfly/memory_data_store.rb +34 -0
  32. data/lib/dragonfly/middleware.rb +5 -3
  33. data/lib/dragonfly/{active_model_extensions.rb → model.rb} +5 -3
  34. data/lib/dragonfly/{active_model_extensions → model}/attachment.rb +40 -35
  35. data/lib/dragonfly/{active_model_extensions → model}/attachment_class_methods.rb +36 -40
  36. data/lib/dragonfly/model/class_methods.rb +109 -0
  37. data/lib/dragonfly/{active_model_extensions → model}/instance_methods.rb +2 -2
  38. data/lib/dragonfly/{active_model_extensions → model}/validations.rb +17 -12
  39. data/lib/dragonfly/railtie.rb +8 -6
  40. data/lib/dragonfly/register.rb +27 -0
  41. data/lib/dragonfly/response.rb +47 -52
  42. data/lib/dragonfly/routed_endpoint.rb +4 -0
  43. data/lib/dragonfly/serializer.rb +15 -5
  44. data/lib/dragonfly/server.rb +56 -29
  45. data/lib/dragonfly/shell.rb +12 -23
  46. data/lib/dragonfly/spec/data_store_examples.rb +64 -0
  47. data/lib/dragonfly/temp_object.rb +32 -47
  48. data/lib/dragonfly/url_attributes.rb +19 -22
  49. data/lib/dragonfly/url_mapper.rb +3 -0
  50. data/lib/dragonfly/utils.rb +12 -0
  51. data/lib/dragonfly/version.rb +1 -1
  52. data/lib/dragonfly/whitelist.rb +19 -0
  53. data/lib/rails/generators/dragonfly/USAGE +8 -0
  54. data/lib/rails/generators/dragonfly/dragonfly_generator.rb +24 -0
  55. data/lib/rails/generators/dragonfly/templates/initializer.rb.erb +27 -0
  56. data/samples/gif.gif +0 -0
  57. data/spec/dragonfly/app_spec.rb +270 -64
  58. data/spec/dragonfly/configurable_spec.rb +142 -418
  59. data/spec/dragonfly/content_spec.rb +353 -0
  60. data/spec/dragonfly/cookie_monster_spec.rb +2 -1
  61. data/spec/dragonfly/file_data_store_spec.rb +301 -0
  62. data/spec/dragonfly/image_magick/analysers/image_properties_spec.rb +20 -0
  63. data/spec/dragonfly/image_magick/generators/convert_spec.rb +19 -0
  64. data/spec/dragonfly/image_magick/generators/plain_spec.rb +50 -0
  65. data/spec/dragonfly/image_magick/generators/plasma_spec.rb +32 -0
  66. data/spec/dragonfly/image_magick/generators/text_spec.rb +77 -0
  67. data/spec/dragonfly/image_magick/plugin_spec.rb +131 -0
  68. data/spec/dragonfly/image_magick/processors/convert_spec.rb +56 -0
  69. data/spec/dragonfly/image_magick/processors/thumb_spec.rb +173 -0
  70. data/spec/dragonfly/job_endpoint_spec.rb +30 -73
  71. data/spec/dragonfly/job_spec.rb +280 -608
  72. data/spec/dragonfly/memory_data_store_spec.rb +20 -0
  73. data/spec/dragonfly/middleware_spec.rb +47 -27
  74. data/spec/dragonfly/{active_model_extensions → model}/model_spec.rb +331 -555
  75. data/spec/dragonfly/model/validations_spec.rb +196 -0
  76. data/spec/dragonfly/register_spec.rb +35 -0
  77. data/spec/dragonfly/routed_endpoint_spec.rb +6 -6
  78. data/spec/dragonfly/serializer_spec.rb +13 -15
  79. data/spec/dragonfly/server_spec.rb +122 -46
  80. data/spec/dragonfly/shell_spec.rb +43 -24
  81. data/spec/dragonfly/temp_object_spec.rb +69 -94
  82. data/spec/dragonfly/url_attributes_spec.rb +49 -0
  83. data/spec/dragonfly/utils_spec.rb +32 -0
  84. data/spec/dragonfly/whitelist_spec.rb +30 -0
  85. data/spec/dragonfly_spec.rb +43 -0
  86. data/spec/fixtures/deprecated_stored_content/eggs.bonus +1 -0
  87. data/spec/fixtures/deprecated_stored_content/eggs.bonus.meta +1 -0
  88. data/spec/functional/configuration_spec.rb +19 -0
  89. data/spec/functional/model_urls_spec.rb +43 -41
  90. data/spec/functional/remote_on_the_fly_spec.rb +14 -16
  91. data/spec/functional/shell_commands_spec.rb +24 -14
  92. data/spec/functional/to_response_spec.rb +10 -10
  93. data/spec/functional/urls_spec.rb +5 -3
  94. data/spec/spec_helper.rb +23 -28
  95. data/spec/support/argument_matchers.rb +7 -8
  96. data/spec/support/image_matchers.rb +14 -36
  97. data/spec/support/model_helpers.rb +97 -0
  98. data/spec/support/simple_matchers.rb +12 -0
  99. metadata +92 -393
  100. data/.yardopts +0 -29
  101. data/Rakefile +0 -36
  102. data/config.ru +0 -14
  103. data/docs.watchr +0 -1
  104. data/extra_docs/Analysers.md +0 -68
  105. data/extra_docs/Caching.md +0 -23
  106. data/extra_docs/Configuration.md +0 -149
  107. data/extra_docs/Couch.md +0 -49
  108. data/extra_docs/DataStorage.md +0 -226
  109. data/extra_docs/Encoding.md +0 -67
  110. data/extra_docs/ExampleUseCases.md +0 -116
  111. data/extra_docs/GeneralUsage.md +0 -105
  112. data/extra_docs/Generators.md +0 -68
  113. data/extra_docs/Heroku.md +0 -50
  114. data/extra_docs/ImageMagick.md +0 -136
  115. data/extra_docs/Index.md +0 -33
  116. data/extra_docs/MimeTypes.md +0 -40
  117. data/extra_docs/Models.md +0 -441
  118. data/extra_docs/Mongo.md +0 -42
  119. data/extra_docs/Processing.md +0 -77
  120. data/extra_docs/Rack.md +0 -52
  121. data/extra_docs/Rails2.md +0 -57
  122. data/extra_docs/Rails3.md +0 -56
  123. data/extra_docs/ServingRemotely.md +0 -104
  124. data/extra_docs/Sinatra.md +0 -25
  125. data/extra_docs/URLs.md +0 -203
  126. data/features/images.feature +0 -47
  127. data/features/no_processing.feature +0 -14
  128. data/features/rails.feature +0 -8
  129. data/features/steps/common_steps.rb +0 -8
  130. data/features/steps/dragonfly_steps.rb +0 -66
  131. data/features/steps/rails_steps.rb +0 -40
  132. data/features/support/env.rb +0 -13
  133. data/features/support/setup.rb +0 -41
  134. data/fixtures/rails/files/app/models/album.rb +0 -6
  135. data/fixtures/rails/files/app/views/albums/new.html.erb +0 -7
  136. data/fixtures/rails/files/app/views/albums/show.html.erb +0 -6
  137. data/fixtures/rails/files/config/initializers/dragonfly.rb +0 -4
  138. data/fixtures/rails/files/features/manage_album_images.feature +0 -38
  139. data/fixtures/rails/files/features/step_definitions/helper_steps.rb +0 -7
  140. data/fixtures/rails/files/features/step_definitions/image_steps.rb +0 -25
  141. data/fixtures/rails/files/features/step_definitions/web_steps.rb +0 -189
  142. data/fixtures/rails/files/features/support/paths.rb +0 -17
  143. data/fixtures/rails/files/features/text_images.feature +0 -7
  144. data/fixtures/rails/template.rb +0 -20
  145. data/irbrc.rb +0 -19
  146. data/lib/dragonfly/active_model_extensions/class_methods.rb +0 -98
  147. data/lib/dragonfly/analyser.rb +0 -58
  148. data/lib/dragonfly/analysis/file_command_analyser.rb +0 -33
  149. data/lib/dragonfly/analysis/image_magick_analyser.rb +0 -6
  150. data/lib/dragonfly/config/heroku.rb +0 -26
  151. data/lib/dragonfly/config/image_magick.rb +0 -6
  152. data/lib/dragonfly/config/rails.rb +0 -20
  153. data/lib/dragonfly/data_storage.rb +0 -11
  154. data/lib/dragonfly/data_storage/couch_data_store.rb +0 -83
  155. data/lib/dragonfly/data_storage/file_data_store.rb +0 -144
  156. data/lib/dragonfly/data_storage/mongo_data_store.rb +0 -96
  157. data/lib/dragonfly/data_storage/s3data_store.rb +0 -168
  158. data/lib/dragonfly/encoder.rb +0 -13
  159. data/lib/dragonfly/encoding/image_magick_encoder.rb +0 -6
  160. data/lib/dragonfly/function_manager.rb +0 -67
  161. data/lib/dragonfly/generation/image_magick_generator.rb +0 -6
  162. data/lib/dragonfly/generator.rb +0 -9
  163. data/lib/dragonfly/image_magick/analyser.rb +0 -53
  164. data/lib/dragonfly/image_magick/config.rb +0 -44
  165. data/lib/dragonfly/image_magick/encoder.rb +0 -57
  166. data/lib/dragonfly/image_magick/generator.rb +0 -147
  167. data/lib/dragonfly/image_magick/processor.rb +0 -114
  168. data/lib/dragonfly/image_magick/utils.rb +0 -46
  169. data/lib/dragonfly/image_magick_utils.rb +0 -4
  170. data/lib/dragonfly/job_builder.rb +0 -39
  171. data/lib/dragonfly/job_definitions.rb +0 -30
  172. data/lib/dragonfly/loggable.rb +0 -28
  173. data/lib/dragonfly/processing/image_magick_processor.rb +0 -6
  174. data/lib/dragonfly/processor.rb +0 -9
  175. data/lib/dragonfly/rails/images.rb +0 -32
  176. data/lib/dragonfly/simple_cache.rb +0 -23
  177. data/spec/dragonfly/active_model_extensions/spec_helper.rb +0 -95
  178. data/spec/dragonfly/analyser_spec.rb +0 -123
  179. data/spec/dragonfly/analysis/file_command_analyser_spec.rb +0 -49
  180. data/spec/dragonfly/data_storage/couch_data_store_spec.rb +0 -84
  181. data/spec/dragonfly/data_storage/file_data_store_spec.rb +0 -308
  182. data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +0 -81
  183. data/spec/dragonfly/data_storage/s3_data_store_spec.rb +0 -277
  184. data/spec/dragonfly/data_storage/shared_data_store_examples.rb +0 -77
  185. data/spec/dragonfly/function_manager_spec.rb +0 -154
  186. data/spec/dragonfly/image_magick/analyser_spec.rb +0 -73
  187. data/spec/dragonfly/image_magick/encoder_spec.rb +0 -46
  188. data/spec/dragonfly/image_magick/generator_spec.rb +0 -178
  189. data/spec/dragonfly/image_magick/processor_spec.rb +0 -293
  190. data/spec/dragonfly/job_builder_spec.rb +0 -37
  191. data/spec/dragonfly/job_definitions_spec.rb +0 -57
  192. data/spec/dragonfly/loggable_spec.rb +0 -80
  193. data/spec/dragonfly/simple_cache_spec.rb +0 -27
  194. data/spec/dragonfly/url_attributes.rb +0 -47
  195. data/spec/functional/deprecations_spec.rb +0 -51
  196. data/spec/functional/image_magick_app_spec.rb +0 -27
  197. data/spec/test_imagemagick.ru +0 -49
  198. data/yard/handlers/configurable_attr_handler.rb +0 -38
  199. data/yard/setup.rb +0 -15
  200. data/yard/templates/default/fulldoc/html/css/common.css +0 -109
  201. data/yard/templates/default/layout/html/layout.erb +0 -93
  202. data/yard/templates/default/module/html/configuration_summary.erb +0 -31
  203. 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
@@ -1,13 +0,0 @@
1
- module Dragonfly
2
- class Encoder < FunctionManager
3
-
4
- def add(name=:encode, callable_obj=nil, &block)
5
- super(name, callable_obj, &block)
6
- end
7
-
8
- def encode(temp_object, *args)
9
- call_last(:encode, temp_object, *args)
10
- end
11
-
12
- end
13
- end
@@ -1,6 +0,0 @@
1
- module Dragonfly
2
- module Encoding
3
- puts "WARNING: Dragonfly::Encoding::ImageMagickEncoder is DEPRECATED and will soon be removed. Please use Dragonfly::ImageMagick::Encoder instead."
4
- ImageMagickEncoder = ImageMagick::Encoder
5
- end
6
- end
@@ -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
@@ -1,6 +0,0 @@
1
- module Dragonfly
2
- module Generation
3
- puts "WARNING: Dragonfly::Generation::ImageMagickGenerator is DEPRECATED and will soon be removed. Please use Dragonfly::ImageMagick::Generator instead."
4
- ImageMagickGenerator = ImageMagick::Generator
5
- end
6
- end
@@ -1,9 +0,0 @@
1
- module Dragonfly
2
- class Generator < FunctionManager
3
-
4
- def generate(method, *args)
5
- call_last(method, *args)
6
- end
7
-
8
- end
9
- end
@@ -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