lib/paperclip/missing_attachment_styles.rb in kt-paperclip-5.4.0 vs lib/paperclip/missing_attachment_styles.rb in kt-paperclip-6.2.0
- old
+ new
@@ -1,13 +1,13 @@
-require 'paperclip/attachment_registry'
-require 'set'
+require "paperclip/attachment_registry"
+require "set"
module Paperclip
class << self
attr_writer :registered_attachments_styles_path
def registered_attachments_styles_path
- @registered_attachments_styles_path ||= Rails.root.join('public/system/paperclip_attachments.yml').to_s
+ @registered_attachments_styles_path ||= Rails.root.join("public/system/paperclip_attachments.yml").to_s
end
end
# Get list of styles saved on previous deploy (running rake paperclip:refresh:missing_styles)
def self.get_registered_attachments_styles
@@ -16,11 +16,11 @@
nil
end
private_class_method :get_registered_attachments_styles
def self.save_current_attachments_styles!
- File.open(Paperclip.registered_attachments_styles_path, 'w') do |f|
+ File.open(Paperclip.registered_attachments_styles_path, "w") do |f|
YAML.dump(current_attachments_styles, f)
end
end
# Returns hash with styles for all classes using Paperclip.
@@ -34,11 +34,12 @@
# }
def self.current_attachments_styles
Hash.new.tap do |current_styles|
Paperclip::AttachmentRegistry.each_definition do |klass, attachment_name, attachment_attributes|
# TODO: is it even possible to take into account Procs?
- next if attachment_attributes[:styles].kind_of?(Proc)
+ next if attachment_attributes[:styles].is_a?(Proc)
+
attachment_attributes[:styles].try(:keys).try(:each) do |style_name|
klass_sym = klass.to_s.to_sym
current_styles[klass_sym] ||= Hash.new
current_styles[klass_sym][attachment_name.to_sym] ||= Array.new
current_styles[klass_sym][attachment_name.to_sym] << style_name.to_sym
@@ -61,10 +62,14 @@
registered_styles = get_registered_attachments_styles
Hash.new.tap do |missing_styles|
current_styles.each do |klass, attachment_definitions|
attachment_definitions.each do |attachment_name, styles|
- registered = registered_styles[klass][attachment_name] || [] rescue []
+ registered = begin
+ registered_styles[klass][attachment_name] || []
+ rescue StandardError
+ []
+ end
missed = styles - registered
if missed.present?
klass_sym = klass.to_s.to_sym
missing_styles[klass_sym] ||= Hash.new
missing_styles[klass_sym][attachment_name.to_sym] ||= Array.new