Module: PictureHandler::Uploader::ImgVersion

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/picture_handler/uploader/img_version.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#process(args) ⇒ Object

The process is the function called inside the versions declared by the user



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/picture_handler/uploader/img_version.rb', line 18

def process(args)
  image = @versions[@current_version][:image]

  args.each do |key, value|
    case key
      when :resize_to_fill
        self.class.resize_to_fill(image, value)
      when :quality
        self.class.quality(image, value)
      # when :rounded
      # self.class.rounded(image, value)
      else
        raise PictureHandler::Exceptions::NoMethodError.new(key)
    end
  end
end

#version(sym, options = {}, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/picture_handler/uploader/img_version.rb', line 6

def version(sym, options={}, &block)
  # If the version already exist, the new one will overwrite the old one
  p "You already have a version named \"#{sym.to_s}\". Old one is being replaced" if @versions[sym] && @versions[sym][:block]

  # Fill the versions[:version_name][:block] with the block to be executed later
  @versions[sym] = { block: block } if block_given?

  # Fill the versions[:version_name][:from_version] with the symbol of the version from witch it should inherit
  @versions[sym].merge!( {from_version: options[:from_version]} )
end