Skip to content

Commit

Permalink
Delegate Attachment#url through to the vault, too.
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-burns committed Dec 18, 2011
1 parent 6a03ce0 commit 10f788a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
9 changes: 1 addition & 8 deletions lib/paperclip/attachment.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def initialize(name, instance, options = {})
@errors = {} @errors = {}
@dirty = false @dirty = false
@interpolator = options[:interpolator] @interpolator = options[:interpolator]
@url_generator = options[:url_generator].new(self, @options)
@source_file_options = options[:source_file_options] @source_file_options = options[:source_file_options]
@whiny = options[:whiny] @whiny = options[:whiny]
@vault = options[:vault].new(self, @options) @vault = options[:vault].new(self, @options)
Expand Down Expand Up @@ -151,13 +150,7 @@ def assign uploaded_file
# +#new(Paperclip::Attachment, options_hash)+ # +#new(Paperclip::Attachment, options_hash)+
# +#for(style_name, options_hash)+ # +#for(style_name, options_hash)+
def url(style_name = default_style, options = {}) def url(style_name = default_style, options = {})
default_options = {:timestamp => @options[:use_timestamp], :escape => true} @vault.url(style_name, options)

if options == true || options == false # Backwards compatibility.
@url_generator.for(style_name, default_options.merge(:timestamp => options))
else
@url_generator.for(style_name, default_options.merge(options))
end
end end


# Returns the path of the attachment as defined by the :path option. If the # Returns the path of the attachment as defined by the :path option. If the
Expand Down
11 changes: 11 additions & 0 deletions lib/paperclip/shim_vault.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def initialize(attachment, options)
@queued_for_delete = [] @queued_for_delete = []
@options = options @options = options
@attachment = attachment @attachment = attachment
@url_generator = options[:url_generator].new(@attachment, @options)


initialize_storage initialize_storage
end end
Expand Down Expand Up @@ -37,6 +38,16 @@ def destroy(styles)
save save
end end


def url(style_name = default_style, options = {})
default_options = {:timestamp => @options[:use_timestamp], :escape => true}

if options == true || options == false # Backwards compatibility.
@url_generator.for(style_name, default_options.merge(:timestamp => options))
else
@url_generator.for(style_name, default_options.merge(options))
end
end

def path(style_name = default_style) def path(style_name = default_style)
if file_attached? if file_attached?
path = interpolate(path_option, style_name) path = interpolate(path_option, style_name)
Expand Down

0 comments on commit 10f788a

Please sign in to comment.