Class: Utopia::Gallery::Cache
- Inherits:
-
Object
- Object
- Utopia::Gallery::Cache
- Defined in:
- lib/utopia/gallery/cache.rb
Instance Attribute Summary collapse
-
#cache_root ⇒ Object
readonly
Returns the value of attribute cache_root.
-
#media ⇒ Object
readonly
Returns the value of attribute media.
-
#media_root ⇒ Object
readonly
Returns the value of attribute media_root.
-
#processes ⇒ Object
readonly
Returns the value of attribute processes.
Instance Method Summary collapse
-
#initialize(media_root, cache_root, cache_path, media, processes) ⇒ Cache
constructor
A new instance of Cache.
-
#method_missing(name, *args) ⇒ Object
This allows dynamic path lookup based on process name, e.g.
- #output_path_for(process) ⇒ Object
- #respond_to?(name) ⇒ Boolean
- #source_path_for(process) ⇒ Object
- #to_s ⇒ Object
-
#update ⇒ Object
Process the media, update files in the cache.
Constructor Details
#initialize(media_root, cache_root, cache_path, media, processes) ⇒ Cache
Returns a new instance of Cache.
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_root ⇒ Object (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 |
#media ⇒ Object (readonly)
Returns the value of attribute media.
38 39 40 |
# File 'lib/utopia/gallery/cache.rb', line 38 def media @media end |
#media_root ⇒ Object (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 |
#processes ⇒ Object (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
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_s ⇒ Object
40 41 42 |
# File 'lib/utopia/gallery/cache.rb', line 40 def to_s @media.path end |
#update ⇒ Object
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 |