I'm looking to do the exact same thing.
For some reason when you try to configure Dragonfly directly it doesn't pick it up. E.g.
Dragonfly.app.configure do
puts "config for dragonfly"
before_serve do |job, env|
# Check to see if the user is authenticated
# Looks like we might have to use Warden to access the Session APIs
# bit.ly/2Nrx82y
puts 'before serve' * 70
binding.pry
throw :halt, [403, {'Content-Type' => 'text/plain'}, ["You shall not pass"]]
end
end
When attempting to configure through `Refinery::Dragonfly` an error is raised.
In `config/initializers/refinery/dragonfly.rb`:
Refinery::Dragonfly.configure do |config|
config.before_serve = proc do |job, env|
# Check to see if the user is authenticated
# Looks like we might have to use Warden to access the Session APIs
# bit.ly/2Nrx82y
puts 'before serve in Refinery::Dragonfly' * 70
binding.pry
throw :halt, [403, {'Content-Type' => 'text/plain'}, ["You shall not pass"]]
end
end
Sadly when you run the server with that configuration an error is raised. Here's the stacktrace.
7: refinerycms-images-4.0.3/lib/refinery/images/engine.rb:12:in `block in <class:Engine>'
6: refinerycms-dragonfly-1.0.1/lib/refinery/dragonfly/dragonfly.rb:10:in `configure!'
5: dragonfly-1.2.0/lib/dragonfly/configurable.rb:89:in `configure'
4: dragonfly-1.2.0/lib/dragonfly/configurable.rb:51:in `configure'
3: dragonfly-1.2.0/lib/dragonfly/configurable.rb:51:in `instance_eval'
2: refinerycms-dragonfly-1.0.1/lib/refinery/dragonfly/dragonfly.rb:35:in `block in configure!'
1: dragonfly-1.2.0/lib/dragonfly/configurable.rb:30:in `block (2 levels) in meth'
dragonfly-1.2.0/lib/dragonfly/server.rb:43:in `before_serve': wrong number of arguments (given 1, expected 0) (ArgumentError)
It looks like the block isn't passed into Dragonfly correctly.
This is one of the downsides to a dynamic language like ruby, you're not sure what the expected structure is supposed to be.