Module: Vips::Process::ClassMethods

Defined in:
lib/vips-process.rb

Instance Method Summary collapse

Instance Method Details

#version(name, deps = [], &block) ⇒ Object

Define a version

A version will then take optional arguments: ‘new_dst` which sets the output for the version (and reverts back to the previous dt) and `should_process` which tells whether we should process the version after running its code or not - comes in handy to stack them up.

Parameters:

  • name

    String the version’s name

  • deps (defaults to: [])

    the version’s dependencies, it’s a list of version names

  • &block

    block if you send a block to it



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/vips-process.rb', line 105

def version(name, deps = [], &block)
  throw :need_block_or_deps unless block_given? || !deps.empty?

  versions = class_variable_defined?(:@@_versions) ? class_variable_get(:@@_versions) : {}
  versions[name] = {deps: deps, block: block}
  class_variable_set :@@_versions, versions

  define_method "#{name}_version" do |new_dst=nil, should_process=true|
    # Make sure we have a reference to the old version if it's being changed
    if new_dst
      old_dst = @dst
      @dst = new_dst
    end

    _versions = self.class.class_variable_get :@@_versions

    # Recursively call dependencies but don't process them yet
    _versions[name][:deps].each { |dep| send "#{dep}_version", new_dst, false }

    # Run the version's block
    instance_eval &_versions[name][:block]

    # Process if we were explicitly told to do so
    version_dst = process! if should_process

    # Revert to the old destination if we changed it during the version
    @dst = old_dst if old_dst

    version_dst
  end
end

#versionsObject

Get all the version keys



138
# File 'lib/vips-process.rb', line 138

def versions; class_variable_get(:@@_versions).keys; end