Class: DynamicPaperclip::Attachment
- Inherits:
-
Paperclip::Attachment
- Object
- Paperclip::Attachment
- DynamicPaperclip::Attachment
- Defined in:
- lib/dynamic_paperclip/attachment.rb
Instance Attribute Summary collapse
-
#dynamic_styles ⇒ Object
readonly
Returns the value of attribute dynamic_styles.
Instance Method Summary collapse
- #dynamic_url(definition) ⇒ Object
-
#initialize(name, instance, options = {}) ⇒ Attachment
constructor
A new instance of Attachment.
- #process_dynamic_style(definition) ⇒ Object
- #styles ⇒ Object
Constructor Details
#initialize(name, instance, options = {}) ⇒ Attachment
Returns a new instance of Attachment.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/dynamic_paperclip/attachment.rb', line 5 def initialize(name, instance, = {}) super @dynamic_styles = {} # Add existing dynamic styles if instance.persisted? path_with_wildcard = path('dynamic_*') style_position = path_with_wildcard.index('dynamic_*') Dir.glob(path_with_wildcard) do |file| add_dynamic_style! file[style_position..-1].split('/').first end end end |
Instance Attribute Details
#dynamic_styles ⇒ Object (readonly)
Returns the value of attribute dynamic_styles.
3 4 5 |
# File 'lib/dynamic_paperclip/attachment.rb', line 3 def dynamic_styles @dynamic_styles end |
Instance Method Details
#dynamic_url(definition) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dynamic_paperclip/attachment.rb', line 32 def dynamic_url(definition) raise DynamicPaperclip::Errors::SecretNotSet, "No secret has been configured. Please run the dynamic_paperclip:install generator." unless DynamicPaperclip.config.secret.present? style_name = StyleNaming.dynamic_style_name_from_definition(definition) url = url(style_name) delimiter_char = url.match(/\?.+=/) ? '&' : '?' "#{url}#{delimiter_char}s=#{UrlSecurity.generate_hash(style_name)}".html_safe end |
#process_dynamic_style(definition) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/dynamic_paperclip/attachment.rb', line 25 def process_dynamic_style(definition) style_name = StyleNaming.dynamic_style_name_from_definition(definition) add_dynamic_style! style_name reprocess! style_name end |
#styles ⇒ Object
21 22 23 |
# File 'lib/dynamic_paperclip/attachment.rb', line 21 def styles super.merge dynamic_styles end |