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,60 +1,61 @@
1
- # AUTOLOAD EVERYTHING IN THE DRAGONFLY DIRECTORY TREE
2
-
3
- # The convention is that dirs are modules
4
- # so declare them here and autoload any modules/classes inside them
5
- # All paths here are absolute
6
- camelize = proc do |path|
7
- # e.g. 'test/this_one' => Test::ThisOne
8
- "#{path}".
9
- chomp('/').
10
- gsub('/','::').
11
- gsub(/([^a-z])(\w)/){ "#{$1}#{$2.upcase}" }.
12
- gsub('_','').
13
- sub(/^(\w)/){ $1.upcase }
14
- end
15
-
16
- autoload_files_in_dir = proc do |path, namespace|
17
- # Define the module
18
- eval("module #{namespace}; end")
19
- # Autoload modules/classes in that module
20
- Dir.glob("#{path}/*.rb").each do |file|
21
- file = File.expand_path(file)
22
- sub_const_name = camelize[ File.basename(file, '.rb') ]
23
- eval("#{namespace}.autoload('#{sub_const_name}', '#{file}')")
24
- end
25
- # Recurse on subdirectories
26
- Dir.glob("#{path}/*/").each do |dir|
27
- sub_namespace = camelize[ File.basename(dir) ]
28
- autoload_files_in_dir[dir, "#{namespace}::#{sub_namespace}"]
29
- end
30
- end
31
-
32
- autoload_files_in_dir["#{File.dirname(__FILE__)}/dragonfly", 'Dragonfly']
33
-
1
+ require 'rbconfig'
2
+ require 'logger'
34
3
  require 'dragonfly/version'
35
4
  require 'dragonfly/core_ext/object'
36
5
  require 'dragonfly/core_ext/array'
37
6
  require 'dragonfly/core_ext/hash'
38
-
39
- Dragonfly::Railtie if defined?(::Rails) # Coz it will autoload
7
+ require 'dragonfly/app'
8
+ require 'dragonfly/image_magick/plugin'
9
+ require 'dragonfly/file_data_store'
10
+ require 'dragonfly/memory_data_store'
11
+ require 'dragonfly/model'
12
+ require 'dragonfly/middleware'
13
+
14
+ if defined?(::Rails)
15
+ require 'dragonfly/railtie'
16
+ require 'dragonfly/model/validations'
17
+ end
40
18
 
41
19
  module Dragonfly
42
20
  class << self
43
21
 
44
- def [](*args)
45
- App[*args]
22
+ def app(name=nil)
23
+ App.instance(name)
46
24
  end
47
25
 
48
- # Register saved configurations so we can do e.g.
49
- # Dragonfly[:my_app].configure_with(:image_magick)
50
- App.register_configuration(:imagemagick){ ImageMagick::Config }
51
- App.register_configuration(:image_magick){ ImageMagick::Config }
52
- App.register_configuration(:rails){ Config::Rails }
53
- App.register_configuration(:heroku){ Config::Heroku }
26
+ def [](name)
27
+ App[name]
28
+ end
54
29
 
55
30
  def running_on_windows?
56
- ENV['OS'] && ENV['OS'].downcase == 'windows_nt'
31
+ !!(RbConfig::CONFIG['host_os'] =~ %r!(msdos|mswin|djgpp|mingw)!)
32
+ end
33
+
34
+ # Logging
35
+ def logger
36
+ @logger ||= Logger.new('dragonfly.log')
57
37
  end
38
+ attr_writer :logger
39
+
40
+ [:debug, :warn, :info].each do |method|
41
+ define_method method do |message|
42
+ logger.send(method, "DRAGONFLY: #{message}")
43
+ end
44
+ end
45
+
46
+ # Register plugins so we can do e.g.
47
+ # Dragonfly.app.configure do
48
+ # plugin :imagemagick
49
+ # end
50
+ App.register_plugin(:imagemagick){ ImageMagick::Plugin.new }
51
+ App.register_plugin(:image_magick){ ImageMagick::Plugin.new }
52
+
53
+ # Register saved datastores so we can do e.g.
54
+ # Dragonfly.app.configure do
55
+ # datastore :file
56
+ # end
57
+ App.register_datastore(:file){ FileDataStore }
58
+ App.register_datastore(:memory){ MemoryDataStore }
58
59
 
59
60
  end
60
61
  end
@@ -1,122 +1,227 @@
1
- require 'logger'
2
1
  require 'forwardable'
3
2
  require 'rack'
3
+ require 'dragonfly/register'
4
+ require 'dragonfly/server'
5
+ require 'dragonfly/shell'
6
+ require 'dragonfly/configurable'
7
+ require 'dragonfly/file_data_store'
8
+ require 'dragonfly/routed_endpoint'
9
+ require 'dragonfly/job_endpoint'
10
+ require 'dragonfly/job'
4
11
 
5
12
  module Dragonfly
6
13
  class App
7
14
 
15
+ # Exceptions
16
+ class UnregisteredDataStore < RuntimeError; end
17
+
18
+ DEFAULT_NAME = :default
19
+
8
20
  class << self
21
+ extend Forwardable
22
+ def_delegator :configurer, :register_plugin
9
23
 
10
24
  private :new # Hide 'new' - need to use 'instance'
11
25
 
12
- def instance(name)
26
+ def instance(name=nil)
27
+ name ||= DEFAULT_NAME
13
28
  name = name.to_sym
14
29
  apps[name] ||= new(name)
15
30
  end
16
31
 
17
- alias [] instance
18
-
19
- private
32
+ def [](name)
33
+ raise "Dragonfly::App[#{name.inspect}] is deprecated - use Dragonfly.app (for the default app) or Dragonfly.app(#{name.inspect}) (for extra named apps) instead. See docs at http://markevans.github.io/dragonfly for details"
34
+ end
20
35
 
21
36
  def apps
22
37
  @apps ||= {}
23
38
  end
24
39
 
40
+ def destroy_apps
41
+ apps.clear
42
+ end
43
+
44
+ def register_datastore(symbol, &block)
45
+ available_datastores[symbol] = block
46
+ end
47
+
48
+ def available_datastores
49
+ @available_datastores ||= {}
50
+ end
51
+
25
52
  end
26
53
 
27
54
  def initialize(name)
28
55
  @name = name
29
- @analyser, @processor, @encoder, @generator = Analyser.new, Processor.new, Encoder.new, Generator.new
30
- [@analyser, @processor, @encoder, @generator].each do |obj|
31
- obj.use_same_log_as(self)
32
- obj.use_as_fallback_config(self)
33
- end
56
+ @analysers, @processors, @generators = Register.new, Register.new, Register.new
34
57
  @server = Server.new(self)
35
- @job_definitions = JobDefinitions.new
58
+ @job_methods = Module.new
59
+ @shell = Shell.new
60
+ @env = {}
36
61
  end
37
62
 
38
- attr_reader :name
39
-
40
- include Configurable
63
+ attr_reader :name, :env
41
64
 
42
65
  extend Forwardable
43
66
  def_delegator :datastore, :destroy
44
67
  def_delegators :new_job, :fetch, :generate, :fetch_file, :fetch_url
45
- def_delegators :server, :call
46
-
47
- configurable_attr :datastore do DataStorage::FileDataStore.new end
48
- configurable_attr :cache_duration, 3600*24*365 # (1 year)
49
- configurable_attr :fallback_mime_type, 'application/octet-stream'
50
- configurable_attr :secret, 'secret yo'
51
- configurable_attr :log do Logger.new('/var/tmp/dragonfly.log') end
52
- configurable_attr :trust_file_extensions, true
53
- configurable_attr :content_disposition
54
- configurable_attr :content_filename, Dragonfly::Response::DEFAULT_FILENAME
55
- configurable_attr :allow_legacy_urls, true
56
-
57
- attr_reader :analyser
58
- attr_reader :processor
59
- attr_reader :encoder
60
- attr_reader :generator
68
+ def_delegators :server, :call, :fetch_file_whitelist, :fetch_url_whitelist
69
+
70
+ # Configuration
71
+
72
+ extend Configurable
73
+
74
+ set_up_config do
75
+ writer :secret, :allow_legacy_urls
76
+ meth :response_header, :define_url, :define
77
+
78
+ def processor(*args, &block)
79
+ obj.add_processor(*args, &block)
80
+ end
81
+
82
+ def generator(*args, &block)
83
+ obj.add_generator(*args, &block)
84
+ end
85
+
86
+ def analyser(*args, &block)
87
+ obj.add_analyser(*args, &block)
88
+ end
89
+
90
+ def datastore(*args)
91
+ obj.use_datastore(*args)
92
+ end
93
+
94
+ def mime_type(*args)
95
+ obj.add_mime_type(*args)
96
+ end
97
+
98
+ def fetch_file_whitelist(patterns)
99
+ obj.server.add_to_fetch_file_whitelist(patterns)
100
+ end
101
+
102
+ def fetch_url_whitelist(patterns)
103
+ obj.server.add_to_fetch_url_whitelist(patterns)
104
+ end
105
+
106
+ writer :dragonfly_url, :protect_from_dos_attacks, :url_format, :url_host, :url_path_prefix,
107
+ :for => :server
108
+ meth :before_serve, :for => :server
109
+
110
+ def method_missing(meth, *args)
111
+ raise NoMethodError, "no method '#{meth}' for App configuration - but the configuration API has changed! see docs at http://markevans.github.io/dragonfly for details"
112
+ end
113
+ end
114
+
115
+ attr_reader :analysers
116
+ attr_reader :processors
117
+ attr_reader :generators
61
118
  attr_reader :server
62
119
 
63
- nested_configurable :server, :analyser, :processor, :encoder, :generator
120
+ def datastore
121
+ @datastore ||= FileDataStore.new
122
+ end
123
+ attr_writer :datastore
124
+
125
+ def use_datastore(store, *args)
126
+ self.datastore = if store.is_a?(Symbol)
127
+ get_klass = self.class.available_datastores[store]
128
+ raise UnregisteredDataStore, "the datastore '#{store}' is not registered" unless get_klass
129
+ klass = get_klass.call
130
+ klass.new(*args)
131
+ else
132
+ raise ArgumentError, "datastore only takes 1 argument unless you use a symbol" if args.any?
133
+ store
134
+ end
135
+ raise "datastores have a new interface (read/write/destroy) - see docs at http://markevans.github.io/dragonfly for details" if datastore.respond_to?(:store) && !datastore.respond_to?(:write)
136
+ end
137
+
138
+ def add_generator(*args, &block)
139
+ generators.add(*args, &block)
140
+ end
141
+
142
+ def get_generator(name)
143
+ generators.get(name)
144
+ end
145
+
146
+ def add_processor(name, callable=nil, &block)
147
+ processors.add(name, callable, &block)
148
+ define(name){|*args| process(name, *args) }
149
+ define("#{name}!"){|*args| process!(name, *args) }
150
+ end
151
+
152
+ def get_processor(name)
153
+ processors.get(name)
154
+ end
64
155
 
65
- attr_accessor :job_definitions
156
+ def add_analyser(name, callable=nil, &block)
157
+ analysers.add(name, callable, &block)
158
+ define(name){ analyse(name) }
159
+ end
66
160
 
67
- def new_job(content=nil, meta={})
161
+ def get_analyser(name)
162
+ analysers.get(name)
163
+ end
164
+
165
+ def new_job(content="", meta={})
68
166
  job_class.new(self, content, meta)
69
167
  end
70
168
  alias create new_job
71
169
 
170
+ attr_reader :shell
171
+
72
172
  def endpoint(job=nil, &block)
73
173
  block ? RoutedEndpoint.new(self, &block) : JobEndpoint.new(job)
74
174
  end
75
175
 
76
- def job(name, &block)
77
- job_definitions.add(name, &block)
78
- end
79
- configuration_method :job
176
+ attr_reader :job_methods
80
177
 
81
178
  def job_class
82
179
  @job_class ||= begin
83
180
  app = self
84
181
  Class.new(Job).class_eval do
85
- include app.analyser.analysis_methods
86
- include app.job_definitions
87
- include Job::OverrideInstanceMethods
182
+ include app.job_methods
88
183
  self
89
184
  end
90
185
  end
91
186
  end
92
187
 
93
- def store(object, opts={})
94
- temp_object = object.is_a?(TempObject) ? object : TempObject.new(object, opts[:meta] || {})
95
- datastore.store(temp_object, opts)
188
+ def define(method, &block)
189
+ job_methods.send(:define_method, method, &block)
190
+ end
191
+
192
+ def store(object, meta={}, opts={})
193
+ create(object, meta).store(opts)
96
194
  end
97
195
 
98
- def register_mime_type(format, mime_type)
99
- registered_mime_types[file_ext_string(format)] = mime_type
196
+ def add_mime_type(format, mime_type)
197
+ mime_types[file_ext_string(format)] = mime_type
100
198
  end
101
- configuration_method :register_mime_type
102
199
 
103
- def registered_mime_types
104
- @registered_mime_types ||= Rack::Mime::MIME_TYPES.dup
200
+ def mime_types
201
+ @mime_types ||= Rack::Mime::MIME_TYPES.dup
105
202
  end
106
203
 
107
204
  def mime_type_for(format)
108
- registered_mime_types[file_ext_string(format)]
205
+ mime_types[file_ext_string(format)] || fallback_mime_type
206
+ end
207
+
208
+ def ext_for(mime_type)
209
+ return 'txt' if mime_type == 'text/plain'
210
+ ext = mime_types.key(mime_type)
211
+ ext.tr('.', '') if ext
212
+ end
213
+
214
+ def response_header(key, value=nil, &block)
215
+ response_headers[key] = value || block
109
216
  end
110
217
 
111
218
  def response_headers
112
219
  @response_headers ||= {}
113
220
  end
114
- configuration_method :response_headers
115
221
 
116
222
  def define_url(&block)
117
223
  @url_proc = block
118
224
  end
119
- configuration_method :define_url
120
225
 
121
226
  def url_for(job, opts={})
122
227
  if @url_proc
@@ -132,70 +237,44 @@ module Dragonfly
132
237
  raise NotImplementedError, "The datastore doesn't support serving content directly - #{datastore.inspect}"
133
238
  end
134
239
 
135
- def define_macro(mod, macro_name)
136
- already_extended = (class << mod; self; end).included_modules.include?(ActiveModelExtensions)
137
- mod.extend(ActiveModelExtensions) unless already_extended
138
- mod.register_dragonfly_app(macro_name, self)
139
- end
140
-
141
- def define_macro_on_include(mod, macro_name)
142
- app = self
143
- name = self.name
144
- (class << mod; self; end).class_eval do
145
- alias_method "included_without_dragonfly_#{name}_#{macro_name}", :included
146
- define_method "included_with_dragonfly_#{name}_#{macro_name}" do |mod|
147
- send "included_without_dragonfly_#{name}_#{macro_name}", mod
148
- app.define_macro(mod, macro_name)
149
- end
150
- alias_method :included, "included_with_dragonfly_#{name}_#{macro_name}"
151
- end
152
- end
153
-
154
240
  # Reflection
155
241
  def processor_methods
156
- processor.functions.keys
242
+ processors.names
157
243
  end
158
-
244
+
159
245
  def generator_methods
160
- generator.functions.keys
246
+ generators.names
161
247
  end
162
-
248
+
163
249
  def analyser_methods
164
- analyser.analysis_method_names
165
- end
166
-
167
- def job_methods
168
- job_definitions.definition_names
250
+ analysers.names
169
251
  end
170
-
252
+
171
253
  def inspect
172
254
  "<#{self.class.name} name=#{name.inspect} >"
173
255
  end
174
-
175
- # Deprecated methods
176
- def url_path_prefix=(thing)
177
- raise NoMethodError, "url_path_prefix is deprecated - please use url_format, e.g. url_format = '/media/:job/:basename.:format' - see docs for more details"
178
- end
179
- configuration_method :url_path_prefix=
180
256
 
181
- def url_suffix=(thing)
182
- raise NoMethodError, "url_suffix is deprecated - please use url_format, e.g. url_format = '/media/:job/:basename.:format' - see docs for more details"
257
+ def fallback_mime_type
258
+ 'application/octet-stream'
183
259
  end
184
- configuration_method :url_suffix=
185
260
 
186
- def infer_mime_type_from_file_ext=(bool)
187
- raise NoMethodError, "infer_mime_type_from_file_ext is deprecated - please use trust_file_extensions = #{bool.inspect} instead"
261
+ def secret
262
+ @secret ||= 'secret yo'
188
263
  end
189
- configuration_method :infer_mime_type_from_file_ext=
264
+ attr_writer :secret
190
265
 
191
- private
266
+ attr_accessor :allow_legacy_urls
192
267
 
193
- attr_accessor :get_remote_url
268
+ def define_macro(klass, name)
269
+ raise NoMethodError, "define_macro is deprecated - instead of defining #{name}, just extend #{klass.name} with Dragonfly::Model and use dragonfly_accessor"
270
+ end
194
271
 
195
- def saved_configs
196
- self.class.saved_configs
272
+ def define_macro_on_include(mod, name)
273
+ raise NoMethodError, "define_macro_on_include is deprecated - instead of defining #{name}, just extend the relevant class with Dragonfly::Model and use dragonfly_accessor"
197
274
  end
198
275
 
276
+ private
277
+
199
278
  def file_ext_string(format)
200
279
  '.' + format.to_s.downcase.sub(/^.*\./,'')
201
280
  end