Module: DirectWave::Uploader::Versions::ClassMethods

Defined in:
lib/directwave/uploader/versions.rb

Instance Method Summary collapse

Instance Method Details

#version(name, &block) ⇒ Object

Adds a new version to this uploader

Parameters

name (#to_sym)

name of the version

&block (Proc)

a block to eval on this version of the uploader

Examples

class Video < DirectWave::Uploader::Base

  version :iphone do
    def filename
      @filename ||= [extract(:guid), "iphone-video" << extract(:extname)].join("/")
    end

    def process
      super

      # processing version here with zencoder.com or another encoding cloud service
    end
  end

end


125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/directwave/uploader/versions.rb', line 125

def version(name, &block)
  name = name.to_sym
  unless versions[name]
    version = Class.new(Version)

    # Add the current version hash to class attribute :versions
    current_version = {}
    current_version[name] = version
    self.versions = versions.merge(current_version)

    class_eval "      def \#{name}\n        versions[:\#{name}]\n      end\n    RUBY\n  end\n  versions[name].class_eval(&block) if block\n  versions[name]\nend\n"