Class: Compostr::MediaLibraryCache
- Inherits:
-
Object
- Object
- Compostr::MediaLibraryCache
- Defined in:
- lib/compostr/media_library_cache.rb
Overview
Cache name->id for media items pretty wet copy of entitycache. Unclear how to DRY this up. Wordpress apparently lowercases file endings on upload, so this fact is respected in the lookup (only file ending is modified).
Instance Attribute Summary collapse
-
#name_id_map ⇒ Object
init and return @name_id_map.
Instance Method Summary collapse
-
#id_of_name(name) ⇒ Object
return id of given name, initializing the cache if necessary.
-
#id_of_names(names) ⇒ Object
return array of ids to given names, initializing the cache if necessary.
-
#initialize ⇒ MediaLibraryCache
constructor
A new instance of MediaLibraryCache.
Constructor Details
#initialize ⇒ MediaLibraryCache
Returns a new instance of MediaLibraryCache.
9 10 11 |
# File 'lib/compostr/media_library_cache.rb', line 9 def initialize @name_id_map = nil end |
Instance Attribute Details
#name_id_map ⇒ Object
init and return @name_id_map
30 31 32 |
# File 'lib/compostr/media_library_cache.rb', line 30 def name_id_map @name_id_map end |
Instance Method Details
#id_of_name(name) ⇒ Object
return id of given name, initializing the cache if necessary
15 16 17 18 19 20 |
# File 'lib/compostr/media_library_cache.rb', line 15 def id_of_name name return [] if name.nil? || name.empty? # Downcase file ending name_for_wp = File.basename(name, '.*') + File.extname(name).downcase name_id_map[name_for_wp] end |
#id_of_names(names) ⇒ Object
return array of ids to given names, initializing the cache if necessary
24 25 26 27 |
# File 'lib/compostr/media_library_cache.rb', line 24 def id_of_names names return [] if names.nil? || names.empty? names.map{|name| id_of_name name } end |