Class: Alula::AttachmentProcessor
- Inherits:
-
Object
- Object
- Alula::AttachmentProcessor
- Defined in:
- lib/alula/attachment_processor.rb
Instance Attribute Summary collapse
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Class Method Summary collapse
Instance Method Summary collapse
- #asset_name(name, *path) ⇒ Object
- #get(item) ⇒ Object
-
#initialize(opts) ⇒ AttachmentProcessor
constructor
A new instance of AttachmentProcessor.
- #mapping ⇒ Object
- #processors ⇒ Object
Constructor Details
#initialize(opts) ⇒ AttachmentProcessor
Returns a new instance of AttachmentProcessor.
9 10 11 12 13 |
# File 'lib/alula/attachment_processor.rb', line 9 def initialize(opts) @site = opts.delete(:site) @@lock = Mutex.new end |
Instance Attribute Details
#site ⇒ Object (readonly)
Returns the value of attribute site.
7 8 9 |
# File 'lib/alula/attachment_processor.rb', line 7 def site @site end |
Class Method Details
.processors ⇒ Object
4 |
# File 'lib/alula/attachment_processor.rb', line 4 def self.processors; @@processors ||= {}; end |
.register(name, klass) ⇒ Object
3 |
# File 'lib/alula/attachment_processor.rb', line 3 def self.register(name, klass); processors[name] = klass; end |
Instance Method Details
#asset_name(name, *path) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/alula/attachment_processor.rb', line 19 def asset_name(name, *path) path ||= [] @@lock.synchronize do md5 = Digest::MD5.hexdigest(name) asset_hash = md5[0..3] asset_name = File.join(path + [asset_hash]) + File.extname(name) until !mapping.key(asset_name) or mapping.key(asset_name) == name.downcase asset_hash = md5[0..(asset_hash.length)] asset_name = File.join(path + [asset_hash]) + File.extname(name) end mapping[name.downcase] = asset_name end mapping[name.downcase] end |
#get(item) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/alula/attachment_processor.rb', line 37 def get(item) # Try to use cached processor for extension type = _type(item) = site.config.[type] self.processors[type].new(item, options: , site: site, attachments: self) end |
#mapping ⇒ Object
15 16 17 |
# File 'lib/alula/attachment_processor.rb', line 15 def mapping @mapping ||= {} end |
#processors ⇒ Object
5 |
# File 'lib/alula/attachment_processor.rb', line 5 def processors; self.class.processors; end |