Module | Paperclip::Interpolations |
In: |
lib/paperclip/interpolations.rb
|
This module contains all the methods that are available for interpolation in paths and urls. To add your own (or override an existing one), you can either open this module and define it, or call the Paperclip.interpolates method.
Hash access of interpolations. Included only for compatability, and is not intended for normal use.
# File lib/paperclip/interpolations.rb, line 17 17: def self.[] name 18: method(name) 19: end
Hash assignment of interpolations. Included only for compatability, and is not intended for normal use.
# File lib/paperclip/interpolations.rb, line 11 11: def self.[]= name, block 12: define_method(name, &block) 13: end
Perform the actual interpolation. Takes the pattern to interpolate and the arguments to pass, which are the attachment and style name.
# File lib/paperclip/interpolations.rb, line 28 28: def self.interpolate pattern, *args 29: all.reverse.inject( pattern.dup ) do |result, tag| 30: result.gsub(/:#{tag}/) do |match| 31: send( tag, *args ) 32: end 33: end 34: end
Returns the pluralized form of the attachment name. e.g. "avatars" for an attachment of :avatar
# File lib/paperclip/interpolations.rb, line 105 105: def attachment attachment, style_name 106: attachment.name.to_s.downcase.pluralize 107: end
Returns the underscored, pluralized version of the class name. e.g. "users" for the User class. NOTE: The arguments need to be optional, because some tools fetch all class names. Calling class will return the expected class.
# File lib/paperclip/interpolations.rb, line 69 69: def class attachment = nil, style_name = nil 70: return super() if attachment.nil? && style_name.nil? 71: attachment.instance.class.to_s.underscore.pluralize 72: end
Returns the extension of the file. e.g. "jpg" for "file.jpg" If the style has a format defined, it will return the format instead of the actual extension.
# File lib/paperclip/interpolations.rb, line 82 82: def extension attachment, style_name 83: ((style = attachment.styles[style_name]) && style[:format]) || 84: File.extname(attachment.original_filename).gsub(/^\.+/, "") 85: end
Returns the fingerprint of the instance.
# File lib/paperclip/interpolations.rb, line 93 93: def fingerprint attachment, style_name 94: attachment.fingerprint 95: end
Returns the Rails.env constant.
# File lib/paperclip/interpolations.rb, line 61 61: def rails_env attachment, style_name 62: Rails.env 63: end
Returns the Rails.root constant.
# File lib/paperclip/interpolations.rb, line 56 56: def rails_root attachment, style_name 57: Rails.root 58: end
Returns the timestamp as defined by the <attachment>_updated_at field
# File lib/paperclip/interpolations.rb, line 51 51: def timestamp attachment, style_name 52: attachment.instance_read(:updated_at).to_s 53: end