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


133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/directwave/uploader/versions.rb', line 133

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 <<-RUBY
      def #{name}
        versions[:#{name}]
      end
    RUBY
  end
  versions[name].class_eval(&block) if block
  versions[name]
end