Module: Nozzle::Adapter::Outlet

Included in:
Base
Defined in:
lib/nozzle/adapter/outlet.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/nozzle/adapter/outlet.rb', line 5

def self.included(base)
  base.instance_eval do
    def outlets
      @outlets ||= {}
    end
  end
  base.extend(ClassMethods)
end

Instance Method Details

#cleanup!Object



44
45
46
47
# File 'lib/nozzle/adapter/outlet.rb', line 44

def cleanup!
  delete_file_and_folder!( path )  if respond_to?(:version_name)
  outlets.each{ |name, outlet| outlet.cleanup! }
end

#outletsObject



14
15
16
17
18
19
20
21
# File 'lib/nozzle/adapter/outlet.rb', line 14

def outlets
  return @outlets  if @outlets
  @outlets = {}
  self.class.outlets.each do |name, outlet_class|
    @outlets[name] = outlet_class.new(@record, @column, @filename, @settings)
  end
  @outlets
end

#prepare(original, result) ⇒ Object

Copies the file from original path to this outlet path.

prepare( original, result )

This method SHOULD be overridden in the outlet block. Example:

class NewAdapter < Nozzle::Adapter::Base
  outlet :thumb do
    def prepare( original, result )
      `convert #{original} -thumbnail x96 #{result}`
    end
  end
end

In the example system convert is called to resize the original file and save it’s smaller version in result path.



35
36
37
38
# File 'lib/nozzle/adapter/outlet.rb', line 35

def prepare( original, result )
  FileUtils.mkdir_p File.dirname(result)
  FileUtils.cp original, result
end

#prepare!Object



40
41
42
# File 'lib/nozzle/adapter/outlet.rb', line 40

def prepare!
  prepare( @record.send(@column).path, path )
end