class Utopia::Gallery::Cache

Attributes

cache_root[R]
media[R]
media_root[R]
processes[R]

Public Class Methods

new(media_root, cache_root, cache_path, media, processes) click to toggle source

@param root [String] The root path for media files.

# File lib/utopia/gallery/cache.rb, line 27
def initialize(media_root, cache_root, cache_path, media, processes)
        # TODO: It's a lot of things to keep track of... perhaps a configuration class?
        @media_root = media_root
        @cache_root = cache_root
        @cache_path = cache_path
        @media = media
        
        @processes = processes
end

Public Instance Methods

input_path() click to toggle source
# File lib/utopia/gallery/cache.rb, line 42
def input_path
        File.join(@media_root, @media.path)
end
method_missing(name, *args) click to toggle source

This allows dynamic path lookup based on process name, e.g. `cache.small`.

Calls superclass method
# File lib/utopia/gallery/cache.rb, line 85
def method_missing(name, *args)
        if process = @processes[name]
                return Trenni::Reference.new(source_path_for(process))
        else
                super
        end
end
original() click to toggle source
# File lib/utopia/gallery/cache.rb, line 80
def original
        Trenni::Reference.new(@media.path)
end
output_path_for(process) click to toggle source
# File lib/utopia/gallery/cache.rb, line 58
def output_path_for(process)
        File.join(@cache_root, process.relative_path(@media))
end
output_paths() click to toggle source
# File lib/utopia/gallery/cache.rb, line 46
def output_paths
        @processes.values.collect{|process| output_path_for(process)}
end
outputs() { |process, output_path_for(process)| ... } click to toggle source
# File lib/utopia/gallery/cache.rb, line 50
def outputs
        return to_enum(:outputs) unless block_given?
        
        @processes.values do |process|
                yield process, output_path_for(process)
        end
end
respond_to?(name) click to toggle source
Calls superclass method
# File lib/utopia/gallery/cache.rb, line 93
def respond_to?(name)
        @processes.include?(name) || super
end
source_path_for(process) click to toggle source
# File lib/utopia/gallery/cache.rb, line 62
def source_path_for(process)
        File.join(@cache_path, process.relative_path(@media))
end
to_s() click to toggle source

Original path.

# File lib/utopia/gallery/cache.rb, line 76
def to_s
        original.to_s
end
update() click to toggle source

Process the media, update files in the cache.

# File lib/utopia/gallery/cache.rb, line 67
def update
        @processes.values.each do |process|
                process.call(self)
        end
        
        return self
end