Class: Paperclip::StyleMap::Map
- Inherits:
-
Object
- Object
- Paperclip::StyleMap::Map
- Defined in:
- lib/paperclip/style_map/map.rb
Constant Summary collapse
- DEFAULT_EXPIRATION =
3600
Instance Attribute Summary collapse
-
#attachment ⇒ Object
readonly
Returns the value of attribute attachment.
-
#attachment_name ⇒ Object
readonly
Returns the value of attribute attachment_name.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#style_names ⇒ Object
readonly
Returns the value of attribute style_names.
Instance Method Summary collapse
- #blank? ⇒ Boolean
- #fetch(style_name, expiration: DEFAULT_EXPIRATION) ⇒ String? (also: #[])
-
#initialize(model:, attachment:) ⇒ Map
constructor
A new instance of Map.
- #inspect ⇒ Object
- #processing? ⇒ Boolean
- #to_h ⇒ Object
- #valid_style?(name) ⇒ Boolean
Constructor Details
#initialize(model:, attachment:) ⇒ Map
Returns a new instance of Map.
13 14 15 16 17 18 19 20 |
# File 'lib/paperclip/style_map/map.rb', line 13 def initialize(model:, attachment:) @model = model @attachment = @attachment_name = .name @style_names = Dux.enum @attachment.default_style, *@attachment.styles.keys end |
Instance Attribute Details
#attachment ⇒ Object (readonly)
Returns the value of attribute attachment.
7 8 9 |
# File 'lib/paperclip/style_map/map.rb', line 7 def @attachment end |
#attachment_name ⇒ Object (readonly)
Returns the value of attribute attachment_name.
8 9 10 |
# File 'lib/paperclip/style_map/map.rb', line 8 def @attachment_name end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
6 7 8 |
# File 'lib/paperclip/style_map/map.rb', line 6 def model @model end |
#style_names ⇒ Object (readonly)
Returns the value of attribute style_names.
9 10 11 |
# File 'lib/paperclip/style_map/map.rb', line 9 def style_names @style_names end |
Instance Method Details
#blank? ⇒ Boolean
33 34 35 |
# File 'lib/paperclip/style_map/map.rb', line 33 def blank? !@attachment.exists? || processing? end |
#fetch(style_name, expiration: DEFAULT_EXPIRATION) ⇒ String? Also known as: []
25 26 27 28 29 |
# 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 |
#inspect ⇒ Object
41 42 43 44 45 |
# 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? ⇒ Boolean
37 38 39 |
# File 'lib/paperclip/style_map/map.rb', line 37 def processing? @attachment.respond_to?(:processing?) && @attachment.processing? end |
#to_h ⇒ Object
52 53 54 55 56 |
# 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) ⇒ Boolean
48 49 50 |
# File 'lib/paperclip/style_map/map.rb', line 48 def valid_style?(name) @style_names.include? name end |