class Paperclip::StyleMap::Map
Constants
- DEFAULT_EXPIRATION
Attributes
attachment[R]
attachment_name[R]
model[R]
style_names[R]
Public Class Methods
new(model:, attachment:)
click to toggle source
@param [ActiveRecord::Base] model @param [Paperclip::Attachment] attachment
# File lib/paperclip/style_map/map.rb, line 13 def initialize(model:, attachment:) @model = model @attachment = attachment @attachment_name = attachment.name @style_names = Dux.enum @attachment.default_style, *@attachment.styles.keys end
Public Instance Methods
blank?()
click to toggle source
# File lib/paperclip/style_map/map.rb, line 33 def blank? !@attachment.exists? || processing? end
fetch(style_name, expiration: DEFAULT_EXPIRATION)
click to toggle source
@param [String, Symbol] style_name @param [ActiveSupport::Duration, Integer] expiration @return [String, nil]
# File lib/paperclip/style_map/map.rb, line 25 def fetch(style_name, expiration: DEFAULT_EXPIRATION) return nil if blank? || !valid_style?(style_name) @attachment.expiring_url(expiration, style_name) end
Also aliased as: []
inspect()
click to toggle source
# File lib/paperclip/style_map/map.rb, line 41 def inspect inspected_styles = @style_names.map { |n| n.to_sym.inspect }.inspect "#<#{self.class.name} @model=#{@model.model_name} @attachment=#{@attachment_name} @style_names=#{inspected_styles}>" end
processing?()
click to toggle source
# File lib/paperclip/style_map/map.rb, line 37 def processing? @attachment.respond_to?(:processing?) && @attachment.processing? end
to_h()
click to toggle source
# File lib/paperclip/style_map/map.rb, line 52 def to_h @style_names.each_with_object({}.with_indifferent_access) do |style_name, urls| urls[style_name.to_s] = self[style_name] end end
valid_style?(name)
click to toggle source
@param [String, Symbol] name
# File lib/paperclip/style_map/map.rb, line 48 def valid_style?(name) @style_names.include? name end