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.



25
26
27
28
29
30
31
32
33
# File 'lib/utopia/gallery/cache.rb', line 25

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`.



64
65
66
67
68
69
70
# File 'lib/utopia/gallery/cache.rb', line 64

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

Instance Attribute Details

#cache_rootObject (readonly)

Returns the value of attribute cache_root.



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

def cache_root
  @cache_root
end

#mediaObject (readonly)

Returns the value of attribute media.



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

def media
  @media
end

#media_rootObject (readonly)

Returns the value of attribute media_root.



35
36
37
# File 'lib/utopia/gallery/cache.rb', line 35

def media_root
  @media_root
end

#processesObject (readonly)

Returns the value of attribute processes.



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

def processes
  @processes
end

Instance Method Details

#output_path_for(process) ⇒ Object



44
45
46
# File 'lib/utopia/gallery/cache.rb', line 44

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

#respond_to?(name) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/utopia/gallery/cache.rb', line 72

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

#source_path_for(process) ⇒ Object



48
49
50
# File 'lib/utopia/gallery/cache.rb', line 48

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

#to_sObject



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

def to_s
  @media.path
end

#updateObject

Process the media, update files in the cache.



53
54
55
56
57
58
59
60
61
# File 'lib/utopia/gallery/cache.rb', line 53

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