Module: Refinery::Images::Dragonfly

Defined in:
images/lib/refinery/images/dragonfly.rb

Class Method Summary collapse

Class Method Details

.attach!(app) ⇒ Object

Injects Dragonfly::Middleware for Refinery::Images into the stack



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'images/lib/refinery/images/dragonfly.rb', line 50

def attach!(app)
  if defined?(::Rack::Cache)
    unless app.config.action_controller.perform_caching && app.config.action_dispatch.rack_cache
      app.config.middleware.insert 0, ::Rack::Cache, {
        verbose: true,
        metastore: URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/meta"), # URI encoded in case of spaces
        entitystore: URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/body")
      }
    end
    app.config.middleware.insert_after ::Rack::Cache, ::Dragonfly::Middleware, :refinery_images
  else
    app.config.middleware.use ::Dragonfly::Middleware, :refinery_images
  end
end

.configure!Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'images/lib/refinery/images/dragonfly.rb', line 8

def configure!
  ActiveRecord::Base.extend ::Dragonfly::Model
  ActiveRecord::Base.extend ::Dragonfly::Model::Validations

  app_images = ::Dragonfly.app(:refinery_images)

  app_images.configure do
    plugin :imagemagick
    datastore :file, {
      :root_path => Refinery::Images.datastore_root_path
    }
    url_format Refinery::Images.dragonfly_url_format
    url_host Refinery::Images.dragonfly_url_host
    verify_urls Refinery::Images.dragonfly_verify_urls
    if Refinery::Images.dragonfly_verify_urls
      secret Refinery::Images.dragonfly_secret
    end
    dragonfly_url nil
    processor :strip do |content|
      content.process!(:convert, '-strip')
    end
  end

  if ::Refinery::Images.s3_backend
    require 'dragonfly/s3_data_store'
    options = {
      bucket_name: Refinery::Images.s3_bucket_name,
      access_key_id: Refinery::Images.s3_access_key_id,
      secret_access_key: Refinery::Images.s3_secret_access_key
    }
    # S3 Region otherwise defaults to 'us-east-1'
    options.update(region: Refinery::Images.s3_region) if Refinery::Images.s3_region
    app_images.use_datastore :s3, options
  end

  if Images.custom_backend?
    app_images.datastore = Images.custom_backend_class.new(Images.custom_backend_opts)
  end
end