Module Paperclip::Interpolations
In: lib/dm-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.

Methods

[]   []=   all   attachment   basename   class   extension   filename   id   id_partition   interpolate   merb_env   merb_root   rails_env   rails_root   style   timestamp   url   web_root  

Public Class methods

Hash access of interpolations. Included only for compatability, and is not intended for normal use.

[Source]

    # File lib/dm-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.

[Source]

    # File lib/dm-paperclip/interpolations.rb, line 11
11:     def self.[]= name, block
12:       define_method(name, &block)
13:     end

Returns a sorted list of all interpolations.

[Source]

    # File lib/dm-paperclip/interpolations.rb, line 22
22:     def self.all
23:       self.instance_methods(false).sort
24:     end

Perform the actual interpolation. Takes the pattern to interpolate and the arguments to pass, which are the attachment and style name.

[Source]

    # File lib/dm-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

Public Instance methods

Returns the pluralized form of the attachment name. e.g. "avatars" for an attachment of :avatar

[Source]

     # File lib/dm-paperclip/interpolations.rb, line 114
114:     def attachment attachment, style
115:       attachment.name.to_s.downcase.pluralize
116:     end

Returns the basename of the file. e.g. "file" for "file.jpg"

[Source]

    # File lib/dm-paperclip/interpolations.rb, line 89
89:     def basename attachment, style
90:       attachment.original_filename.gsub(/#{File.extname(attachment.original_filename)}$/, "")
91:     end

Returns the snake cased, pluralized version of the class name. e.g. "users" for the User class.

[Source]

    # File lib/dm-paperclip/interpolations.rb, line 84
84:     def class attachment, style
85:       attachment.instance.class.to_s.snake_case.pluralize
86:     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.

[Source]

    # File lib/dm-paperclip/interpolations.rb, line 96
96:     def extension attachment, style
97:       ((style = attachment.styles[style]) && style[:format]) ||
98:         File.extname(attachment.original_filename).gsub(/^\.+/, "")
99:     end

Returns the filename, the same way as ":basename.:extension" would.

[Source]

    # File lib/dm-paperclip/interpolations.rb, line 37
37:     def filename attachment, style
38:       "#{basename(attachment, style)}.#{extension(attachment, style)}"
39:     end

Returns the id of the instance.

[Source]

     # File lib/dm-paperclip/interpolations.rb, line 102
102:     def id attachment, style
103:       attachment.instance.id
104:     end

Returns the id of the instance in a split path form. e.g. returns 000/001/234 for an id of 1234.

[Source]

     # File lib/dm-paperclip/interpolations.rb, line 108
108:     def id_partition attachment, style
109:       ("%09d" % attachment.instance.id).scan(/\d{3}/).join("/")
110:     end

[Source]

    # File lib/dm-paperclip/interpolations.rb, line 78
78:     def merb_env attachment, style
79:       Object.const_defined?('Merb') ? Merb.env : nil
80:     end

[Source]

    # File lib/dm-paperclip/interpolations.rb, line 74
74:     def merb_root attachment, style
75:       Object.const_defined?('Merb') ? Merb.root : nil
76:     end

Returns the RAILS_ENV constant.

[Source]

    # File lib/dm-paperclip/interpolations.rb, line 70
70:     def rails_env attachment, style
71:       Object.const_defined?('RAILS_ENV') ? RAILS_ENV : nil
72:     end

Returns the RAILS_ROOT constant.

[Source]

    # File lib/dm-paperclip/interpolations.rb, line 65
65:     def rails_root attachment, style
66:       Object.const_defined?('RAILS_ROOT') ? RAILS_ROOT : nil
67:     end

Returns the style, or the default style if nil is supplied.

[Source]

     # File lib/dm-paperclip/interpolations.rb, line 119
119:     def style attachment, style
120:       style || attachment.default_style
121:     end

Returns the timestamp as defined by the <attachment>_updated_at field

[Source]

    # File lib/dm-paperclip/interpolations.rb, line 50
50:     def timestamp attachment, style
51:       attachment.instance_read(:updated_at).to_s
52:     end

Returns the interpolated URL. Will raise an error if the url itself contains ":url" to prevent infinite recursion. This interpolation is used in the default :path to ease default specifications.

[Source]

    # File lib/dm-paperclip/interpolations.rb, line 44
44:     def url attachment, style
45:       raise InfiniteInterpolationError if attachment.options[:url].include?(":url")
46:       attachment.url(style, false)
47:     end

[Source]

    # File lib/dm-paperclip/interpolations.rb, line 54
54:     def web_root attachment, style
55:       if Object.const_defined?('Merb')
56:         merb_root(attachment, style)
57:       elsif Object.const_defined("RAILS_ROOT")
58:         rails_root(attachment, style)
59:       else
60:         ""
61:       end
62:     end

[Validate]