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.
- #input_path ⇒ Object
-
#method_missing(name, *args) ⇒ Object
This allows dynamic path lookup based on process name, e.g.
- #original ⇒ Object
- #output_path_for(process) ⇒ Object
- #output_paths ⇒ Object
- #outputs ⇒ Object
- #respond_to?(name) ⇒ Boolean
- #source_path_for(process) ⇒ Object
-
#to_s ⇒ Object
Original path.
-
#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.
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_root ⇒ Object (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 |
#media ⇒ Object (readonly)
Returns the value of attribute media.
40 41 42 |
# File 'lib/utopia/gallery/cache.rb', line 40 def media @media end |
#media_root ⇒ Object (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 |
#processes ⇒ Object (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_path ⇒ Object
42 43 44 |
# File 'lib/utopia/gallery/cache.rb', line 42 def input_path File.join(@media_root, @media.path) end |
#original ⇒ Object
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_paths ⇒ Object
46 47 48 |
# File 'lib/utopia/gallery/cache.rb', line 46 def output_paths @processes.values.collect{|process| output_path_for(process)} end |
#outputs ⇒ Object
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
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_s ⇒ Object
Original path.
78 79 80 |
# File 'lib/utopia/gallery/cache.rb', line 78 def to_s original.to_s end |
#update ⇒ Object
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 |