class MiniPaperclip::Interpolator

Attributes

attachment[R]
config[R]

Public Class Methods

new(attachment, config) click to toggle source
# File lib/mini_paperclip/interpolator.rb, line 7
def initialize(attachment, config)
  @attachment = attachment
  @config = config
end

Public Instance Methods

interpolate(template, style) click to toggle source
# File lib/mini_paperclip/interpolator.rb, line 12
def interpolate(template, style)
  template.dup.tap do |t|
    @config.interpolates&.each do |matcher, block|
      t.gsub!(matcher) { instance_exec(style, &block) }
    end
  end
end

Private Instance Methods

attachment_result() click to toggle source
# File lib/mini_paperclip/interpolator.rb, line 26
def attachment_result
  @attachment.attachment_name.to_s.downcase.pluralize
end
class_result() click to toggle source
# File lib/mini_paperclip/interpolator.rb, line 22
def class_result
  @attachment.record.class.name.underscore.pluralize
end
extension() click to toggle source
# File lib/mini_paperclip/interpolator.rb, line 30
def extension
  attachment.original_filename &&
    File.extname(attachment.original_filename)[1..-1]
end
hash_key(style) click to toggle source
# File lib/mini_paperclip/interpolator.rb, line 35
def hash_key(style)
  OpenSSL::HMAC.hexdigest(
    OpenSSL::Digest::SHA1.new,
    @config.hash_secret,
    interpolated_hash_data(style),
  )
end
interpolated_hash_data(style) click to toggle source
# File lib/mini_paperclip/interpolator.rb, line 43
def interpolated_hash_data(style)
  interpolate(@config.hash_data, style)
end