Class: Utopia::Gallery::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/gallery/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(media_root, cache_root, cache_path, media, processes) ⇒ Cache

Returns a new instance of Cache.

Parameters:

  • root (String)

    The root path for media files.



27
28
29
30
31
32
33
34
35
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

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



87
88
89
90
91
92
93
# File 'lib/utopia/gallery/cache.rb', line 87

def method_missing(name, *args)
	if process = @processes[name]
		return Trenni::URI(source_path_for(process))
	else
		super
	end
end

Instance Attribute Details

#cache_rootObject (readonly)

Returns the value of attribute cache_root.



38
39
40
# File 'lib/utopia/gallery/cache.rb', line 38

def cache_root
  @cache_root
end

#mediaObject (readonly)

Returns the value of attribute media.



40
41
42
# File 'lib/utopia/gallery/cache.rb', line 40

def media
  @media
end

#media_rootObject (readonly)

Returns the value of attribute media_root.



37
38
39
# File 'lib/utopia/gallery/cache.rb', line 37

def media_root
  @media_root
end

#processesObject (readonly)

Returns the value of attribute processes.



39
40
41
# File 'lib/utopia/gallery/cache.rb', line 39

def processes
  @processes
end

Instance Method Details

#input_pathObject



42
43
44
# File 'lib/utopia/gallery/cache.rb', line 42

def input_path
	File.join(@media_root, @media.path)
end

#originalObject



82
83
84
# File 'lib/utopia/gallery/cache.rb', line 82

def original
	Trenni::URI(@media.path)
end

#output_path_for(process) ⇒ Object



58
59
60
# File 'lib/utopia/gallery/cache.rb', line 58

def output_path_for(process)
	File.join(@cache_root, process.relative_path(@media))
end

#output_pathsObject



46
47
48
# File 'lib/utopia/gallery/cache.rb', line 46

def output_paths
	@processes.values.collect{|process| output_path_for(process)}
end

#outputsObject



50
51
52
53
54
55
56
# 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) ⇒ Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/utopia/gallery/cache.rb', line 95

def respond_to?(name)
	@processes.include?(name) || super
end

#source_path_for(process) ⇒ Object



62
63
64
# File 'lib/utopia/gallery/cache.rb', line 62

def source_path_for(process)
	File.join(@cache_path, process.relative_path(@media))
end

#to_sObject

Original path.



78
79
80
# File 'lib/utopia/gallery/cache.rb', line 78

def to_s
	original.to_s
end

#updateObject

Process the media, update files in the cache.



67
68
69
70
71
72
73
74
75
# File 'lib/utopia/gallery/cache.rb', line 67

def update
	locals = {}
	
	@processes.values.each do |process|
		process.call(self, locals)
	end
	
	return self
end