Created
March 14, 2012 12:57
-
-
Save markevans/2036284 to your computer and use it in GitHub Desktop.
Ideas for changing dragonfly configuration API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### EXAMPLE: USING DRAGONFLY WITH S3 ON HEROKU ### | |
#### CURRENT API ##### | |
# in initializer file | |
require 'dragonfly' | |
app = Dragonfly[:images] | |
app.configure_with(:imagemagick) | |
app.configure_with(:rails) | |
app.configure do |c| | |
if Rails.env.production? | |
c.datastore = Dragonfly::DataStorage::S3DataStore.new( | |
:bucket_name => 'my-bucket-name', | |
:access_key_id => ENV['S3_KEY'], | |
:secret_access_key => ENV['S3_SECRET'] | |
) | |
end | |
c.some_other_option = 'blah' | |
end | |
app.define_macro(ActiveRecord::Base, :image_accessor) | |
# in Model: | |
class MyModel < ActiveRecord::Base | |
image_accessor :image | |
end | |
####################################################################### | |
#### NEW API ##### | |
# in initializer file: | |
require 'dragonfly' | |
Dragonfly[:app].configure do | |
use :imagemagick | |
use :rails | |
datastore :s3 do | |
bucket_name 'my-bucket-name' | |
access_key_id ENV['S3_KEY'] | |
secret_access_key ENV['S3_SECRET'] | |
end if Rails.env.production? | |
some_other_option 'blah' | |
end | |
# in Model: | |
class MyModel < ActiveRecord::Base | |
dragonfly_accessor :image | |
end |
Nice idea, though I'm not so keen on that because then it depends on Rails (at the moment it would work anywhere)
I guess I could use RACK_ENV or something, but still I'd rather not complicate the "datastore" configuration method - it should simply configure the datastore, and any conditions should go outside
what do you reckon?
The env option can't work because in rack application it's define by RACK_ENV but RAILS_ENV in rails.
@shingara - yes exactly I agree - avoiding thinking it's only for images is a benefit
Yes, you're right guys, I agree.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
New API looks great! But I think this would cleaner:
what do you think?