lib/cloudinary/carrier_wave/process.rb in cloudinary-1.0.31 vs lib/cloudinary/carrier_wave/process.rb in cloudinary-1.0.32
- old
+ new
@@ -1,7 +1,17 @@
module Cloudinary::CarrierWave
module ClassMethods
+ def make_private
+ process :cloudinary_transformation=>{:type => :private}
+ process_all_versions :cloudinary_transformation=>{:type => :private}
+ end
+
+ def process_all_versions(*args)
+ @all_versions ||= Class.new(self)
+ @all_versions.process *args
+ end
+
def eager
process :eager => true
end
def convert(format)
@@ -40,18 +50,18 @@
process :tags=>tags
end
end
def set_or_yell(hash, attr, value)
- raise "conflicting transformation on #{attr} #{value}!=#{hash[attr]}" if hash[attr]
+ raise "conflicting transformation on #{attr} #{value}!=#{hash[attr]}" if hash[attr] && hash[attr] != value
hash[attr] = value
end
def transformation
return @transformation if @transformation
@transformation = {}
- self.class.processors.each do
+ self.all_processors.each do
|name, args|
case name
when :convert # Do nothing. This is handled by format
when :resize_to_limit
set_or_yell(@transformation, :width, args[0])
@@ -96,21 +106,31 @@
end
end
@transformation
end
+ def all_versions_processors
+ all_versions = self.class.instance_variable_get('@all_versions')
+
+ all_versions ? all_versions.processors : []
+ end
+
+ def all_processors
+ (self.is_main_uploader? ? [] : all_versions_processors) + self.class.processors
+ end
+
def eager
- @eager ||= self.class.processors.any?{|processor| processor[0] == :eager}
+ @eager ||= self.all_processors.any?{|processor| processor[0] == :eager}
end
def tags
- @tags ||= self.class.processors.select{|processor| processor[0] == :tags}.map(&:second).first
+ @tags ||= self.all_processors.select{|processor| processor[0] == :tags}.map(&:second).first
raise "tags cannot be used in versions." if @tags.present? && self.version_name.present?
@tags
end
def format
- format_processor = self.class.processors.find{|processor| processor[0] == :convert}
+ format_processor = self.all_processors.find{|processor| processor[0] == :convert}
if format_processor
# Explicit format is given
return Array(format_processor[1]).first
elsif self.version_name.present?
# No local format. The reset should be handled by main uploader