Module: Refinery::Resources::Dragonfly

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

Class Method Summary collapse

Class Method Details

.attach!(app) ⇒ Object

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



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'resources/lib/refinery/resources/dragonfly.rb', line 46

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_resources
  else
    app.config.middleware.use ::Dragonfly::Middleware, :refinery_resources
  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
# File 'resources/lib/refinery/resources/dragonfly.rb', line 8

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

  app_resources = ::Dragonfly.app(:refinery_resources)

  app_resources.configure do |c|
    datastore :file, {
      :root_path => Refinery::Resources.datastore_root_path
    }
    url_format Refinery::Resources.dragonfly_url_format
    url_host Refinery::Resources.dragonfly_url_host
    verify_urls Refinery::Resources.dragonfly_verify_urls
    secret Refinery::Resources.dragonfly_secret
    response_header 'Content-Disposition' do |job, request, headers|
      "attachment; #{headers['Content-Disposition']}"
    end if Refinery::Resources.content_disposition == :attachment
    dragonfly_url nil
  end

  if ::Refinery::Resources.s3_backend
    require 'dragonfly/s3_data_store'
    options = {
      bucket_name: Refinery::Resources.s3_bucket_name,
      access_key_id: Refinery::Resources.s3_access_key_id,
      secret_access_key: Refinery::Resources.s3_secret_access_key
    }
    options.update(region: Refinery::Resources.s3_region) if Refinery::Resources.s3_region
    app_resources.use_datastore :s3, options
  end

  if Resources.custom_backend?
    app_resources.datastore = Resources.custom_backend_class.new(Resources.custom_backend_opts)
  end
end